|
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 | }; |
|
84 | 80 | # end |
85 | 81 | # ``` |
86 | 82 | # where `{pkg}` is the executable name of the package |
87 | | - posixFunctions = map (package: '' |
88 | | - ${package}() { |
89 | | - op plugin run -- ${package}; |
90 | | - } |
91 | | - '') pkg-exe-names; |
92 | | - fishFunctions = map (package: '' |
93 | | - function ${package} --wraps "${package}" --description "1Password Shell Plugin for ${package}" |
94 | | - op plugin run -- ${package} |
95 | | - end |
96 | | - '') pkg-exe-names; |
| 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 | 97 | packages = lib.optional (cfg.package != null) cfg.package ++ cfg.plugins; |
98 | 98 | in |
99 | 99 | mkIf cfg.enable (mkMerge [ |
100 | | - ( |
101 | | - { |
102 | | - # for Fish its the same option path between NixOS vs. home-manager |
103 | | - fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions; |
104 | | - } |
105 | | - // optionalAttrs is-home-manager { |
106 | | - programs = { |
107 | | - # for the Bash and Zsh home-manager modules, |
108 | | - # the initExtra option is equivalent to Fish's interactiveShellInit |
109 | | - bash.initExtra = strings.concatStringsSep "\n" posixFunctions; |
110 | | - zsh.initExtra = strings.concatStringsSep "\n" posixFunctions; |
111 | | - }; |
112 | | - home = { |
113 | | - inherit packages; |
114 | | - sessionVariables = { |
115 | | - OP_PLUGINS_SOURCED = "1"; |
116 | | - }; |
117 | | - }; |
118 | | - } |
119 | | - // optionalAttrs (!is-home-manager) { |
120 | | - programs = { |
121 | | - bash.interactiveShellInit = |
122 | | - strings.concatStringsSep "\n" posixFunctions; |
123 | | - zsh.interactiveShellInit = strings.concatStringsSep "\n" posixFunctions; |
124 | | - }; |
125 | | - environment = { |
126 | | - systemPackages = packages; |
127 | | - variables = { |
128 | | - OP_PLUGINS_SOURCED = "1"; |
129 | | - }; |
130 | | - }; |
131 | | - } |
132 | | - ) |
| 100 | + { |
| 101 | + programs.fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions; |
| 102 | + } |
| 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 | + }) |
133 | 126 | ]); |
134 | 127 | } |
| 128 | + |
0 commit comments