1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-31 04:04:32 +00:00

pay-respects: allow setting custom options

This commit is contained in:
jaredmontoya 2025-03-20 01:15:51 +01:00
parent 467dbe9e2a
commit 3e54b76507
3 changed files with 46 additions and 34 deletions

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

@ -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'
'';
}