|
1 | | -{ pkgs, lib, config, is-home-manager, ... }: |
| 1 | +{ |
| 2 | + pkgs, |
| 3 | + lib, |
| 4 | + config, |
| 5 | + is-home-manager, |
| 6 | + ... |
| 7 | +}: |
2 | 8 | with lib; |
3 | 9 | let |
4 | 10 | cfg = config.programs._1password-shell-plugins; |
5 | 11 |
|
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 |
8 | 15 | 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: |
14 | 25 | # NOTE: SAFETY: This is okay because the `packages` list is also referred |
15 | 26 | # to below as `home.packages = packages;` or `environment.systemPackages = packages;` |
16 | 27 | # depending on if it's using `home-manager` or not; this means that Nix can still |
17 | 28 | # compute the dependency tree, even though we're discarding string context here, |
18 | 29 | # since the packages are still referred to below without discarding string context. |
19 | 30 | strings.unsafeDiscardStringContext (baseNameOf (getExe package)); |
20 | | -in { |
| 31 | +in |
| 32 | +{ |
21 | 33 | options = { |
22 | 34 | programs._1password-shell-plugins = { |
23 | 35 | enable = mkEnableOption "1Password Shell Plugins"; |
|
32 | 44 | cachix |
33 | 45 | ] |
34 | 46 | ''; |
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/"; |
37 | 48 | # this is a bit of a hack to do option validation; |
38 | 49 | # ensure that the list of packages include only packages |
39 | 50 | # 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: |
42 | 55 | if (elem (getExeName package) supported_plugins) then |
43 | 56 | package |
44 | 57 | 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; |
49 | 60 | }; |
50 | 61 | }; |
51 | 62 | }; |
52 | | - |
| 63 | + |
53 | 64 | config = let |
54 | 65 | # executable names as strings, e.g. `pkgs.gh` => `"gh"`, `pkgs.awscli2` => `"aws"` |
55 | 66 | pkg-exe-names = map getExeName cfg.plugins; |
|
0 commit comments