This repository has no description
0

Configure Feed

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

lib.makeWrapper: add flags support and function-based wrappers

- Add flags parameter to makeWrapper for command-line arguments
- Change wrapper parameter to always be a function receiving { exePath, flagsString, envString, env, flags }
- Remove automatic "--" prefix handling for flags (users specify full flag names)
- Improve formatting with proper line breaks and indentation for multi-line commands
- Add passthru for env and flags to make them accessible
- Update tools to use new function-based wrapper syntax:
- tmux: uses flags directly with -f for config file
- pass: uses custom wrapper function for GPG key import
- muchsync: uses custom wrapper function with host detection logic

+124 -70
+59 -10
lib/make-wrapper.nix
··· 8 8 - `package`: The package to wrap 9 9 - `runtimeInputs`: List of packages to add to PATH (optional) 10 10 - `env`: Attribute set of environment variables to export (optional) 11 - - `wrapper`: Custom wrapper script (optional, defaults to exec'ing the original binary) 11 + - `flags`: Attribute set of command-line flags to add (optional) 12 + - `wrapper`: Custom wrapper function (optional, defaults to exec'ing the original binary with flags) 13 + - Called with { env, flags, envString, flagsString, exePath } 12 14 13 15 # Example 14 16 ··· 18 20 env = { 19 21 CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; 20 22 }; 21 - wrapper = '' 23 + flags = { 24 + "--silent" = { }; # becomes --silent 25 + "--connect-timeout" = "30"; # becomes --connect-timeout 30 26 + }; 27 + wrapper = { exePath, flagsString, envString, ... }: '' 28 + ${envString} 22 29 echo "Making request..." >&2 23 - exec ${lib.getExe pkgs.curl} "$@" 30 + exec ${exePath} ${flagsString} "$@" 24 31 ''; 25 32 } 26 33 ``` ··· 30 37 { 31 38 runtimeInputs ? [ ], 32 39 env ? { }, 33 - wrapper ? ''exec ${lib.getExe package} "$@"'', 40 + flags ? { }, 41 + wrapper ? ( 42 + { 43 + exePath, 44 + flagsString, 45 + envString, 46 + ... 47 + }: 48 + '' 49 + ${envString} 50 + exec ${exePath}${flagsString} "$@" 51 + '' 52 + ), 34 53 }: 35 54 let 36 55 # Extract binary name from the exe path 37 56 exePath = lib.getExe package; 38 57 binName = baseNameOf exePath; 58 + 59 + # Generate environment variable exports 60 + envString = 61 + if env == { } then 62 + "" 63 + else 64 + lib.concatStringsSep "\n" ( 65 + lib.mapAttrsToList (name: value: ''export ${name}="${toString value}"'') env 66 + ) 67 + + "\n"; 68 + 69 + # Generate flag arguments with proper line breaks and indentation 70 + flagsString = 71 + if flags == { } then 72 + "" 73 + else 74 + " \\\n " 75 + + lib.concatStringsSep " \\\n " ( 76 + lib.mapAttrsToList ( 77 + name: value: if value == { } then "${name}" else "${name} ${lib.escapeShellArg (toString value)}" 78 + ) flags 79 + ); 80 + 81 + finalWrapper = wrapper { 82 + inherit 83 + env 84 + flags 85 + envString 86 + flagsString 87 + exePath 88 + ; 89 + }; 39 90 in 40 91 pkgs.symlinkJoin { 41 92 name = package.pname or package.name; ··· 43 94 (pkgs.writeShellApplication { 44 95 name = binName; 45 96 runtimeInputs = runtimeInputs; 46 - text = '' 47 - ${lib.concatStringsSep "\n" ( 48 - lib.mapAttrsToList (name: value: ''export ${name}="${toString value}"'') env 49 - )} 50 - ${wrapper} 51 - ''; 97 + text = finalWrapper; 52 98 }) 53 99 package 54 100 ]; 101 + passthru = (package.passthru or { }) // { 102 + inherit env flags; 103 + }; 55 104 }; 56 105 }
+54 -52
tools/muchsync/flake-module.nix
··· 15 15 pkgs.writeText "notmuch-config" 16 16 self.packages.${pkgs.system}.mutt.passthru.notmuchConfig; 17 17 }; 18 - wrapper = '' 18 + wrapper = 19 + { exePath, envString, ... }: 20 + '' 21 + ${envString} 22 + # Create Maildir structure if it doesn't exist 23 + mkdir -p "$HOME/Maildir"/{cur,new,tmp} 19 24 20 - # Create Maildir structure if it doesn't exist 21 - mkdir -p "$HOME/Maildir"/{cur,new,tmp} 25 + # Check if a host is reachable 26 + check_host() { 27 + local host=$1 28 + ping -W2 -c1 "$host" >/dev/null 2>&1 29 + } 22 30 23 - # Check if a host is reachable 24 - check_host() { 25 - local host=$1 26 - ping -W2 -c1 "$host" >/dev/null 2>&1 27 - } 31 + # Smart host selection - try spora, nether, retiolum, then tor 32 + find_green_host() { 33 + if check_host green.s; then 34 + echo "green.s" 35 + elif check_host green.n; then 36 + echo "green.n" 37 + elif check_host green.r; then 38 + echo "green.r" 39 + else 40 + echo "tor" 41 + fi 42 + } 28 43 29 - # Smart host selection - try spora, nether, retiolum, then tor 30 - find_green_host() { 31 - if check_host green.s; then 32 - echo "green.s" 33 - elif check_host green.n; then 34 - echo "green.n" 35 - elif check_host green.r; then 36 - echo "green.r" 44 + # Check if arguments look like flags or a hostname 45 + has_hostname=false 46 + for arg in "$@"; do 47 + case "$arg" in 48 + -*) ;; # This is a flag 49 + *) has_hostname=true; break ;; # Found a non-flag argument 50 + esac 51 + done 52 + 53 + # If only flags provided (or no args), do a sync with green host 54 + if [ "$has_hostname" = "false" ]; then 55 + host=$(find_green_host) 56 + echo "Syncing with $host..." >&2 57 + 58 + if [ "$host" = "tor" ]; then 59 + # Build dependencies lazily 60 + echo "Building tornade..." >&2 61 + tornade_path=$(nix build --no-link --print-out-paths "${self}#tornade") 62 + clan_path=$(nix build --no-link --print-out-paths "${self}#clan-cli") 63 + 64 + # Get tor hostname using clan CLI 65 + tor_hostname=$(CLAN_DIR="${self}" "$clan_path/bin/clan" vars get green tor-ssh/tor-hostname) 66 + 67 + # Use muchsync with custom ssh command via tornade 68 + exec ${exePath} "$@" -s "$tornade_path/bin/tornade ssh" lass@"$tor_hostname" 69 + else 70 + exec ${exePath} "$@" lass@"$host" 71 + fi 37 72 else 38 - echo "tor" 73 + # Pass through arguments to muchsync 74 + exec ${exePath} "$@" 39 75 fi 40 - } 41 - 42 - # Check if arguments look like flags or a hostname 43 - has_hostname=false 44 - for arg in "$@"; do 45 - case "$arg" in 46 - -*) ;; # This is a flag 47 - *) has_hostname=true; break ;; # Found a non-flag argument 48 - esac 49 - done 50 - 51 - # If only flags provided (or no args), do a sync with green host 52 - if [ "$has_hostname" = "false" ]; then 53 - host=$(find_green_host) 54 - echo "Syncing with $host..." >&2 55 - 56 - if [ "$host" = "tor" ]; then 57 - # Build dependencies lazily 58 - echo "Building tornade..." >&2 59 - tornade_path=$(nix build --no-link --print-out-paths "${self}#tornade") 60 - clan_path=$(nix build --no-link --print-out-paths "${self}#clan-cli") 61 - 62 - # Get tor hostname using clan CLI 63 - tor_hostname=$(CLAN_DIR="${self}" "$clan_path/bin/clan" vars get green tor-ssh/tor-hostname) 64 - 65 - # Use muchsync with custom ssh command via tornade 66 - exec muchsync "$@" -s "$tornade_path/bin/tornade ssh" lass@"$tor_hostname" 67 - else 68 - exec muchsync "$@" lass@"$host" 69 - fi 70 - else 71 - # Pass through arguments to muchsync 72 - exec muchsync "$@" 73 - fi 74 - ''; 76 + ''; 75 77 }; 76 78 }; 77 79 }
+8 -5
tools/pass/flake-module.nix
··· 8 8 { 9 9 packages.pass = self.libWithPkgs.${system}.makeWrapper passWithOtp { 10 10 runtimeInputs = [ pkgs.gnupg ]; 11 - wrapper = '' 12 - gpg --import ${self.keys.pgp.yubi.key} &>/dev/null 13 - echo '${self.keys.pgp.yubi.id}:6:' | gpg --import-ownertrust &>/dev/null 14 - exec ${pkgs.lib.getExe passWithOtp} "$@" 15 - ''; 11 + wrapper = 12 + { exePath, envString, ... }: 13 + '' 14 + ${envString} 15 + gpg --import ${self.keys.pgp.yubi.key} &>/dev/null 16 + echo '${self.keys.pgp.yubi.id}:6:' | gpg --import-ownertrust &>/dev/null 17 + exec ${exePath} "$@" 18 + ''; 16 19 }; 17 20 }; 18 21 }
+3 -3
tools/tmux/flake-module.nix
··· 14 14 { 15 15 packages.tmux = 16 16 (self.libWithPkgs.${system}.makeWrapper pkgs.tmux { 17 - wrapper = '' 18 - exec ${pkgs.lib.getExe pkgs.tmux} -f ${tmuxConfigFile} "$@" 19 - ''; 17 + flags = { 18 + "-f" = tmuxConfigFile; 19 + }; 20 20 }).overrideAttrs 21 21 (old: { 22 22 passthru = (old.passthru or { }) // {