|
1 | | -{ |
2 | | - pkgs, |
3 | | - lib, |
4 | | - config, |
5 | | - is-home-manager, |
6 | | - ... |
7 | | -}: |
| 1 | +{ pkgs, lib, config, is-home-manager, ... }: |
8 | 2 | with lib; |
9 | 3 | let |
10 | 4 | cfg = config.programs._1password-shell-plugins; |
|
50 | 44 | # for which the executable has a supported 1Password Shell Plugin |
51 | 45 | apply = |
52 | 46 | 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; |
60 | 56 | }; |
61 | 57 | }; |
62 | 58 | }; |
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; |
89 | 102 | } |
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 | + ]); |
123 | 127 | } |
| 128 | + |
0 commit comments