1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-31 04:04:32 +00:00
This commit is contained in:
jaredmontoya 2025-03-30 12:57:19 +11:00 committed by GitHub
commit 9d63eb55aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 122 additions and 147 deletions

View file

@ -125,17 +125,12 @@ in {
'';
programs.nushell = mkIf cfg.enableNushellIntegration {
extraEnv = ''
let atuin_cache = "${config.xdg.cacheHome}/atuin"
if not ($atuin_cache | path exists) {
mkdir $atuin_cache
}
${
lib.getExe cfg.package
} init nu ${flagsStr} | save --force ${config.xdg.cacheHome}/atuin/init.nu
'';
extraConfig = ''
source ${config.xdg.cacheHome}/atuin/init.nu
source ${
pkgs.runCommand "atuin-nushell-config" { } ''
${lib.getExe cfg.package} init nu ${flagsStr} >> "$out"
''
}
'';
};
}

View file

@ -1,20 +1,16 @@
{ config, pkgs, lib, ... }:
let
inherit (lib)
mkEnableOption mkPackageOption mkIf pipe fileContents splitString;
cfg = config.programs.carapace;
bin = cfg.package + "/bin/carapace";
bin = lib.getExe cfg.package;
in {
meta.maintainers = with lib.maintainers; [ weathercold bobvanderlinden ];
options.programs.carapace = {
enable =
mkEnableOption "carapace, a multi-shell multi-command argument completer";
enable = lib.mkEnableOption
"carapace, a multi-shell multi-command argument completer";
package = mkPackageOption pkgs "carapace" { };
package = lib.mkPackageOption pkgs "carapace" { };
enableBashIntegration =
lib.hm.shell.mkBashIntegrationOption { inherit config; };
@ -29,39 +25,34 @@ in {
lib.hm.shell.mkZshIntegrationOption { inherit config; };
};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
programs = {
bash.initExtra = mkIf cfg.enableBashIntegration ''
bash.initExtra = lib.mkIf cfg.enableBashIntegration ''
source <(${bin} _carapace bash)
'';
zsh.initContent = mkIf cfg.enableZshIntegration ''
zsh.initContent = lib.mkIf cfg.enableZshIntegration ''
source <(${bin} _carapace zsh)
'';
fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration ''
${bin} _carapace fish | source
'';
nushell = mkIf cfg.enableNushellIntegration {
# Note, the ${"$"} below is a work-around because xgettext otherwise
# interpret it as a Bash i18n string.
extraEnv = ''
let carapace_cache = "${config.xdg.cacheHome}/carapace"
if not ($carapace_cache | path exists) {
mkdir $carapace_cache
}
${bin} _carapace nushell | save -f ${"$"}"($carapace_cache)/init.nu"
'';
nushell = lib.mkIf cfg.enableNushellIntegration {
extraConfig = ''
source ${config.xdg.cacheHome}/carapace/init.nu
source ${
pkgs.runCommand "carapace-nushell-config" { } ''
${bin} _carapace nushell >> "$out"
''
}
'';
};
};
xdg.configFile = mkIf (config.programs.fish.enable
xdg.configFile = lib.mkIf (config.programs.fish.enable
&& cfg.enableFishIntegration
&& lib.versionOlder config.programs.fish.package.version "4.0.0") (
# Convert the entries from `carapace --list` to empty
@ -84,9 +75,9 @@ in {
} ''
${bin} --list > $out
'';
in pipe carapaceListFile [
fileContents
(splitString "\n")
in lib.pipe carapaceListFile [
lib.fileContents
(lib.splitString "\n")
(map (builtins.match "^([a-z0-9-]+) .*"))
(builtins.filter
(match: match != null && (builtins.length match) > 0))

View file

@ -31,22 +31,21 @@ in {
programs = {
fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
${cfg.package}/bin/nix-your-shell fish | source
${lib.getExe cfg.package} fish | source
'';
nushell = mkIf cfg.enableNushellIntegration {
extraEnv = ''
mkdir ${config.xdg.cacheHome}/nix-your-shell
${cfg.package}/bin/nix-your-shell nu | save --force ${config.xdg.cacheHome}/nix-your-shell/init.nu
'';
extraConfig = ''
source ${config.xdg.cacheHome}/nix-your-shell/init.nu
source ${
pkgs.runCommand "nix-your-shell-nushell-config" { } ''
${lib.getExe cfg.package} nu >> "$out"
''
}
'';
};
zsh.initContent = mkIf cfg.enableZshIntegration ''
${cfg.package}/bin/nix-your-shell zsh | source /dev/stdin
${lib.getExe cfg.package} zsh | source /dev/stdin
'';
};
};

View file

@ -68,27 +68,26 @@ in {
};
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
eval "$(${cfg.package}/bin/oh-my-posh init bash ${configArgument})"
eval "$(${lib.getExe cfg.package} init bash ${configArgument})"
'';
programs.zsh.initContent = mkIf cfg.enableZshIntegration ''
eval "$(${cfg.package}/bin/oh-my-posh init zsh ${configArgument})"
eval "$(${lib.getExe cfg.package} init zsh ${configArgument})"
'';
programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
${cfg.package}/bin/oh-my-posh init fish ${configArgument} | source
${lib.getExe cfg.package} init fish ${configArgument} | source
'';
programs.nushell = mkIf cfg.enableNushellIntegration {
extraEnv = ''
let oh_my_posh_cache = "${config.xdg.cacheHome}/oh-my-posh"
if not ($oh_my_posh_cache | path exists) {
mkdir $oh_my_posh_cache
}
${cfg.package}/bin/oh-my-posh init nu ${configArgument} --print | save --force ${config.xdg.cacheHome}/oh-my-posh/init.nu
'';
extraConfig = ''
source ${config.xdg.cacheHome}/oh-my-posh/init.nu
source ${
pkgs.runCommand "oh-my-posh-nushell-config" { } ''
${
lib.getExe cfg.package
} init nu ${configArgument} --print >> "$out"
''
}
'';
};
};

View file

@ -1,16 +1,24 @@
{ config, lib, pkgs, ... }:
let
inherit (lib) mkEnableOption mkPackageOption getExe optionalString mkIf;
cfg = config.programs.pay-respects;
payRespectsCmd = getExe cfg.package;
payRespectsCmd = lib.getExe cfg.package;
cfgOptions = lib.concatStringsSep " " cfg.options;
in {
meta.maintainers = [ lib.hm.maintainers.ALameLlama ];
options.programs.pay-respects = {
enable = mkEnableOption "pay-respects";
enable = lib.mkEnableOption "pay-respects";
package = mkPackageOption pkgs "pay-respects" { };
package = lib.mkPackageOption pkgs "pay-respects" { };
options = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "--alias" ];
example = [ "--alias" "f" ];
description = ''
List of options to pass to pay-respects <shell>.
'';
};
enableBashIntegration =
lib.hm.shell.mkBashIntegrationOption { inherit config; };
@ -25,32 +33,28 @@ in {
lib.hm.shell.mkZshIntegrationOption { inherit config; };
};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
programs = {
bash.initExtra = ''
${optionalString cfg.enableBashIntegration ''
eval "$(${payRespectsCmd} bash --alias)"
''}
bash.initExtra = lib.mkIf cfg.enableBashIntegration ''
eval "$(${payRespectsCmd} bash ${cfgOptions})"
'';
zsh.initContent = ''
${optionalString cfg.enableZshIntegration ''
eval "$(${payRespectsCmd} zsh --alias)"
''}
zsh.initContent = lib.mkIf cfg.enableZshIntegration ''
eval "$(${payRespectsCmd} zsh ${cfgOptions})"
'';
fish.interactiveShellInit = ''
${optionalString cfg.enableFishIntegration ''
${payRespectsCmd} fish --alias | source
''}
fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration ''
${payRespectsCmd} fish ${cfgOptions} | source
'';
nushell.extraConfig = ''
${optionalString cfg.enableNushellIntegration ''
${payRespectsCmd} nushell --alias [<alias>]
''}
nushell.extraConfig = lib.mkIf cfg.enableNushellIntegration ''
source ${
pkgs.runCommand "pay-respects-nushell-config" { } ''
${payRespectsCmd} nushell ${cfgOptions} >> "$out"
''
}
'';
};
};

View file

@ -8,8 +8,6 @@ let
tomlFormat = pkgs.formats.toml { };
starshipCmd = "${config.home.profileDirectory}/bin/starship";
initFish =
if cfg.enableInteractive then "interactiveShellInit" else "shellInitLast";
in {
@ -102,26 +100,26 @@ in {
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
if [[ $TERM != "dumb" ]]; then
eval "$(${starshipCmd} init bash --print-full-init)"
eval "$(${lib.getExe cfg.package} init bash --print-full-init)"
fi
'';
programs.zsh.initContent = mkIf cfg.enableZshIntegration ''
if [[ $TERM != "dumb" ]]; then
eval "$(${starshipCmd} init zsh)"
eval "$(${lib.getExe cfg.package} init zsh)"
fi
'';
programs.fish.${initFish} = mkIf cfg.enableFishIntegration ''
if test "$TERM" != "dumb"
${starshipCmd} init fish | source
${lib.getExe cfg.package} init fish | source
${lib.optionalString cfg.enableTransience "enable_transience"}
end
'';
programs.ion.initExtra = mkIf cfg.enableIonIntegration ''
if test $TERM != "dumb"
eval $(${starshipCmd} init ion)
eval $(${lib.getExe cfg.package} init ion)
end
'';
@ -130,15 +128,12 @@ in {
# conditionally setting (global) environment variables, which is why the
# check for terminal compatibility (as seen above for the other shells) is
# not done here.
extraEnv = ''
let starship_cache = "${config.xdg.cacheHome}/starship"
if not ($starship_cache | path exists) {
mkdir $starship_cache
}
${starshipCmd} init nu | save --force ${config.xdg.cacheHome}/starship/init.nu
'';
extraConfig = ''
use ${config.xdg.cacheHome}/starship/init.nu
use ${
pkgs.runCommand "starship-nushell-config" { } ''
${lib.getExe cfg.package} init nu >> "$out"
''
}
'';
};
};

View file

@ -38,29 +38,25 @@ in {
programs.bash.initExtra = lib.mkIf cfg.enableBashIntegration
(lib.mkOrder 2000 ''
eval "$(${cfg.package}/bin/zoxide init bash ${cfgOptions})"
eval "$(${lib.getExe cfg.package} init bash ${cfgOptions})"
'');
programs.zsh.initContent = lib.mkIf cfg.enableZshIntegration
(lib.mkOrder 2000 ''
eval "$(${cfg.package}/bin/zoxide init zsh ${cfgOptions})"
eval "$(${lib.getExe cfg.package} init zsh ${cfgOptions})"
'');
programs.fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration ''
${cfg.package}/bin/zoxide init fish ${cfgOptions} | source
${lib.getExe cfg.package} init fish ${cfgOptions} | source
'';
programs.nushell = lib.mkIf cfg.enableNushellIntegration {
extraEnv = ''
let zoxide_cache = "${config.xdg.cacheHome}/zoxide"
if not ($zoxide_cache | path exists) {
mkdir $zoxide_cache
}
${cfg.package}/bin/zoxide init nushell ${cfgOptions} |
save --force ${config.xdg.cacheHome}/zoxide/init.nu
'';
extraConfig = ''
source ${config.xdg.cacheHome}/zoxide/init.nu
source ${
pkgs.runCommand "zoxide-nushell-config" { } ''
${lib.getExe cfg.package} init nushell ${cfgOptions} >> "$out"
''
}
'';
};
};

View file

@ -1,4 +1,4 @@
{ pkgs, config, ... }:
{ lib, pkgs, realPkgs, config, ... }:
{
programs = {
@ -6,17 +6,16 @@
nushell.enable = true;
};
_module.args.pkgs = lib.mkForce realPkgs;
nmt.script = let
configDir = if pkgs.stdenv.isDarwin && !config.xdg.enable then
"home-files/Library/Application Support/nushell"
else
"home-files/.config/nushell";
in ''
assertFileExists "${configDir}/env.nu"
assertFileRegex "${configDir}/env.nu" \
'/nix/store/.*carapace.*/bin/carapace _carapace nushell \| save -f \$"(\$carapace_cache)/init\.nu"'
assertFileExists "${configDir}/config.nu"
assertFileRegex "${configDir}/config.nu" \
'source /.*/\.cache/carapace/init\.nu'
'source /nix/store/[^/]*-carapace-nushell-config'
'';
}

View file

@ -1,4 +1,4 @@
{ pkgs, config, ... }:
{ lib, pkgs, realPkgs, config, ... }:
{
programs = {
@ -13,6 +13,8 @@
zsh.enable = true;
};
_module.args.pkgs = lib.mkForce realPkgs;
nmt.script = let
nushellConfigDir = if pkgs.stdenv.isDarwin && !config.xdg.enable then
"home-files/Library/Application Support/nushell"
@ -20,23 +22,18 @@
"home-files/.config/nushell";
in ''
assertFileExists home-files/.config/fish/config.fish
assertFileContains \
assertFileRegex \
home-files/.config/fish/config.fish \
'@nix-your-shell@/bin/nix-your-shell fish | source'
'/nix/store/[^/]*-nix-your-shell-[^/]*/bin/nix-your-shell fish | source'
assertFileExists ${nushellConfigDir}/config.nu
assertFileContains \
assertFileRegex \
${nushellConfigDir}/config.nu \
'source ${config.xdg.cacheHome}/nix-your-shell/init.nu'
assertFileExists ${nushellConfigDir}/env.nu
assertFileContains \
${nushellConfigDir}/env.nu \
'@nix-your-shell@/bin/nix-your-shell nu | save --force ${config.xdg.cacheHome}/nix-your-shell/init.nu'
'source /nix/store/[^/]*-nix-your-shell-nushell-config'
assertFileExists home-files/.zshrc
assertFileContains \
assertFileRegex \
home-files/.zshrc \
'@nix-your-shell@/bin/nix-your-shell zsh | source /dev/stdin'
'/nix/store/[^/]*-nix-your-shell-[^/]*/bin/nix-your-shell zsh | source /dev/stdin'
'';
}

View file

@ -1,4 +1,4 @@
{ pkgs, config, ... }:
{ lib, pkgs, realPkgs, config, ... }:
{
programs = {
@ -10,25 +10,17 @@
};
};
_module.args.pkgs = lib.mkForce realPkgs;
nmt.script = let
configFile = if pkgs.stdenv.isDarwin && !config.xdg.enable then
"home-files/Library/Application Support/nushell/config.nu"
else
"home-files/.config/nushell/config.nu";
envFile = if pkgs.stdenv.isDarwin && !config.xdg.enable then
"home-files/Library/Application Support/nushell/env.nu"
else
"home-files/.config/nushell/env.nu";
in ''
assertFileExists "${envFile}"
assertFileRegex \
"${envFile}" \
'/bin/oh-my-posh init nu --config .*--print \| save --force /.*/home-files/\.cache/oh-my-posh/init\.nu'
assertFileExists "${configFile}"
assertFileRegex \
"${configFile}" \
'source /.*/\.cache/oh-my-posh/init\.nu'
'source /nix/store/[^/]*-oh-my-posh-nushell-config'
'';
}

View file

@ -1,3 +1,5 @@
{ lib, realPkgs, ... }:
{
programs = {
pay-respects.enable = true;
@ -11,10 +13,12 @@
nushell.enable = true;
};
_module.args.pkgs = lib.mkForce realPkgs;
nmt.script = ''
assertFileNotRegex home-files/.bashrc '@pay-respects@/bin/pay-respects'
assertFileNotRegex home-files/.zshrc '@pay-respects@/bin/pay-respects'
assertFileNotRegex home-files/.config/fish/config.fish '@pay-respects@/bin/pay-respects'
assertFileNotRegex home-files/.config/nushell/config.nu '@pay-respects@/bin/pay-respects'
assertFileNotRegex home-files/.bashrc '/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects'
assertFileNotRegex home-files/.zshrc '/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects'
assertFileNotRegex home-files/.config/fish/config.fish '/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects'
assertFileNotRegex home-files/.config/nushell/config.nu 'source /nix/store/[^/]*-pay-respects-nushell-config'
'';
}

View file

@ -1,3 +1,5 @@
{ lib, realPkgs, ... }:
{
programs = {
pay-respects.enable = true;
@ -7,25 +9,27 @@
nushell.enable = true;
};
_module.args.pkgs = lib.mkForce realPkgs;
nmt.script = ''
assertFileExists home-files/.bashrc
assertFileContains \
assertFileRegex \
home-files/.bashrc \
'eval "$(@pay-respects@/bin/pay-respects bash --alias)"'
'eval "$(/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects bash --alias)"'
assertFileExists home-files/.zshrc
assertFileContains \
assertFileRegex \
home-files/.zshrc \
'eval "$(@pay-respects@/bin/pay-respects zsh --alias)"'
'eval "$(/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects zsh --alias)"'
assertFileExists home-files/.config/fish/config.fish
assertFileContains \
assertFileRegex \
home-files/.config/fish/config.fish \
'@pay-respects@/bin/pay-respects fish --alias | source'
'/nix/store/[^/]*-pay-respects-[^/]*/bin/pay-respects fish --alias | source'
assertFileExists home-files/.config/nushell/config.nu
assertFileContains \
assertFileRegex \
home-files/.config/nushell/config.nu \
'@pay-respects@/bin/pay-respects nushell --alias [<alias>]'
'source /nix/store/[^/]*-pay-respects-nushell-config'
'';
}

View file

@ -10,7 +10,7 @@
export GOT="$(tail -n 5 `_abs home-files/.config/fish/config.fish`)"
export NOT_EXPECTED="
if test \"\$TERM\" != dumb
/home/hm-user/.nix-profile/bin/starship init fish | source
@starship@/bin/starship init fish | source
end"

View file

@ -14,7 +14,7 @@
export GOT="$(tail -n 5 `_abs home-files/.config/fish/config.fish`)"
export EXPECTED="
if test \"\$TERM\" != dumb
/home/hm-user/.nix-profile/bin/starship init fish | source
@starship@/bin/starship init fish | source
end"