Skip to content

Commit fc45441

Browse files
committed
add fish to host configs
set programs fish at top level merge
1 parent 6be39d6 commit fc45441

File tree

1 file changed

+78
-73
lines changed

1 file changed

+78
-73
lines changed

nix/shell-plugins.nix

Lines changed: 78 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
{
2-
pkgs,
3-
lib,
4-
config,
5-
is-home-manager,
6-
...
7-
}:
1+
{ pkgs, lib, config, is-home-manager, ... }:
82
with lib;
93
let
104
cfg = config.programs._1password-shell-plugins;
@@ -50,74 +44,85 @@ in
5044
# for which the executable has a supported 1Password Shell Plugin
5145
apply =
5246
package_list:
53-
map (
54-
package:
55-
if (elem (getExeName package) supported_plugins) then
56-
package
57-
else
58-
abort "${getExeName package} is not a valid 1Password Shell Plugin. A list of supported plugins can be found by running `op plugin list` or at: https://developer.1password.com/docs/cli/shell-plugins/"
59-
) package_list;
47+
map
48+
(
49+
package:
50+
if (elem (getExeName package) supported_plugins) then
51+
package
52+
else
53+
abort "${getExeName package} is not a valid 1Password Shell Plugin. A list of supported plugins can be found by running `op plugin list` or at: https://developer.1password.com/docs/cli/shell-plugins/"
54+
)
55+
package_list;
6056
};
6157
};
6258
};
63-
64-
config = let
65-
# executable names as strings, e.g. `pkgs.gh` => `"gh"`, `pkgs.awscli2` => `"aws"`
66-
pkg-exe-names = map getExeName cfg.plugins;
67-
# Explanation:
68-
# Map over `cfg.plugins` (the value of the `plugins` option provided by the user)
69-
# and for each package specified, get the executable name, then create a shell function
70-
# of the form:
71-
#
72-
# For Bash and Zsh:
73-
# ```
74-
# {pkg}() {
75-
# op plugin run -- {pkg};
76-
# }
77-
# ```
78-
#
79-
# And for Fish:
80-
# ```
81-
# function {pkg} --wraps {pkg}
82-
# op plugin run -- {pkg}
83-
# end
84-
# ```
85-
# where `{pkg}` is the executable name of the package
86-
posixFunctions = map (package: ''
87-
${package}() {
88-
op plugin run -- ${package} "$@";
59+
60+
config =
61+
let
62+
# executable names as strings, e.g. `pkgs.gh` => `"gh"`, `pkgs.awscli2` => `"aws"`
63+
pkg-exe-names = map getExeName cfg.plugins;
64+
# Explanation:
65+
# Map over `cfg.plugins` (the value of the `plugins` option provided by the user)
66+
# and for each package specified, get the executable name, then create a shell function
67+
# of the form:
68+
#
69+
# For Bash and Zsh:
70+
# ```
71+
# {pkg}() {
72+
# op plugin run -- {pkg};
73+
# }
74+
# ```
75+
#
76+
# And for Fish:
77+
# ```
78+
# function {pkg} --wraps {pkg}
79+
# op plugin run -- {pkg}
80+
# end
81+
# ```
82+
# where `{pkg}` is the executable name of the package
83+
posixFunctions = map
84+
(package: ''
85+
${package}() {
86+
op plugin run -- ${package} "$@";
87+
}
88+
'')
89+
pkg-exe-names;
90+
fishFunctions = map
91+
(package: ''
92+
function ${package} --wraps "${package}" --description "1Password Shell Plugin for ${package}"
93+
op plugin run -- ${package} $argv
94+
end
95+
'')
96+
pkg-exe-names;
97+
packages = lib.optional (cfg.package != null) cfg.package ++ cfg.plugins;
98+
in
99+
mkIf cfg.enable (mkMerge [
100+
{
101+
programs.fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions;
89102
}
90-
'') pkg-exe-names;
91-
fishFunctions = map (package: ''
92-
function ${package} --wraps "${package}" --description "1Password Shell Plugin for ${package}"
93-
op plugin run -- ${package} $argv
94-
end
95-
'') pkg-exe-names;
96-
packages = lib.optional (cfg.package != null) cfg.package ++ cfg.plugins;
97-
in mkIf cfg.enable (mkMerge [
98-
(
99-
optionalAttrs is-home-manager {
100-
programs = {
101-
# for the Bash and Zsh home-manager modules,
102-
# the initExtra option is equivalent to Fish's interactiveShellInit
103-
fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions;
104-
bash.initExtra = strings.concatStringsSep "\n" posixFunctions;
105-
zsh.initExtra = strings.concatStringsSep "\n" posixFunctions;
106-
};
107-
home = {
108-
inherit packages;
109-
sessionVariables = { OP_PLUGINS_SOURCED = "1"; };
110-
};
111-
} // optionalAttrs (!is-home-manager) {
112-
programs = {
113-
bash.interactiveShellInit =
114-
strings.concatStringsSep "\n" posixFunctions;
115-
zsh.interactiveShellInit = strings.concatStringsSep "\n" posixFunctions;
116-
};
117-
environment = {
118-
systemPackages = packages;
119-
variables = { OP_PLUGINS_SOURCED = "1"; };
120-
};
121-
})
122-
]);
103+
(optionalAttrs is-home-manager {
104+
programs = {
105+
# for the Bash and Zsh home-manager modules,
106+
# the initExtra option is equivalent to Fish's interactiveShellInit
107+
bash.initExtra = strings.concatStringsSep "\n" posixFunctions;
108+
zsh.initExtra = strings.concatStringsSep "\n" posixFunctions;
109+
};
110+
home = {
111+
inherit packages;
112+
sessionVariables = { OP_PLUGINS_SOURCED = "1"; };
113+
};
114+
})
115+
(optionalAttrs (!is-home-manager) {
116+
programs = {
117+
bash.interactiveShellInit =
118+
strings.concatStringsSep "\n" posixFunctions;
119+
zsh.interactiveShellInit = strings.concatStringsSep "\n" posixFunctions;
120+
};
121+
environment = {
122+
systemPackages = packages;
123+
variables = { OP_PLUGINS_SOURCED = "1"; };
124+
};
125+
})
126+
]);
123127
}
128+

0 commit comments

Comments
 (0)