1
0

pkgs/clerie-sops: Add clerie-sops-edit for working with multiline string attributes in json

This commit is contained in:
clerie 2024-05-01 17:11:36 +02:00
parent 3371f47f68
commit 2970a7d892
5 changed files with 38 additions and 0 deletions

View File

@ -16,6 +16,7 @@
colmena colmena
agenix agenix
clerie-sops clerie-sops
clerie-sops-edit
sops sops
# Debugging # Debugging

View File

@ -132,6 +132,7 @@
clerie-update-nixfiles clerie-update-nixfiles
clerie-sops clerie-sops
clerie-sops-config clerie-sops-config
clerie-sops-edit
chromium-incognito chromium-incognito
iot-data iot-data
nix-remove-result-links nix-remove-result-links

View File

@ -0,0 +1,10 @@
{ pkgs, ... }:
pkgs.writeShellApplication {
name = "clerie-sops-edit";
text = builtins.readFile ./clerie-sops-edit.sh;
runtimeInputs = with pkgs; [
clerie-sops
jq
];
}

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Edit a single attribute of a sops json file
# Helps working with multiline strings in json
set -euo pipefail
SECRETS_FILE="$1"
KEY="$2"
if [[ -n $EDITOR ]]; then
EDITOR=vim
fi
TMP_FILE="$(mktemp)"
clerie-sops --decrypt --extract "[\"${KEY}\"]" "${SECRETS_FILE}" > "${TMP_FILE}"
vim "${TMP_FILE}"
JSON_QUOTED_SECRET="$(jq -Rs '.' "${TMP_FILE}")"
rm "${TMP_FILE}"
clerie-sops --set "[\"${KEY}\"] ${JSON_QUOTED_SECRET}" "${SECRETS_FILE}"

View File

@ -4,6 +4,7 @@ final: prev: {
clerie-merge-nixfiles-update = final.callPackage ./clerie-update-nixfiles/clerie-merge-nixfiles-update.nix {}; clerie-merge-nixfiles-update = final.callPackage ./clerie-update-nixfiles/clerie-merge-nixfiles-update.nix {};
clerie-sops = final.callPackage ./clerie-sops/clerie-sops.nix {}; clerie-sops = final.callPackage ./clerie-sops/clerie-sops.nix {};
clerie-sops-config = final.callPackage ./clerie-sops/clerie-sops-config.nix {}; clerie-sops-config = final.callPackage ./clerie-sops/clerie-sops-config.nix {};
clerie-sops-edit = final.callPackage ./clerie-sops/clerie-sops-edit.nix {};
clerie-update-nixfiles = final.callPackage ./clerie-update-nixfiles/clerie-update-nixfiles.nix {}; clerie-update-nixfiles = final.callPackage ./clerie-update-nixfiles/clerie-update-nixfiles.nix {};
chromium-incognito = final.callPackage ./chromium-incognito {}; chromium-incognito = final.callPackage ./chromium-incognito {};
iot-data = final.python3.pkgs.callPackage ./iot-data {}; iot-data = final.python3.pkgs.callPackage ./iot-data {};