1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-12 20:11:06 +01:00

ty: add module

This commit is contained in:
Mirko Lenz 2025-12-06 09:51:31 +01:00 committed by Austin Horstman
parent f9d45d664e
commit 6bdf2a68e1
5 changed files with 107 additions and 0 deletions

View file

@ -0,0 +1,10 @@
{
time = "2025-12-06T10:05:43+00:00";
condition = true;
message = ''
A new module is available: `programs.ty`
It allows to manage the configuration and package
of the Python language server `ty` by Astral.
'';
}

51
modules/programs/ty.nix Normal file
View file

@ -0,0 +1,51 @@
{
pkgs,
config,
lib,
...
}:
let
inherit (lib)
mkEnableOption
mkPackageOption
mkOption
literalExpression
;
tomlFormat = pkgs.formats.toml { };
cfg = config.programs.ty;
in
{
meta.maintainers = with lib.maintainers; [ mirkolenz ];
options.programs.ty = {
enable = mkEnableOption "ty";
package = mkPackageOption pkgs "ty" { nullable = true; };
settings = mkOption {
type = tomlFormat.type;
default = { };
example = literalExpression ''
{
rules.index-out-of-bounds = "ignore";
}
'';
description = ''
Configuration written to
{file}`$XDG_CONFIG_HOME/ty/ty.toml`.
See <https://docs.astral.sh/ty/configuration/>
and <https://docs.astral.sh/ty/reference/configuration/>
for more information.
'';
};
};
config = lib.mkIf cfg.enable {
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
xdg.configFile."ty/ty.toml" = lib.mkIf (cfg.settings != { }) {
source = tomlFormat.generate "ty-config.toml" cfg.settings;
};
};
}

View file

@ -0,0 +1,4 @@
{
ty-example-settings = ./example-settings.nix;
ty-no-settings = ./no-settings.nix;
}

View file

@ -0,0 +1,25 @@
{ pkgs, ... }:
{
programs.ty = {
enable = true;
settings = {
rules.index-out-of-bounds = "ignore";
};
};
test.stubs.ty = { };
nmt.script =
let
expectedConfigPath = "home-files/.config/ty/ty.toml";
expectedConfigContent = pkgs.writeText "ty.config-custom.expected" ''
[rules]
index-out-of-bounds = "ignore"
'';
in
''
assertFileExists "${expectedConfigPath}"
assertFileContent "${expectedConfigPath}" "${expectedConfigContent}"
'';
}

View file

@ -0,0 +1,17 @@
{ pkgs, ... }:
{
programs.ty = {
enable = true;
};
test.stubs.ty = { };
nmt.script =
let
expectedConfigPath = "home-files/.config/ty/ty.toml";
in
''
assertPathNotExists "${expectedConfigPath}"
'';
}