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:
parent
f9d45d664e
commit
6bdf2a68e1
5 changed files with 107 additions and 0 deletions
10
modules/misc/news/2025/12/2025-12-06_11-05-43.nix
Normal file
10
modules/misc/news/2025/12/2025-12-06_11-05-43.nix
Normal 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
51
modules/programs/ty.nix
Normal 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;
|
||||
};
|
||||
};
|
||||
}
|
||||
4
tests/modules/programs/ty/default.nix
Normal file
4
tests/modules/programs/ty/default.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
ty-example-settings = ./example-settings.nix;
|
||||
ty-no-settings = ./no-settings.nix;
|
||||
}
|
||||
25
tests/modules/programs/ty/example-settings.nix
Normal file
25
tests/modules/programs/ty/example-settings.nix
Normal 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}"
|
||||
'';
|
||||
}
|
||||
17
tests/modules/programs/ty/no-settings.nix
Normal file
17
tests/modules/programs/ty/no-settings.nix
Normal 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}"
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue