Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get SOPS secrets as strings for build time use. #2

Open
rakino opened this issue Oct 4, 2024 · 0 comments
Open

Get SOPS secrets as strings for build time use. #2

rakino opened this issue Oct 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@rakino
Copy link

rakino commented Oct 4, 2024

Here's a procedure to get SOPS secrets as strings (usable at build time, NOTE THAT these secrets will be made available in /gnu/store), in case it's useful:

(use-modules ((ice-9 popen) #:select (open-input-pipe close-pipe))
             ((rnrs io ports) #:select (get-string-all))
             ((sops secrets) #:select (sanitize-sops-key))

(define* (get-sops-secret key #:key file (number? #f))
  (let* ((cmd (format #f "sops --decrypt --extract '~a' '~a'"
                      (sanitize-sops-key key)
                      file))
         (port (open-input-pipe cmd))
         (secret (get-string-all port)))
    (close-pipe port)
    (if number?
        (string->number secret)
        secret)))

Usage:

(get-sops-secret '("some_key")
                 #:file "/path/to/some_file.yaml")

(get-sops-secret '("some_key")
                 #:file "/path/to/some_file.yaml"
                 #:number? #t)
@rakino rakino changed the title Get SOPS secrets as strings at build time. Get SOPS secrets as strings for build time use. Oct 4, 2024
@fishinthecalculator fishinthecalculator added the enhancement New feature or request label Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants