This repository has no description
2.7 kB
89 lines
1{ self, ... }:
2{
3 perSystem =
4 {
5 pkgs,
6 system,
7 ...
8 }:
9 {
10 packages.pass = self.wrapLib.makeWrapper {
11 pkgs = pkgs;
12 package = pkgs.passage;
13 runtimeInputs = [
14 pkgs.age-plugin-fido2-hmac
15 pkgs.age-plugin-yubikey
16 self.packages.${system}.pass-otp
17 self.packages.${system}.age-detect
18 ]
19 ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin [
20 pkgs.age-plugin-se
21 ]);
22 aliases = [ "pass" ];
23 wrapper =
24 {
25 exePath,
26 envString,
27 preHook,
28 ...
29 }:
30 ''
31 set -x
32 ${envString}
33 ${preHook}
34
35 # Check if bulk key file should be used for decryption
36 if [[ -n "''${PASS_BULK_KEY_FILE:-}" ]]; then
37 if [[ ! -f "$PASS_BULK_KEY_FILE" ]] || [[ ! -s "$PASS_BULK_KEY_FILE" ]]; then
38 mkdir -p "$(dirname "$PASS_BULK_KEY_FILE")"
39 ${exePath} show bulk-operations/age-key > "$PASS_BULK_KEY_FILE" 2>/dev/null || true
40 fi
41 fi
42
43 # Set up identities for age decryption
44 if [[ -n "''${PASS_BULK_KEY_FILE:-}" ]] && [[ -f "$PASS_BULK_KEY_FILE" ]] && [[ -s "$PASS_BULK_KEY_FILE" ]]; then
45 # Use bulk key if available
46 export PASSAGE_IDENTITIES_FILE="$PASS_BULK_KEY_FILE"
47 else
48 # Detect available age keys
49 eval "$(age-detect)"
50
51 # Set up identity file if detected
52 if [[ -n "''${IDENTITY_FILE:-}" ]]; then
53 export PASSAGE_IDENTITIES_FILE="$IDENTITY_FILE"
54 trap 'rm -f "$IDENTITY_FILE"' EXIT
55 fi
56 fi
57
58 # Handle OTP commands by delegating to pass-otp
59 if [[ "''${1:-}" == "otp" ]]; then
60 shift
61 # Extract pass name and options
62 clip_arg=""
63 pass_name=""
64 for arg in "$@"; do
65 case "$arg" in
66 "--clip"|"-c")
67 clip_arg="--clip"
68 ;;
69 *)
70 pass_name="$arg"
71 ;;
72 esac
73 done
74
75 if [[ -z "$pass_name" ]]; then
76 echo "Usage: pass otp [--clip,-c] pass-name"
77 exit 1
78 fi
79
80 # Show pass and pipe to OTP (identities already set up by age-detect)
81 ${exePath} show "$pass_name" | pass-otp $clip_arg
82 else
83 # Pass all other commands directly to passage (identities already set up)
84 ${exePath} "$@"
85 fi
86 '';
87 };
88 };
89}