This repository has no description
0

Configure Feed

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

lib: add library structure with makeWrapper helper

+78
+7
flake.nix
··· 177 177 ]; 178 178 }; 179 179 }; 180 + flake.lib = import ./lib { inherit (nixpkgs) lib; }; 181 + flake.libWithPkgs = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: 182 + import ./lib/pkgs.nix { 183 + inherit (nixpkgs) lib; 184 + pkgs = nixpkgs.legacyPackages.${system}; 185 + } 186 + ); 180 187 flake.keys = { 181 188 pgp.yubi = { 182 189 key = ./keys/yubi.pgp;
+8
lib/default.nix
··· 1 + { lib, ... }: 2 + let 3 + # Pure library functions that don't need pkgs 4 + superlib = { 5 + # Add pure functions here 6 + }; 7 + in 8 + superlib
+54
lib/make-wrapper.nix
··· 1 + { lib, superlib, 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 + - `wrapper`: Custom wrapper script (optional, defaults to exec'ing the original binary) 12 + 13 + # Example 14 + 15 + ```nix 16 + makeWrapper pkgs.curl { 17 + runtimeInputs = [ pkgs.jq ]; 18 + env = { 19 + CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; 20 + }; 21 + wrapper = '' 22 + echo "Making request..." >&2 23 + exec ${lib.getExe pkgs.curl} "$@" 24 + ''; 25 + } 26 + ``` 27 + */ 28 + makeWrapper = package: args@{ 29 + runtimeInputs ? [], 30 + env ? {}, 31 + wrapper ? ''exec ${lib.getExe package} "$@"'' 32 + }: 33 + let 34 + # Extract binary name from the exe path 35 + exePath = lib.getExe package; 36 + binName = baseNameOf exePath; 37 + in 38 + pkgs.symlinkJoin { 39 + name = package.pname or package.name; 40 + paths = [ 41 + (pkgs.writeShellApplication { 42 + name = binName; 43 + runtimeInputs = runtimeInputs; 44 + text = '' 45 + ${lib.concatStringsSep "\n" ( 46 + lib.mapAttrsToList (name: value: ''export ${name}="${toString value}"'') env 47 + )} 48 + ${wrapper} 49 + ''; 50 + }) 51 + package 52 + ]; 53 + }; 54 + }
+9
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 + }