Skip to content

Commit d0f4f2d

Browse files
committed
fix(nix): Resolve warning about 1Password nixpkgs name
1 parent 9e0c714 commit d0f4f2d

File tree

1 file changed

+73
-50
lines changed

1 file changed

+73
-50
lines changed

nix/shell-plugins.nix

Lines changed: 73 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1-
{ pkgs, lib, config, is-home-manager, ... }:
1+
{
2+
pkgs,
3+
lib,
4+
config,
5+
is-home-manager,
6+
...
7+
}:
28
with lib;
39
let
410
cfg = config.programs._1password-shell-plugins;
511

6-
supported_plugins = splitString "\n" (lib.readFile "${
7-
# get the list of supported plugin executable names
12+
supported_plugins = splitString "\n" (
13+
lib.readFile "${
14+
# get the list of supported plugin executable names
815
pkgs.runCommand "op-plugin-list" { }
9-
# 1Password CLI tries to create the config directory automatically, so set a temp XDG_CONFIG_HOME
10-
# since we don't actually need it for this
11-
"mkdir $out && XDG_CONFIG_HOME=$out ${pkgs._1password}/bin/op plugin list | cut -d ' ' -f1 | tail -n +2 > $out/plugins.txt"
12-
}/plugins.txt");
13-
getExeName = package:
16+
# 1Password CLI tries to create the config directory automatically, so set a temp XDG_CONFIG_HOME
17+
# since we don't actually need it for this
18+
"mkdir $out && XDG_CONFIG_HOME=$out ${
19+
if cfg.package != null then cfg.package else pkgs._1password-cli
20+
}/bin/op plugin list | cut -d ' ' -f1 | tail -n +2 > $out/plugins.txt"
21+
}/plugins.txt"
22+
);
23+
getExeName =
24+
package:
1425
# NOTE: SAFETY: This is okay because the `packages` list is also referred
1526
# to below as `home.packages = packages;` or `environment.systemPackages = packages;`
1627
# depending on if it's using `home-manager` or not; this means that Nix can still
1728
# compute the dependency tree, even though we're discarding string context here,
1829
# since the packages are still referred to below without discarding string context.
1930
strings.unsafeDiscardStringContext (baseNameOf (getExe package));
20-
in {
31+
in
32+
{
2133
options = {
2234
programs._1password-shell-plugins = {
2335
enable = mkEnableOption "1Password Shell Plugins";
@@ -32,55 +44,66 @@ in {
3244
cachix
3345
]
3446
'';
35-
description =
36-
"CLI Packages to enable 1Password Shell Plugins for; ensure that a Shell Plugin exists by checking the docs: https://developer.1password.com/docs/cli/shell-plugins/";
47+
description = "CLI Packages to enable 1Password Shell Plugins for; ensure that a Shell Plugin exists by checking the docs: https://developer.1password.com/docs/cli/shell-plugins/";
3748
# this is a bit of a hack to do option validation;
3849
# ensure that the list of packages include only packages
3950
# for which the executable has a supported 1Password Shell Plugin
40-
apply = package_list:
41-
map (package:
51+
apply =
52+
package_list:
53+
map (
54+
package:
4255
if (elem (getExeName package) supported_plugins) then
4356
package
4457
else
45-
abort "${
46-
getExeName package
47-
} 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/")
48-
package_list;
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;
4960
};
5061
};
5162
};
5263

53-
config = let
54-
# executable names as strings, e.g. `pkgs.gh` => `"gh"`, `pkgs.awscli2` => `"aws"`
55-
pkg-exe-names = map getExeName cfg.plugins;
56-
# Explanation:
57-
# 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
59-
# of the form:
60-
# `alias {pkg}="op plugin run -- {pkg}"`
61-
# 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);
66-
packages = lib.optional (cfg.package != null) cfg.package ++ cfg.plugins;
67-
in mkIf cfg.enable (mkMerge [
68-
({
69-
programs = {
70-
bash.shellAliases = aliases;
71-
zsh.shellAliases = aliases;
72-
fish.shellAliases = aliases;
73-
};
74-
} // optionalAttrs is-home-manager {
75-
home = {
76-
inherit packages;
77-
sessionVariables = { OP_PLUGINS_SOURCED = "1"; };
78-
};
79-
} // optionalAttrs (!is-home-manager) {
80-
environment = {
81-
systemPackages = packages;
82-
variables = { OP_PLUGINS_SOURCED = "1"; };
83-
};
84-
})
85-
]);
64+
config =
65+
let
66+
# executable names as strings, e.g. `pkgs.gh` => `"gh"`, `pkgs.awscli2` => `"aws"`
67+
pkg-exe-names = map getExeName cfg.plugins;
68+
# Explanation:
69+
# Map over `cfg.plugins` (the value of the `plugins` option provided by the user)
70+
# and for each package specified, get the executable name, then create a shell alias
71+
# of the form:
72+
# `alias {pkg}="op plugin run -- {pkg}"`
73+
# where `{pkg}` is the executable name of the package
74+
aliases = listToAttrs (
75+
map (package: {
76+
name = package;
77+
value = "op plugin run -- ${package}";
78+
}) pkg-exe-names
79+
);
80+
packages = lib.optional (cfg.package != null) cfg.package ++ cfg.plugins;
81+
in
82+
mkIf cfg.enable (mkMerge [
83+
(
84+
{
85+
programs = {
86+
bash.shellAliases = aliases;
87+
zsh.shellAliases = aliases;
88+
fish.shellAliases = aliases;
89+
};
90+
}
91+
// optionalAttrs is-home-manager {
92+
home = {
93+
inherit packages;
94+
sessionVariables = {
95+
OP_PLUGINS_SOURCED = "1";
96+
};
97+
};
98+
}
99+
// optionalAttrs (!is-home-manager) {
100+
environment = {
101+
systemPackages = packages;
102+
variables = {
103+
OP_PLUGINS_SOURCED = "1";
104+
};
105+
};
106+
}
107+
)
108+
]);
86109
}

0 commit comments

Comments
 (0)