guix.scm (3528B)
1 (use-modules (guix packages) 2 (guix licenses) 3 (guix git) 4 (guix build-system trivial) 5 (guix gexp) 6 (gnu packages) 7 (gnu packages authentication) 8 (gnu packages base) 9 (gnu packages bash) 10 (gnu packages golang-crypto) 11 (gnu packages shells) 12 (gnu packages version-control) 13 (gnu packages xdisorg)) 14 15 ;; dash is a good POSIX shell for scripts in my experience 16 (define dash-w-sh-symlink 17 (package 18 (inherit dash) 19 (arguments 20 `(#:phases 21 (modify-phases %standard-phases 22 (add-after 'install 'install-sh-symlink 23 (lambda* (#:key outputs #:allow-other-keys) 24 ;; Add a `sh' -> `dash' link. 25 (let ((out (assoc-ref outputs "out"))) 26 (with-directory-excursion (string-append out "/bin") 27 (symlink "dash" "sh") 28 #t))))))))) 29 30 ;; TODO: Rewrite sta.sh with libage somehow? This is slightly jank. 31 ;; I will probably do a C or Rust rewrite in the future. 32 (define-public age-with-stdin-passphrase 33 (package 34 (inherit age) 35 (source (origin 36 (inherit (package-source age)) 37 (patches (list 38 (local-file "passphrase-from-stdin.patch"))))))) 39 40 ;; Package 41 (define stash 42 (package 43 (name "stash") 44 (version "0.1.0-1") 45 ;; Use local directory as source 46 (source (local-file (dirname (current-filename)) #:recursive? #t)) 47 (build-system trivial-build-system) 48 (arguments 49 `(#:modules ((guix build utils)) 50 #:builder 51 (begin 52 (use-modules (guix build utils)) 53 (let* ((bin-dir (string-append %output "/bin")) 54 (bin (string-append bin-dir "/sta.sh")) 55 (get-input-bin (lambda (input-name bin-name) 56 (string-append 57 (assoc-ref %build-inputs input-name) 58 (string-append "/bin/" bin-name)))) 59 (wrapper-helper (lambda (var value) 60 `(,var ":" = (,(string-append 61 "${" var ":=" value "}"))))) 62 (copy-script (lambda (file dest) 63 (copy-file file dest) 64 (patch-shebang dest 65 (list (string-append 66 (assoc-ref %build-inputs "dash") 67 "/bin"))) 68 (chmod dest #o555)))) 69 (mkdir-p bin-dir) 70 (copy-script (string-append (assoc-ref %build-inputs "source") "/sta.sh") 71 bin) 72 (wrap-program bin #:sh (get-input-bin "bash-minimal" "bash") 73 (wrapper-helper "TOFI" (get-input-bin "tofi" "tofi")) 74 (wrapper-helper "AGE" (get-input-bin "age" "age")) 75 (wrapper-helper "AGEKEYGEN" (get-input-bin "age" "age-keygen")) 76 (wrapper-helper "OATHTOOL" (get-input-bin "oath-toolkit" "oathtool"))))))) 77 (inputs (list bash-minimal ;; Needed for wrap-program 78 dash-w-sh-symlink 79 tofi 80 age-with-stdin-passphrase 81 oath-toolkit)) 82 (home-page "https://git.loquat.dev/stash") 83 (synopsis "Simple password manager shell script") 84 (description #f) 85 (license gpl3+))) 86 87 stash