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