Skip to content

Commit f3b595b

Browse files
committed
fix(nix): Update flake.nix to configure Shell Plugins as functions instead of aliases
1 parent 0b156f8 commit f3b595b

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

nix/shell-plugins.nix

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,55 @@ in {
5454
pkg-exe-names = map getExeName cfg.plugins;
5555
# Explanation:
5656
# Map over `cfg.plugins` (the value of the `plugins` option provided by the user)
57-
# and for each package specified, get the executable name, then create a shell alias
57+
# and for each package specified, get the executable name, then create a shell function
5858
# of the form:
59-
# `alias {pkg}="op plugin run -- {pkg}"`
59+
#
60+
# For Bash and Zsh:
61+
# ```
62+
# {pkg}() {
63+
# op plugin run -- {pkg};
64+
# }
65+
# ```
66+
#
67+
# And for Fish:
68+
# ```
69+
# function {pkg} --wraps {pkg}
70+
# op plugin run -- {pkg}
71+
# end
72+
# ```
6073
# where `{pkg}` is the executable name of the package
61-
aliases = listToAttrs (map (package: {
62-
name = package;
63-
value = "op plugin run -- ${package}";
64-
}) pkg-exe-names);
74+
posixFunctions = map (package: ''
75+
${package}() {
76+
op plugin run -- ${package};
77+
}
78+
'') pkg-exe-names;
79+
fishFunctions = map (package: ''
80+
function ${package} --wraps "${package}" --description "1Password Shell Plugin for ${package}"
81+
op plugin run -- ${package}
82+
end
83+
'') pkg-exe-names;
6584
packages = [ pkgs._1password ] ++ cfg.plugins;
6685
in mkIf cfg.enable (mkMerge [
6786
({
87+
# for Fish its the same option path between NixOS vs. home-manager
88+
fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions;
89+
} // optionalAttrs is-home-manager {
6890
programs = {
69-
bash.shellAliases = aliases;
70-
zsh.shellAliases = aliases;
71-
fish.shellAliases = aliases;
91+
# for the Bash and Zsh home-manager modules,
92+
# the initExtra option is equivalent to Fish's interactiveShellInit
93+
bash.initExtra = strings.concatStringsSep "\n" posixFunctions;
94+
zsh.initExtra = strings.concatStringsSep "\n" posixFunctions;
7295
};
73-
} // optionalAttrs is-home-manager {
7496
home = {
7597
inherit packages;
7698
sessionVariables = { OP_PLUGINS_SOURCED = "1"; };
7799
};
78100
} // optionalAttrs (!is-home-manager) {
101+
programs = {
102+
bash.interactiveShellInit =
103+
strings.concatStringsSep "\n" posixFunctions;
104+
zsh.interactiveShellInit = strings.concatStringsSep "\n" posixFunctions;
105+
};
79106
environment = {
80107
systemPackages = packages;
81108
variables = { OP_PLUGINS_SOURCED = "1"; };

0 commit comments

Comments
 (0)