-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ pkgs, config, lib, ... }: | ||
|
||
let | ||
|
||
inherit (lib) mkEnableOption mkPackageOption mkOption literalExpression; | ||
|
||
tomlFormat = pkgs.formats.toml { }; | ||
cfg = config.programs.uv; | ||
|
||
in { | ||
meta.maintainers = with lib.maintainers; [ mirkolenz ]; | ||
|
||
options.programs.uv = { | ||
enable = mkEnableOption "uv"; | ||
|
||
package = mkPackageOption pkgs "uv" { }; | ||
|
||
settings = mkOption { | ||
type = tomlFormat.type; | ||
default = { }; | ||
example = literalExpression '' | ||
{ | ||
python-downloads = "never"; | ||
python-preference = "only-system"; | ||
pip.index-url = "https://test.pypi.org/simple"; | ||
} | ||
''; | ||
description = '' | ||
Configuration written to | ||
{file}`$XDG_CONFIG_HOME/uv/uv.toml`. | ||
See <https://docs.astral.sh/uv/configuration/files/> | ||
and <https://docs.astral.sh/uv/reference/settings/> | ||
for more information. | ||
''; | ||
}; | ||
|
||
enableBashIntegration = (mkEnableOption "uv's bash integration") // { | ||
default = true; | ||
}; | ||
|
||
enableZshIntegration = (mkEnableOption "uv's zsh integration") // { | ||
default = true; | ||
}; | ||
|
||
enableFishIntegration = (mkEnableOption "uv's fish integration") // { | ||
default = true; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
home.packages = [ cfg.package ]; | ||
|
||
xdg.configFile."uv/uv.toml" = lib.mkIf (cfg.settings != { }) { | ||
source = tomlFormat.generate "uv-config" cfg.settings; | ||
}; | ||
|
||
programs.bash.initExtra = lib.mkIf cfg.enableBashIntegration '' | ||
eval "$(${lib.getExe cfg.package} generate-shell-completion bash)" | ||
eval "$(${ | ||
lib.getExe' cfg.package "uvx" | ||
} --generate-shell-completion bash)" | ||
''; | ||
|
||
programs.zsh.initExtra = lib.mkIf cfg.enableZshIntegration '' | ||
eval "$(${lib.getExe cfg.package} generate-shell-completion zsh)" | ||
eval "$(${lib.getExe' cfg.package "uvx"} --generate-shell-completion zsh)" | ||
''; | ||
|
||
programs.fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration '' | ||
${lib.getExe cfg.package} generate-shell-completion fish | source | ||
${lib.getExe' cfg.package "uvx"} --generate-shell-completion fish | source | ||
''; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ ... }: | ||
|
||
{ | ||
programs = { | ||
uv.enable = true; | ||
bash = { | ||
enable = true; | ||
enableCompletion = false; | ||
}; | ||
}; | ||
|
||
test.stubs = { uv = { name = "uv"; }; }; | ||
|
||
nmt.script = '' | ||
assertFileExists home-files/.bashrc | ||
assertFileContains \ | ||
home-files/.bashrc \ | ||
'eval "$(@uv@/bin/uv generate-shell-completion bash)"' | ||
assertFileContains \ | ||
home-files/.bashrc \ | ||
'eval "$(@uv@/bin/uvx --generate-shell-completion bash)"' | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
uv-bash = ./bash.nix; | ||
uv-example-settings = ./example-settings.nix; | ||
uv-fish = ./fish.nix; | ||
uv-no-settings = ./no-settings.nix; | ||
uv-no-shell = ./no-shell.nix; | ||
uv-zsh = ./zsh.nix; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ pkgs, ... }: | ||
|
||
{ | ||
programs.uv = { | ||
enable = true; | ||
settings = { | ||
python-downloads = "never"; | ||
python-preference = "only-system"; | ||
pip.index-url = "https://test.pypi.org/simple"; | ||
}; | ||
}; | ||
|
||
test.stubs.uv = { }; | ||
|
||
nmt.script = let | ||
expectedConfigPath = "home-files/.config/uv/uv.toml"; | ||
expectedConfigContent = pkgs.writeText "uv.config-custom.expected" '' | ||
python-downloads = "never" | ||
python-preference = "only-system" | ||
[pip] | ||
index-url = "https://test.pypi.org/simple" | ||
''; | ||
in '' | ||
assertFileExists "${expectedConfigPath}" | ||
assertFileContent "${expectedConfigPath}" "${expectedConfigContent}" | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ lib, ... }: | ||
|
||
{ | ||
programs = { | ||
uv.enable = true; | ||
fish.enable = true; | ||
}; | ||
|
||
# Needed to avoid error with dummy fish package. | ||
xdg.dataFile."fish/home-manager_generated_completions".source = | ||
lib.mkForce (builtins.toFile "empty" ""); | ||
|
||
test.stubs = { uv = { name = "uv"; }; }; | ||
|
||
nmt.script = '' | ||
assertFileExists home-files/.config/fish/config.fish | ||
assertFileContains \ | ||
home-files/.config/fish/config.fish \ | ||
'@uv@/bin/uv generate-shell-completion fish | source' | ||
assertFileContains \ | ||
home-files/.config/fish/config.fish \ | ||
'@uv@/bin/uvx --generate-shell-completion fish | source' | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ ... }: { | ||
programs.uv = { enable = true; }; | ||
|
||
test.stubs.uv = { }; | ||
|
||
nmt.script = let expectedConfigPath = "home-files/.config/uv/uv.toml"; | ||
in '' | ||
assertPathNotExists "${expectedConfigPath}" | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ lib, ... }: | ||
|
||
{ | ||
programs = { | ||
uv = { | ||
enable = true; | ||
enableBashIntegration = false; | ||
enableZshIntegration = false; | ||
enableFishIntegration = false; | ||
}; | ||
bash.enable = true; | ||
zsh.enable = true; | ||
fish.enable = true; | ||
}; | ||
|
||
# Needed to avoid error with dummy fish package. | ||
xdg.dataFile."fish/home-manager_generated_completions".source = | ||
lib.mkForce (builtins.toFile "empty" ""); | ||
|
||
nmt.script = '' | ||
assertFileNotRegex home-files/.zshrc 'uv generate-shell-completion zsh' | ||
assertFileNotRegex home-files/.bashrc 'uv generate-shell-completion bash' | ||
assertFileNotRegex home-files/.config/fish/config.fish 'uv generate-shell-completion fish' | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ ... }: | ||
|
||
{ | ||
programs = { | ||
uv.enable = true; | ||
zsh.enable = true; | ||
}; | ||
|
||
test.stubs = { uv = { name = "uv"; }; }; | ||
|
||
nmt.script = '' | ||
assertFileExists home-files/.zshrc | ||
assertFileContains \ | ||
home-files/.zshrc \ | ||
'eval "$(@uv@/bin/uv generate-shell-completion zsh)"' | ||
assertFileContains \ | ||
home-files/.zshrc \ | ||
'eval "$(@uv@/bin/uvx --generate-shell-completion zsh)"' | ||
''; | ||
} |