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.3 kB 161 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 setup_identities() { 55 # Check if bulk key file should be used for decryption 56 if [[ -n "''${PASS_BULK_KEY_FILE:-}" ]]; then 57 if [[ ! -f "$PASS_BULK_KEY_FILE" ]] || [[ ! -s "$PASS_BULK_KEY_FILE" ]]; then 58 mkdir -p "$(dirname "$PASS_BULK_KEY_FILE")" 59 ${exePath} show bulk-operations/age-key > "$PASS_BULK_KEY_FILE" 2>/dev/null || true 60 fi 61 fi 62 63 # Set up identities for age decryption 64 if [[ -n "''${PASS_BULK_KEY_FILE:-}" ]] && [[ -f "$PASS_BULK_KEY_FILE" ]] && [[ -s "$PASS_BULK_KEY_FILE" ]]; then 65 # Use bulk key if available 66 export PASSAGE_IDENTITIES_FILE="$PASS_BULK_KEY_FILE" 67 else 68 # Detect available age keys 69 export AGE_DETECT_KEYS_DIR="${self}/keys" 70 eval "$(age-detect)" 71 72 # Set up identity file if detected 73 if [[ -n "''${IDENTITY_FILE:-}" ]]; then 74 export PASSAGE_IDENTITIES_FILE="$IDENTITY_FILE" 75 trap 'rm -f "$IDENTITY_FILE"' EXIT 76 fi 77 fi 78 } 79 80 if [[ "$needs_decrypt" == true ]]; then 81 setup_identities 82 fi 83 84 ${ 85 if pkgs.stdenv.isLinux then 86 '' 87 maybe_set_tpm_pin() { 88 local target="''${1:-<stdin>}" 89 if [[ "''${KEY_TYPE:-}" != "tpm" ]]; then 90 return 0 91 fi 92 if [[ -n "''${AGE_TPM_PIN:-}" ]]; then 93 return 0 94 fi 95 AGE_TPM_PIN="$(${self.packages.${system}.pinentry-rofi-age}/bin/pinentry-rofi-age "$target")" 96 export AGE_TPM_PIN 97 } 98 99 decrypt_target="" 100 if [[ "''${1:-}" == "show" ]]; then 101 decrypt_target="''${2:-}" 102 elif [[ -n "''${1:-}" ]] && [[ "''${1:-}" != -* ]] && [[ "''${1:-}" != "otp" ]]; then 103 # Skip passage subcommands that don't need decryption 104 case "''${1:-}" in 105 ls|find|git|insert|generate|rm|mv|cp|help|version|init) 106 ;; 107 edit|grep|reencrypt) 108 # These commands do decrypt, prompt with command as target 109 decrypt_target="''${2:-''${1:-}}" 110 ;; 111 *) 112 # Bare pass-name (implicit show) 113 decrypt_target="''${1:-}" 114 ;; 115 esac 116 fi 117 118 if [[ -n "$decrypt_target" ]]; then 119 maybe_set_tpm_pin "$decrypt_target" 120 fi 121 '' 122 else 123 '' 124 # No TPM on Darwin, define no-op 125 maybe_set_tpm_pin() { :; } 126 '' 127 } 128 129 # Handle OTP commands by delegating to pass-otp 130 if [[ "''${1:-}" == "otp" ]]; then 131 shift 132 # Extract pass name and options 133 clip_arg="" 134 pass_name="" 135 for arg in "$@"; do 136 case "$arg" in 137 "--clip"|"-c") 138 clip_arg="--clip" 139 ;; 140 *) 141 pass_name="$arg" 142 ;; 143 esac 144 done 145 146 if [[ -z "$pass_name" ]]; then 147 echo "Usage: pass otp [--clip,-c] pass-name" 148 exit 1 149 fi 150 151 # Show pass and pipe to OTP (identities already set up by age-detect) 152 maybe_set_tpm_pin "$pass_name" 153 ${exePath} show "$pass_name" | pass-otp $clip_arg 154 else 155 # Pass all other commands directly to passage (identities already set up) 156 ${exePath} "$@" 157 fi 158 ''; 159 }; 160 }; 161}