|
132 | 132 | "nvim" = "custom-nvim";
|
133 | 133 | };
|
134 | 134 | };
|
| 135 | + |
| 136 | + overrideAttrs = mkOption { |
| 137 | + type = with types; functionTo attrs; |
| 138 | + description = '' |
| 139 | + Function to override attributes from the final package. |
| 140 | + ''; |
| 141 | + default = lib.id; |
| 142 | + example = '' |
| 143 | + old: { |
| 144 | + pname = "''${old.pname}-wrapped"; |
| 145 | + } |
| 146 | + ''; |
| 147 | + }; |
135 | 148 | };
|
136 | 149 |
|
137 | 150 | config = {
|
|
155 | 168 | if config.value == null
|
156 | 169 | then unsetArg
|
157 | 170 | else setArg;
|
158 |
| - result = |
159 |
| - pkgs.symlinkJoin ({ |
160 |
| - paths = [config.basePackage] ++ config.extraPackages; |
161 |
| - nativeBuildInputs = [pkgs.makeWrapper]; |
162 |
| - postBuild = let |
163 |
| - envArgs = lib.mapAttrsToList envToWrapperArg config.env; |
164 |
| - # Yes, the arguments are escaped later, yes, this is intended to "double escape", |
165 |
| - # so that they are escaped for wrapProgram and for the final binary too. |
166 |
| - prependFlagArgs = map (args: ["--add-flags" (lib.escapeShellArg args)]) config.prependFlags; |
167 |
| - appendFlagArgs = map (args: ["--append-flags" (lib.escapeShellArg args)]) config.appendFlags; |
168 |
| - pathArgs = map (p: ["--prefix" "PATH" ":" "${p}/bin"]) config.pathAdd; |
169 |
| - allArgs = lib.flatten (envArgs ++ prependFlagArgs ++ appendFlagArgs ++ pathArgs); |
170 |
| - in '' |
171 |
| - for file in $out/bin/*; do |
172 |
| - echo "Wrapping $file" |
173 |
| - wrapProgram \ |
174 |
| - $file \ |
175 |
| - ${lib.escapeShellArgs allArgs} \ |
176 |
| - ${config.extraWrapperFlags} |
177 |
| - done |
| 171 | + result = pkgs.symlinkJoin ( |
| 172 | + { |
| 173 | + paths = [config.basePackage] ++ config.extraPackages; |
| 174 | + nativeBuildInputs = [pkgs.makeWrapper]; |
| 175 | + postBuild = let |
| 176 | + envArgs = lib.mapAttrsToList envToWrapperArg config.env; |
| 177 | + # Yes, the arguments are escaped later, yes, this is intended to "double escape", |
| 178 | + # so that they are escaped for wrapProgram and for the final binary too. |
| 179 | + prependFlagArgs = map (args: ["--add-flags" (lib.escapeShellArg args)]) config.prependFlags; |
| 180 | + appendFlagArgs = map (args: ["--append-flags" (lib.escapeShellArg args)]) config.appendFlags; |
| 181 | + pathArgs = map (p: ["--prefix" "PATH" ":" "${p}/bin"]) config.pathAdd; |
| 182 | + allArgs = lib.flatten (envArgs ++ prependFlagArgs ++ appendFlagArgs ++ pathArgs); |
| 183 | + in '' |
| 184 | + for file in $out/bin/*; do |
| 185 | + echo "Wrapping $file" |
| 186 | + wrapProgram \ |
| 187 | + $file \ |
| 188 | + ${lib.escapeShellArgs allArgs} \ |
| 189 | + ${config.extraWrapperFlags} |
| 190 | + done |
178 | 191 |
|
179 |
| - # Some derivations have nested symlinks here |
180 |
| - if [[ -d $out/share/applications && ! -w $out/share/applications ]]; then |
181 |
| - echo "Detected nested symlink, fixing" |
182 |
| - temp=$(mktemp -d) |
183 |
| - cp -v $out/share/applications/* $temp |
184 |
| - rm -vf $out/share/applications |
185 |
| - mkdir -pv $out/share/applications |
186 |
| - cp -v $temp/* $out/share/applications |
187 |
| - fi |
| 192 | + # Some derivations have nested symlinks here |
| 193 | + if [[ -d $out/share/applications && ! -w $out/share/applications ]]; then |
| 194 | + echo "Detected nested symlink, fixing" |
| 195 | + temp=$(mktemp -d) |
| 196 | + cp -v $out/share/applications/* $temp |
| 197 | + rm -vf $out/share/applications |
| 198 | + mkdir -pv $out/share/applications |
| 199 | + cp -v $temp/* $out/share/applications |
| 200 | + fi |
188 | 201 |
|
189 |
| - cd $out/bin |
190 |
| - for exe in *; do |
| 202 | + cd $out/bin |
| 203 | + for exe in *; do |
191 | 204 |
|
192 |
| - if false; then |
193 |
| - exit 2 |
194 |
| - ${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: '' |
195 |
| - elif [[ $exe == ${lib.escapeShellArg name} ]]; then |
196 |
| - newexe=${lib.escapeShellArg value} |
197 |
| - mv -vf $exe $newexe |
198 |
| - '') |
199 |
| - config.renames)} |
200 |
| - else |
201 |
| - newexe=$exe |
202 |
| - fi |
| 205 | + if false; then |
| 206 | + exit 2 |
| 207 | + ${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: '' |
| 208 | + elif [[ $exe == ${lib.escapeShellArg name} ]]; then |
| 209 | + newexe=${lib.escapeShellArg value} |
| 210 | + mv -vf $exe $newexe |
| 211 | + '') |
| 212 | + config.renames)} |
| 213 | + else |
| 214 | + newexe=$exe |
| 215 | + fi |
203 | 216 |
|
204 |
| - # Fix .desktop files |
205 |
| - # This list of fixes might not be exhaustive |
206 |
| - for file in $out/share/applications/*; do |
207 |
| - echo "Fixing file=$file for exe=$exe" |
208 |
| - set -x |
209 |
| - trap "set +x" ERR |
210 |
| - sed -i "s#/nix/store/.*/bin/$exe #$out/bin/$newexe #" "$file" |
211 |
| - sed -i -E "s#Exec=$exe([[:space:]]*)#Exec=$out/bin/$newexe\1#g" "$file" |
212 |
| - sed -i -E "s#TryExec=$exe([[:space:]]*)#TryExec=$out/bin/$newexe\1#g" "$file" |
213 |
| - set +x |
214 |
| - done |
| 217 | + # Fix .desktop files |
| 218 | + # This list of fixes might not be exhaustive |
| 219 | + for file in $out/share/applications/*; do |
| 220 | + echo "Fixing file=$file for exe=$exe" |
| 221 | + set -x |
| 222 | + trap "set +x" ERR |
| 223 | + sed -i "s#/nix/store/.*/bin/$exe #$out/bin/$newexe #" "$file" |
| 224 | + sed -i -E "s#Exec=$exe([[:space:]]*)#Exec=$out/bin/$newexe\1#g" "$file" |
| 225 | + sed -i -E "s#TryExec=$exe([[:space:]]*)#TryExec=$out/bin/$newexe\1#g" "$file" |
| 226 | + set +x |
215 | 227 | done
|
| 228 | + done |
216 | 229 |
|
217 | 230 |
|
218 |
| - # I don't know of a better way to create a multe-output derivation for symlinkJoin |
219 |
| - # So if the packages have man, just link them into $out |
220 |
| - ${ |
221 |
| - lib.concatMapStringsSep "\n" |
222 |
| - (p: |
223 |
| - if lib.hasAttr "man" p |
224 |
| - then "${pkgs.xorg.lndir}/bin/lndir -silent ${p.man} $out" |
225 |
| - else "#") |
226 |
| - ([config.basePackage] ++ config.extraPackages) |
227 |
| - } |
228 |
| - ''; |
229 |
| - passthru = |
230 |
| - (config.basePackage.passthru or {}) |
231 |
| - // { |
232 |
| - unwrapped = config.basePackage; |
233 |
| - }; |
234 |
| - } |
235 |
| - // lib.getAttrs [ |
236 |
| - "name" |
237 |
| - "meta" |
238 |
| - ] |
239 |
| - config.basePackage) |
240 |
| - // (lib.optionalAttrs (lib.hasAttr "pname" config.basePackage) { |
241 |
| - inherit (config.basePackage) pname; |
242 |
| - }) |
243 |
| - // (lib.optionalAttrs (lib.hasAttr "version" config.basePackage) { |
244 |
| - inherit (config.basePackage) version; |
245 |
| - }); |
| 231 | + # I don't know of a better way to create a multe-output derivation for symlinkJoin |
| 232 | + # So if the packages have man, just link them into $out |
| 233 | + ${ |
| 234 | + lib.concatMapStringsSep "\n" |
| 235 | + (p: |
| 236 | + if lib.hasAttr "man" p |
| 237 | + then "${pkgs.xorg.lndir}/bin/lndir -silent ${p.man} $out" |
| 238 | + else "#") |
| 239 | + ([config.basePackage] ++ config.extraPackages) |
| 240 | + } |
| 241 | + ''; |
| 242 | + passthru = |
| 243 | + (config.basePackage.passthru or {}) |
| 244 | + // { |
| 245 | + unwrapped = config.basePackage; |
| 246 | + }; |
| 247 | + } |
| 248 | + // { |
| 249 | + inherit (config.basePackage) name meta; |
| 250 | + } |
| 251 | + ); |
246 | 252 | in
|
247 |
| - lib.recursiveUpdate result { |
| 253 | + lib.recursiveUpdate ((result.overrideAttrs config.overrideAttrs).overrideAttrs (old: |
| 254 | + lib.optionalAttrs (lib.hasAttr "pname" old) { |
| 255 | + pname = lib.warn "wrapper-manager: ${old.name}: symlinkJoin requires a name, not a pname+version" old.pname; |
| 256 | + })) { |
248 | 257 | meta.outputsToInstall = ["out"];
|
249 | 258 | };
|
250 | 259 | };
|
|
0 commit comments