Skip to content

Commit 87d0c77

Browse files
committed
feat(sops): add generic sopsAndroidSecrets activation hook for non-systemd environments
1 parent 5695116 commit 87d0c77

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

programs/sops.nix

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{ config, pkgs, lib, ... }:
22

3+
let
4+
cfg = config.sops;
5+
in
36
{
47
home.packages = [ pkgs.sops ];
58

@@ -13,18 +16,28 @@
1316

1417
defaultSopsFile = ../secrets/secrets.yaml;
1518

16-
# Every input is avaiable in 'config.sops.secrets.<nome>'.
1719
secrets = {
1820
"gemini_api_key" = {
1921
sopsFile = ../secrets/api_keys.yaml;
20-
key = "";
22+
key = "";
2123
};
22-
23-
# Add new secret on the future
24-
# "my_api_token" = {
25-
# sopsFile = ../secrets/secrets.yaml;
26-
# key = "apis_tokens.my_service2";
27-
# };
2824
};
2925
};
26+
27+
home.activation.sopsAndroidSecrets = lib.mkIf pkgs.stdenv.hostPlatform.isAndroid (
28+
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
29+
if [ -f "${cfg.age.keyFile}" ]; then
30+
${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: secret: ''
31+
if [ -n "${secret.path or ""}" ]; then
32+
mkdir -p "$(dirname "${secret.path}")"
33+
$DRY_RUN_CMD ${pkgs.sops}/bin/sops --decrypt \
34+
--age-key-file "${cfg.age.keyFile}" \
35+
--extract '["${lib.replaceStrings ["/"] ["\"][\""] name}"]' \
36+
${secret.sopsFile} > "${secret.path}" 2>/dev/null || true
37+
chmod ${secret.mode or "0600"} "${secret.path}"
38+
fi
39+
'') (lib.filterAttrs (_: s: s.path != null && s.path != "") cfg.secrets))}
40+
fi
41+
''
42+
);
3043
}

0 commit comments

Comments
 (0)