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