This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

wrapLib: move makeWrapper into wrapLib, refactor users

+259 -262
-7
flake.nix
··· 200 200 }; 201 201 }; 202 202 flake.lib = import ./lib { inherit (nixpkgs) lib; }; 203 - flake.libWithPkgs = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed ( 204 - system: 205 - import ./lib/pkgs.nix { 206 - inherit (nixpkgs) lib; 207 - pkgs = nixpkgs.legacyPackages.${system}; 208 - } 209 - ); 210 203 }; 211 204 }
-222
lib/make-wrapper.nix
··· 1 - { lib, pkgs, ... }: 2 - { 3 - /** 4 - Create a wrapped application that preserves all original outputs (man pages, completions, etc.) 5 - 6 - # Arguments 7 - 8 - - `package`: The package to wrap 9 - - `runtimeInputs`: List of packages to add to PATH (optional) 10 - - `env`: Attribute set of environment variables to export (optional) 11 - - `flags`: Attribute set of command-line flags to add (optional) 12 - - `flagSeparator`: Separator between flag names and values (optional, defaults to " ") 13 - - `preHook`: Shell script to run before executing the command (optional) 14 - - `passthru`: Attribute set to pass through to the wrapped derivation (optional) 15 - - `aliases`: List of additional names to symlink to the wrapped executable (optional) 16 - - `wrapper`: Custom wrapper function (optional, defaults to exec'ing the original binary with flags) 17 - - Called with { env, flags, envString, flagsString, exePath, preHook } 18 - 19 - # Example 20 - 21 - ```nix 22 - makeWrapper pkgs.curl { 23 - runtimeInputs = [ pkgs.jq ]; 24 - env = { 25 - CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; 26 - }; 27 - flags = { 28 - "--silent" = { }; # becomes --silent 29 - "--connect-timeout" = "30"; # becomes --connect-timeout 30 30 - }; 31 - preHook = '' 32 - echo "Making request..." >&2 33 - ''; 34 - } 35 - 36 - # Or with custom wrapper: 37 - makeWrapper pkgs.someProgram { 38 - wrapper = { exePath, flagsString, envString, preHook, ... }: '' 39 - ${envString} 40 - ${preHook} 41 - echo "Custom logic here" 42 - exec ${exePath} ${flagsString} "$@" 43 - ''; 44 - } 45 - ``` 46 - */ 47 - makeWrapper = 48 - package: 49 - { 50 - runtimeInputs ? [ ], 51 - env ? { }, 52 - flags ? { }, 53 - flagSeparator ? " ", # " " for "--flag value" or "=" for "--flag=value" 54 - preHook ? "", 55 - passthru ? { }, 56 - aliases ? [ ], 57 - wrapper ? ( 58 - { 59 - exePath, 60 - flagsString, 61 - envString, 62 - preHook, 63 - ... 64 - }: 65 - '' 66 - ${envString} 67 - ${preHook} 68 - exec ${exePath}${flagsString} "$@" 69 - '' 70 - ), 71 - }: 72 - let 73 - # Extract binary name from the exe path 74 - exePath = lib.getExe package; 75 - binName = baseNameOf exePath; 76 - 77 - # Generate environment variable exports 78 - envString = 79 - if env == { } then 80 - "" 81 - else 82 - lib.concatStringsSep "\n" ( 83 - lib.mapAttrsToList (name: value: ''export ${name}="${toString value}"'') env 84 - ) 85 - + "\n"; 86 - 87 - # Generate flag arguments with proper line breaks and indentation 88 - flagsString = 89 - if flags == { } then 90 - "" 91 - else 92 - " \\\n " 93 - + lib.concatStringsSep " \\\n " ( 94 - lib.mapAttrsToList ( 95 - name: value: 96 - if value == { } then "${name}" else "${name}${flagSeparator}${lib.escapeShellArg (toString value)}" 97 - ) flags 98 - ); 99 - 100 - finalWrapper = wrapper { 101 - inherit 102 - env 103 - flags 104 - envString 105 - flagsString 106 - exePath 107 - preHook 108 - ; 109 - }; 110 - 111 - # Multi-output aware symlink join function 112 - multiOutputSymlinkJoin = 113 - { 114 - name, 115 - paths, 116 - outputs ? [ "out" ], 117 - originalOutputs ? { }, 118 - passthru ? { }, 119 - meta ? { }, 120 - aliases ? [ ], 121 - binName ? null, 122 - ... 123 - }@args: 124 - pkgs.stdenv.mkDerivation ( 125 - { 126 - inherit name outputs; 127 - 128 - buildCommand = '' 129 - # Symlink all paths to the main output 130 - mkdir -p $out 131 - for path in ${lib.concatStringsSep " " (map toString paths)}; do 132 - ${pkgs.lndir}/bin/lndir -silent "$path" $out 133 - done 134 - 135 - # Create symlinks for aliases 136 - ${lib.optionalString (aliases != [ ] && binName != null) '' 137 - mkdir -p $out/bin 138 - for alias in ${lib.concatStringsSep " " (map lib.escapeShellArg aliases)}; do 139 - ln -sf ${lib.escapeShellArg binName} $out/bin/$alias 140 - done 141 - ''} 142 - 143 - # Handle additional outputs by symlinking from the original package's outputs 144 - ${lib.concatMapStringsSep "\n" ( 145 - output: 146 - if output != "out" && originalOutputs ? ${output} && originalOutputs.${output} != null then 147 - '' 148 - if [[ -n "''${${output}:-}" ]]; then 149 - mkdir -p ${"$" + output} 150 - # Only symlink from the original package's corresponding output 151 - ${pkgs.lndir}/bin/lndir -silent "${originalOutputs.${output}}" ${"$" + output} 152 - fi 153 - '' 154 - else 155 - "" 156 - ) outputs} 157 - ''; 158 - 159 - inherit passthru meta; 160 - } 161 - // (removeAttrs args [ 162 - "name" 163 - "paths" 164 - "outputs" 165 - "originalOutputs" 166 - "passthru" 167 - "meta" 168 - "aliases" 169 - "binName" 170 - ]) 171 - ); 172 - 173 - # Get original package outputs for symlinking 174 - originalOutputs = 175 - if package ? outputs then 176 - lib.listToAttrs ( 177 - map (output: { 178 - name = output; 179 - value = if package ? ${output} then package.${output} else null; 180 - }) package.outputs 181 - ) 182 - else 183 - { }; 184 - 185 - # Create the wrapper derivation using our multi-output aware symlink join 186 - wrappedPackage = multiOutputSymlinkJoin ( 187 - { 188 - name = package.pname or package.name; 189 - paths = [ 190 - (pkgs.writeShellApplication { 191 - name = binName; 192 - runtimeInputs = runtimeInputs; 193 - text = finalWrapper; 194 - }) 195 - package 196 - ]; 197 - outputs = if package ? outputs then package.outputs else [ "out" ]; 198 - inherit originalOutputs aliases binName; 199 - passthru = 200 - (package.passthru or { }) 201 - // passthru 202 - // { 203 - inherit 204 - env 205 - flags 206 - preHook 207 - aliases 208 - ; 209 - }; 210 - # Pass through original attributes 211 - meta = package.meta or { }; 212 - } 213 - // lib.optionalAttrs (package ? version) { 214 - inherit (package) version; 215 - } 216 - // lib.optionalAttrs (package ? pname) { 217 - inherit (package) pname; 218 - } 219 - ); 220 - in 221 - wrappedPackage; 222 - }
-11
lib/pkgs.nix
··· 1 - # Library functions that require pkgs 2 - { lib, pkgs, ... }: 3 - let 4 - superlib = import ./default.nix { inherit lib; }; 5 - in 6 - { 7 - # Import functions that need pkgs 8 - makeWrapper = (import ./make-wrapper.nix { inherit lib superlib pkgs; }).makeWrapper; 9 - makeWrapperModule = 10 - (import ./make-wrapper-module.nix { inherit lib superlib pkgs; }).makeWrapperModule; 11 - }
+227 -1
wrapperModules/flake-module.nix
··· 139 139 options = eval.options; 140 140 config = eval.config; 141 141 in 142 - self.libWithPkgs.${config.pkgs.system}.makeWrapper config.package { 142 + self.wrapLib.makeWrapper { 143 + pkgs = config.pkgs; 144 + package = config.package; 143 145 runtimeInputs = config.extraPackages; 144 146 flagSeparator = "="; 145 147 flags = config.flags; ··· 150 152 // config.passthru; 151 153 }; 152 154 }; 155 + 156 + /** 157 + Create a wrapped application that preserves all original outputs (man pages, completions, etc.) 158 + 159 + # Arguments 160 + 161 + - `pkgs`: The nixpkgs pkgs instance to use 162 + - `package`: The package to wrap 163 + - `runtimeInputs`: List of packages to add to PATH (optional) 164 + - `env`: Attribute set of environment variables to export (optional) 165 + - `flags`: Attribute set of command-line flags to add (optional) 166 + - `flagSeparator`: Separator between flag names and values (optional, defaults to " ") 167 + - `preHook`: Shell script to run before executing the command (optional) 168 + - `passthru`: Attribute set to pass through to the wrapped derivation (optional) 169 + - `aliases`: List of additional names to symlink to the wrapped executable (optional) 170 + - `wrapper`: Custom wrapper function (optional, defaults to exec'ing the original binary with flags) 171 + - Called with { env, flags, envString, flagsString, exePath, preHook } 172 + 173 + # Example 174 + 175 + ```nix 176 + makeWrapper { 177 + pkgs = pkgs; 178 + package = pkgs.curl; 179 + runtimeInputs = [ pkgs.jq ]; 180 + env = { 181 + CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; 182 + }; 183 + flags = { 184 + "--silent" = { }; # becomes --silent 185 + "--connect-timeout" = "30"; # becomes --connect-timeout 30 186 + }; 187 + preHook = '' 188 + echo "Making request..." >&2 189 + ''; 190 + } 191 + 192 + # Or with custom wrapper: 193 + makeWrapper pkgs.someProgram { 194 + wrapper = { exePath, flagsString, envString, preHook, ... }: '' 195 + ${envString} 196 + ${preHook} 197 + echo "Custom logic here" 198 + exec ${exePath} ${flagsString} "$@" 199 + ''; 200 + } 201 + ``` 202 + */ 203 + flake.config.wrapLib.makeWrapper = 204 + { 205 + pkgs, 206 + package, 207 + runtimeInputs ? [ ], 208 + env ? { }, 209 + flags ? { }, 210 + flagSeparator ? " ", # " " for "--flag value" or "=" for "--flag=value" 211 + preHook ? "", 212 + passthru ? { }, 213 + aliases ? [ ], 214 + wrapper ? ( 215 + { 216 + exePath, 217 + flagsString, 218 + envString, 219 + preHook, 220 + ... 221 + }: 222 + '' 223 + ${envString} 224 + ${preHook} 225 + exec ${exePath}${flagsString} "$@" 226 + '' 227 + ), 228 + }: 229 + let 230 + # Extract binary name from the exe path 231 + exePath = lib.getExe package; 232 + binName = baseNameOf exePath; 233 + 234 + # Generate environment variable exports 235 + envString = 236 + if env == { } then 237 + "" 238 + else 239 + lib.concatStringsSep "\n" ( 240 + lib.mapAttrsToList (name: value: ''export ${name}="${toString value}"'') env 241 + ) 242 + + "\n"; 243 + 244 + # Generate flag arguments with proper line breaks and indentation 245 + flagsString = 246 + if flags == { } then 247 + "" 248 + else 249 + " \\\n " 250 + + lib.concatStringsSep " \\\n " ( 251 + lib.mapAttrsToList ( 252 + name: value: 253 + if value == { } then "${name}" else "${name}${flagSeparator}${lib.escapeShellArg (toString value)}" 254 + ) flags 255 + ); 256 + 257 + finalWrapper = wrapper { 258 + inherit 259 + env 260 + flags 261 + envString 262 + flagsString 263 + exePath 264 + preHook 265 + ; 266 + }; 267 + 268 + # Multi-output aware symlink join function 269 + multiOutputSymlinkJoin = 270 + { 271 + name, 272 + paths, 273 + outputs ? [ "out" ], 274 + originalOutputs ? { }, 275 + passthru ? { }, 276 + meta ? { }, 277 + aliases ? [ ], 278 + binName ? null, 279 + ... 280 + }@args: 281 + pkgs.stdenv.mkDerivation ( 282 + { 283 + inherit name outputs; 284 + 285 + buildCommand = '' 286 + # Symlink all paths to the main output 287 + mkdir -p $out 288 + for path in ${lib.concatStringsSep " " (map toString paths)}; do 289 + ${pkgs.lndir}/bin/lndir -silent "$path" $out 290 + done 291 + 292 + # Create symlinks for aliases 293 + ${lib.optionalString (aliases != [ ] && binName != null) '' 294 + mkdir -p $out/bin 295 + for alias in ${lib.concatStringsSep " " (map lib.escapeShellArg aliases)}; do 296 + ln -sf ${lib.escapeShellArg binName} $out/bin/$alias 297 + done 298 + ''} 299 + 300 + # Handle additional outputs by symlinking from the original package's outputs 301 + ${lib.concatMapStringsSep "\n" ( 302 + output: 303 + if output != "out" && originalOutputs ? ${output} && originalOutputs.${output} != null then 304 + '' 305 + if [[ -n "''${${output}:-}" ]]; then 306 + mkdir -p ${"$" + output} 307 + # Only symlink from the original package's corresponding output 308 + ${pkgs.lndir}/bin/lndir -silent "${originalOutputs.${output}}" ${"$" + output} 309 + fi 310 + '' 311 + else 312 + "" 313 + ) outputs} 314 + ''; 315 + 316 + inherit passthru meta; 317 + } 318 + // (removeAttrs args [ 319 + "name" 320 + "paths" 321 + "outputs" 322 + "originalOutputs" 323 + "passthru" 324 + "meta" 325 + "aliases" 326 + "binName" 327 + ]) 328 + ); 329 + 330 + # Get original package outputs for symlinking 331 + originalOutputs = 332 + if package ? outputs then 333 + lib.listToAttrs ( 334 + map (output: { 335 + name = output; 336 + value = if package ? ${output} then package.${output} else null; 337 + }) package.outputs 338 + ) 339 + else 340 + { }; 341 + 342 + # Create the wrapper derivation using our multi-output aware symlink join 343 + wrappedPackage = multiOutputSymlinkJoin ( 344 + { 345 + name = package.pname or package.name; 346 + paths = [ 347 + (pkgs.writeShellApplication { 348 + name = binName; 349 + runtimeInputs = runtimeInputs; 350 + text = finalWrapper; 351 + }) 352 + package 353 + ]; 354 + outputs = if package ? outputs then package.outputs else [ "out" ]; 355 + inherit originalOutputs aliases binName; 356 + passthru = 357 + (package.passthru or { }) 358 + // passthru 359 + // { 360 + inherit 361 + env 362 + flags 363 + preHook 364 + aliases 365 + ; 366 + }; 367 + # Pass through original attributes 368 + meta = package.meta or { }; 369 + } 370 + // lib.optionalAttrs (package ? version) { 371 + inherit (package) version; 372 + } 373 + // lib.optionalAttrs (package ? pname) { 374 + inherit (package) pname; 375 + } 376 + ); 377 + in 378 + wrappedPackage; 153 379 }
+3 -1
tools/claude/flake-module.nix
··· 11 11 claudeMd = ./CLAUDE.md; 12 12 in 13 13 { 14 - packages.claude = self.libWithPkgs.${system}.makeWrapper (self.lib.halalify pkgs.claude-code) { 14 + packages.claude = self.wrapLib.makeWrapper { 15 + pkgs = pkgs; 16 + package = (self.lib.halalify pkgs.claude-code); 15 17 wrapper = 16 18 { exePath, ... }: 17 19 ''
+4 -4
tools/muchsync/flake-module.nix
··· 4 4 { 5 5 pkgs, 6 6 lib, 7 - system, 8 7 ... 9 8 }: 10 9 { 11 - packages.muchsync = self.libWithPkgs.${system}.makeWrapper pkgs.muchsync { 10 + packages.muchsync = self.wrapLib.makeWrapper { 11 + pkgs = pkgs; 12 + package = pkgs.muchsync; 12 13 runtimeInputs = [ pkgs.notmuch ] ++ lib.optionals pkgs.stdenv.isLinux [ pkgs.iputils ]; 13 14 env = { 14 15 NOTMUCH_CONFIG = 15 - pkgs.writeText "notmuch-config" 16 - self.packages.${pkgs.system}.mutt.passthru.notmuchConfig; 16 + self.packages.${pkgs.system}.notmuch.passthru.config.configFile.path; 17 17 }; 18 18 wrapper = 19 19 { exePath, envString, ... }:
+5 -6
tools/mutt/flake-module.nix
··· 12 12 let 13 13 # Mailboxes configuration from mail.nix 14 14 mailboxes = self.packages.${system}.notmuch.mailboxes; 15 - notmuchConfig = self.packages.${system}.notmuch.notmuchConfig; 15 + notmuchConfig = self.packages.${system}.notmuch.passthru.config.configFile.path; 16 16 17 17 mailcap = pkgs.writeText "mailcap" '' 18 18 text/html; ${pkgs.elinks}/bin/elinks -dump ; copiousoutput; ··· 188 188 ''; 189 189 190 190 in 191 - self.libWithPkgs.${pkgs.system}.makeWrapper pkgs.neomutt { 191 + self.wrapLib.makeWrapper { 192 + pkgs = pkgs; 193 + package = pkgs.neomutt; 192 194 aliases = [ "mutt" ]; 193 195 runtimeInputs = [ 194 196 pkgs.elinks ··· 200 202 pkgs.iputils 201 203 ]; 202 204 env = { 203 - NOTMUCH_CONFIG = "${pkgs.writeText "notmuch-config" notmuchConfig}"; 205 + NOTMUCH_CONFIG = notmuchConfig; 204 206 }; 205 207 flags = { 206 208 "-F" = "${muttrc}"; 207 - }; 208 - passthru = { 209 - notmuchConfig = notmuchConfig; 210 209 }; 211 210 }; 212 211 };
+3 -1
tools/pass/flake-module.nix
··· 7 7 ... 8 8 }: 9 9 { 10 - packages.pass = self.libWithPkgs.${system}.makeWrapper pkgs.passage { 10 + packages.pass = self.wrapLib.makeWrapper { 11 + pkgs = pkgs; 12 + package = pkgs.passage; 11 13 runtimeInputs = [ 12 14 pkgs.age-plugin-se 13 15 pkgs.age-plugin-fido2-hmac
+10 -6
tools/ssh-yubikey/flake-module.nix
··· 3 3 perSystem = 4 4 { pkgs, ... }: 5 5 { 6 - packages.ssh-yubikey = self.libWithPkgs.${pkgs.system}.makeWrapper pkgs.openssh { 6 + packages.ssh-yubikey = self.wrapLib.makeWrapper { 7 + pkgs = pkgs; 8 + package = pkgs.openssh; 7 9 env = { 8 10 KEYS_DIR = "${self}/keys"; 9 11 SSH = "${pkgs.openssh}/bin/ssh"; ··· 16 18 libfido2 17 19 self.packages.${pkgs.system}.age-detect 18 20 ]; 19 - wrapper = { exePath, envString, ... }: '' 20 - ${envString} 21 - ${builtins.readFile ./ssh-yubikey} 22 - ''; 21 + wrapper = 22 + { envString, ... }: 23 + '' 24 + ${envString} 25 + ${builtins.readFile ./ssh-yubikey} 26 + ''; 23 27 }; 24 28 }; 25 - } 29 + }
+4 -2
tools/tmux/flake-module.nix
··· 1 1 { self, ... }: 2 2 { 3 3 perSystem = 4 - { pkgs, system, ... }: 4 + { pkgs, ... }: 5 5 let 6 6 tmuxConfigText = '' 7 7 set-option -g default-terminal screen-256color ··· 13 13 in 14 14 { 15 15 packages.tmux = 16 - (self.libWithPkgs.${system}.makeWrapper pkgs.tmux { 16 + (self.wrapLib.makeWrapper { 17 + pkgs = pkgs; 18 + package = pkgs.tmux; 17 19 flags = { 18 20 "-f" = tmuxConfigFile; 19 21 };
+3 -1
tools/zsh/flake-module.nix
··· 306 306 in 307 307 { 308 308 packages.zsh = 309 - (self.libWithPkgs.${pkgs.system}.makeWrapper pkgs.zsh { 309 + (self.wrapLib.makeWrapper { 310 + pkgs = pkgs; 311 + package = pkgs.zsh; 310 312 runtimeInputs = with pkgs; [ 311 313 gnugrep 312 314 tmux