This repository has no description
0

Configure Feed

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

superconfig / tools / pass / flake-module.nix
6.5 kB 167 lines
1{ self, inputs, ... }: 2{ 3 perSystem = 4 { 5 pkgs, 6 system, 7 ... 8 }: 9 { 10 packages.pass = inputs.wrappers.lib.wrapPackage { 11 pkgs = pkgs; 12 package = pkgs.passage; 13 runtimeInputs = [ 14 pkgs.age-plugin-fido2-hmac 15 pkgs.age-plugin-yubikey 16 pkgs.age-plugin-tpm 17 self.packages.${system}.pass-otp 18 self.packages.${system}.age-detect 19 ] 20 ++ (pkgs.lib.optionals pkgs.stdenv.isLinux [ 21 self.packages.${system}.pinentry-rofi-age 22 ]) 23 ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin [ 24 pkgs.age-plugin-se 25 ]) 26 ++ (pkgs.lib.optionals (!pkgs.stdenv.isDarwin) [ 27 # Dummy age-plugin-se for Linux (encryption only, no Secure Enclave hardware) 28 (pkgs.writeShellScriptBin "age-plugin-se" '' 29 exec env PYTHONUNBUFFERED=1 ${ 30 pkgs.python3.withPackages (ps: [ ps.cryptography ]) 31 }/bin/python3 ${./age-plugin-se-dummy.py} "$@" 32 '') 33 ]); 34 aliases = [ "pass" ]; 35 wrapper = 36 { 37 exePath, 38 envString, 39 preHook, 40 ... 41 }: 42 '' 43 ${envString} 44 ${preHook} 45 46 # Determine if the command needs decryption 47 needs_decrypt=true 48 case "''${1:-}" in 49 ls|find|git|insert|generate|rm|mv|cp|help|version|init) 50 needs_decrypt=false 51 ;; 52 esac 53 54 ${ 55 if pkgs.stdenv.isLinux then 56 '' 57 maybe_set_tpm_pin() { 58 local target="''${1:-<stdin>}" 59 if [[ "''${KEY_TYPE:-}" != "tpm" ]]; then 60 return 0 61 fi 62 if [[ -n "''${AGE_TPM_PIN:-}" ]]; then 63 return 0 64 fi 65 AGE_TPM_PIN="$(${self.packages.${system}.pinentry-rofi-age}/bin/pinentry-rofi-age "$target")" 66 export AGE_TPM_PIN 67 } 68 '' 69 else 70 '' 71 # No TPM on Darwin, define no-op 72 maybe_set_tpm_pin() { :; } 73 '' 74 } 75 76 setup_identities() { 77 # Always detect available age keys first 78 export AGE_DETECT_KEYS_DIR="${self}/keys" 79 eval "$(age-detect)" 80 81 # Set up identity file if detected 82 if [[ -n "''${IDENTITY_FILE:-}" ]]; then 83 export PASSAGE_IDENTITIES_FILE="$IDENTITY_FILE" 84 trap 'rm -f "$IDENTITY_FILE"' EXIT 85 fi 86 87 # Try to decrypt and cache the bulk key using the detected identity 88 if [[ -n "''${PASS_BULK_KEY_FILE:-}" ]]; then 89 if [[ ! -f "$PASS_BULK_KEY_FILE" ]] || [[ ! -s "$PASS_BULK_KEY_FILE" ]]; then 90 mkdir -p "$(dirname "$PASS_BULK_KEY_FILE")" 91 maybe_set_tpm_pin "bulk-operations/age-key" 92 ${exePath} show bulk-operations/age-key > "$PASS_BULK_KEY_FILE" 2>/dev/null || true 93 fi 94 # Switch to bulk key for subsequent operations if available 95 if [[ -f "$PASS_BULK_KEY_FILE" ]] && [[ -s "$PASS_BULK_KEY_FILE" ]]; then 96 export PASSAGE_IDENTITIES_FILE="$PASS_BULK_KEY_FILE" 97 fi 98 fi 99 } 100 101 if [[ "$needs_decrypt" == true ]]; then 102 setup_identities 103 fi 104 105 ${ 106 if pkgs.stdenv.isLinux then 107 '' 108 decrypt_target="" 109 if [[ "''${1:-}" == "show" ]]; then 110 decrypt_target="''${2:-}" 111 elif [[ -n "''${1:-}" ]] && [[ "''${1:-}" != -* ]] && [[ "''${1:-}" != "otp" ]]; then 112 # Skip passage subcommands that don't need decryption 113 case "''${1:-}" in 114 ls|find|git|insert|generate|rm|mv|cp|help|version|init) 115 ;; 116 edit|grep|reencrypt) 117 # These commands do decrypt, prompt with command as target 118 decrypt_target="''${2:-''${1:-}}" 119 ;; 120 *) 121 # Bare pass-name (implicit show) 122 decrypt_target="''${1:-}" 123 ;; 124 esac 125 fi 126 127 if [[ -n "$decrypt_target" ]]; then 128 maybe_set_tpm_pin "$decrypt_target" 129 fi 130 '' 131 else 132 "" 133 } 134 135 # Handle OTP commands by delegating to pass-otp 136 if [[ "''${1:-}" == "otp" ]]; then 137 shift 138 # Extract pass name and options 139 clip_arg="" 140 pass_name="" 141 for arg in "$@"; do 142 case "$arg" in 143 "--clip"|"-c") 144 clip_arg="--clip" 145 ;; 146 *) 147 pass_name="$arg" 148 ;; 149 esac 150 done 151 152 if [[ -z "$pass_name" ]]; then 153 echo "Usage: pass otp [--clip,-c] pass-name" 154 exit 1 155 fi 156 157 # Show pass and pipe to OTP (identities already set up by age-detect) 158 maybe_set_tpm_pin "$pass_name" 159 ${exePath} show "$pass_name" | pass-otp $clip_arg 160 else 161 # Pass all other commands directly to passage (identities already set up) 162 ${exePath} "$@" 163 fi 164 ''; 165 }; 166 }; 167}