Skip to content

Commit 62f91c1

Browse files
Merge pull request #464 from 1Password/mrj/nix-flake-shell-functions
fix(nix): Update flake.nix to configure Shell Plugins as functions vs. aliases
2 parents 0b021e2 + b2df10c commit 62f91c1

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
@@ -55,28 +55,55 @@ in {
5555
pkg-exe-names = map getExeName cfg.plugins;
5656
# Explanation:
5757
# Map over `cfg.plugins` (the value of the `plugins` option provided by the user)
58-
# and for each package specified, get the executable name, then create a shell alias
58+
# and for each package specified, get the executable name, then create a shell function
5959
# of the form:
60-
# `alias {pkg}="op plugin run -- {pkg}"`
60+
#
61+
# For Bash and Zsh:
62+
# ```
63+
# {pkg}() {
64+
# op plugin run -- {pkg};
65+
# }
66+
# ```
67+
#
68+
# And for Fish:
69+
# ```
70+
# function {pkg} --wraps {pkg}
71+
# op plugin run -- {pkg}
72+
# end
73+
# ```
6174
# where `{pkg}` is the executable name of the package
62-
aliases = listToAttrs (map (package: {
63-
name = package;
64-
value = "op plugin run -- ${package}";
65-
}) pkg-exe-names);
75+
posixFunctions = map (package: ''
76+
${package}() {
77+
op plugin run -- ${package};
78+
}
79+
'') pkg-exe-names;
80+
fishFunctions = map (package: ''
81+
function ${package} --wraps "${package}" --description "1Password Shell Plugin for ${package}"
82+
op plugin run -- ${package}
83+
end
84+
'') pkg-exe-names;
6685
packages = lib.optional (cfg.package != null) cfg.package ++ cfg.plugins;
6786
in mkIf cfg.enable (mkMerge [
6887
({
88+
# for Fish its the same option path between NixOS vs. home-manager
89+
fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions;
90+
} // optionalAttrs is-home-manager {
6991
programs = {
70-
bash.shellAliases = aliases;
71-
zsh.shellAliases = aliases;
72-
fish.shellAliases = aliases;
92+
# for the Bash and Zsh home-manager modules,
93+
# the initExtra option is equivalent to Fish's interactiveShellInit
94+
bash.initExtra = strings.concatStringsSep "\n" posixFunctions;
95+
zsh.initExtra = strings.concatStringsSep "\n" posixFunctions;
7396
};
74-
} // optionalAttrs is-home-manager {
7597
home = {
7698
inherit packages;
7799
sessionVariables = { OP_PLUGINS_SOURCED = "1"; };
78100
};
79101
} // optionalAttrs (!is-home-manager) {
102+
programs = {
103+
bash.interactiveShellInit =
104+
strings.concatStringsSep "\n" posixFunctions;
105+
zsh.interactiveShellInit = strings.concatStringsSep "\n" posixFunctions;
106+
};
80107
environment = {
81108
systemPackages = packages;
82109
variables = { OP_PLUGINS_SOURCED = "1"; };

0 commit comments

Comments
 (0)