aboutsummaryrefslogtreecommitdiff
path: root/flakes
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2021-10-16 17:40:07 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2021-10-16 20:20:45 +0200
commit4c4652aabf2cb3ac8b40f2856eca07a1df9c27e0 (patch)
tree9a7ede9ac3f1899074e9ef568a447f883191d3b5 /flakes
parentda30ae4ffdd153a1eb32fb86f9ca9a65aa19e4e2 (diff)
downloadNix-4c4652aabf2cb3ac8b40f2856eca07a1df9c27e0.tar.gz
Nix-4c4652aabf2cb3ac8b40f2856eca07a1df9c27e0.tar.zst
Nix-4c4652aabf2cb3ac8b40f2856eca07a1df9c27e0.zip
Use attrs for secrets instead of lists
Diffstat (limited to 'flakes')
-rw-r--r--flakes/private/openarc/flake.lock2
-rw-r--r--flakes/private/opendmarc/flake.lock2
-rw-r--r--flakes/private/opendmarc/flake.nix9
-rw-r--r--flakes/secrets/flake.nix49
4 files changed, 47 insertions, 15 deletions
diff --git a/flakes/private/openarc/flake.lock b/flakes/private/openarc/flake.lock
index 744d002..be75993 100644
--- a/flakes/private/openarc/flake.lock
+++ b/flakes/private/openarc/flake.lock
@@ -146,7 +146,7 @@
146 }, 146 },
147 "secrets": { 147 "secrets": {
148 "locked": { 148 "locked": {
149 "narHash": "sha256-aRHKDVHDpnqpmgGhLGQxXwyTwmPuhUJTVcOLBYtY2ks=", 149 "narHash": "sha256-w3u1bMEJHCg9SqErJ5Qi0sTX2xx7mk+HrHZXzpjQd1w=",
150 "path": "../../secrets", 150 "path": "../../secrets",
151 "type": "path" 151 "type": "path"
152 }, 152 },
diff --git a/flakes/private/opendmarc/flake.lock b/flakes/private/opendmarc/flake.lock
index bd5019c..f40e1a9 100644
--- a/flakes/private/opendmarc/flake.lock
+++ b/flakes/private/opendmarc/flake.lock
@@ -129,7 +129,7 @@
129 }, 129 },
130 "secrets": { 130 "secrets": {
131 "locked": { 131 "locked": {
132 "narHash": "sha256-aRHKDVHDpnqpmgGhLGQxXwyTwmPuhUJTVcOLBYtY2ks=", 132 "narHash": "sha256-w3u1bMEJHCg9SqErJ5Qi0sTX2xx7mk+HrHZXzpjQd1w=",
133 "path": "../../secrets", 133 "path": "../../secrets",
134 "type": "path" 134 "type": "path"
135 }, 135 },
diff --git a/flakes/private/opendmarc/flake.nix b/flakes/private/opendmarc/flake.nix
index 2b73070..e2575e7 100644
--- a/flakes/private/opendmarc/flake.nix
+++ b/flakes/private/opendmarc/flake.nix
@@ -53,9 +53,8 @@
53 config.secrets.fullPaths."opendmarc/ignore.hosts" 53 config.secrets.fullPaths."opendmarc/ignore.hosts"
54 ]; 54 ];
55 }; 55 };
56 secrets.keys = [ 56 secrets.keys = {
57 { 57 "opendmarc/ignore.hosts" = {
58 dest = "opendmarc/ignore.hosts";
59 user = config.services.opendmarc.user; 58 user = config.services.opendmarc.user;
60 group = config.services.opendmarc.group; 59 group = config.services.opendmarc.group;
61 permissions = "0400"; 60 permissions = "0400";
@@ -67,8 +66,8 @@
67 builtins.concatStringsSep "\n" ([ 66 builtins.concatStringsSep "\n" ([
68 config.myEnv.mail.dmarc.ignore_hosts 67 config.myEnv.mail.dmarc.ignore_hosts
69 ] ++ lib.mapAttrsToList (n: v: v.fqdn) mxes); 68 ] ++ lib.mapAttrsToList (n: v: v.fqdn) mxes);
70 } 69 };
71 ]; 70 };
72 }; 71 };
73 }; 72 };
74 in 73 in
diff --git a/flakes/secrets/flake.nix b/flakes/secrets/flake.nix
index 0ee6a40..ef74a30 100644
--- a/flakes/secrets/flake.nix
+++ b/flakes/secrets/flake.nix
@@ -5,9 +5,42 @@
5 nixosModule = { config, lib, pkgs, ... }: { 5 nixosModule = { config, lib, pkgs, ... }: {
6 options.secrets = with lib; { 6 options.secrets = with lib; {
7 keys = mkOption { 7 keys = mkOption {
8 type = types.listOf types.unspecified; 8 type = types.attrsOf (types.submodule {
9 default = []; 9 options = {
10 description = "Keys to upload to server"; 10 isTemplated = mkOption {
11 type = types.bool;
12 default = true;
13 description = "If the file is a gucci template that needs to be resolved";
14 };
15 isDir = mkOption {
16 type = types.bool;
17 default = false;
18 description = "If the entry is a directory";
19 };
20 group = mkOption {
21 type = types.str;
22 default = "root";
23 description = "Group to associate to the entry";
24 };
25 user = mkOption {
26 type = types.str;
27 default = "root";
28 description = "User to associate to the entry";
29 };
30 permissions = mkOption {
31 type = types.str;
32 default = "0600";
33 description = "Permissions to associate to the entry";
34 };
35 text = mkOption {
36 type = types.str;
37 description = "Content of the entry";
38 };
39 };
40 });
41 default = {};
42 description = "Keys attrs to upload to the server";
43 apply = lib.mapAttrsToList (dest: v: v // { inherit dest; });
11 }; 44 };
12 gpgKeys = mkOption { 45 gpgKeys = mkOption {
13 type = types.listOf types.path; 46 type = types.listOf types.path;
@@ -52,20 +85,20 @@
52 location = config.secrets.location; 85 location = config.secrets.location;
53 keys = config.secrets.keys; 86 keys = config.secrets.keys;
54 empty = pkgs.runCommand "empty" { preferLocalBuild = true; } "mkdir -p $out && touch $out/done"; 87 empty = pkgs.runCommand "empty" { preferLocalBuild = true; } "mkdir -p $out && touch $out/done";
55 fpath = v: "secrets/${v.dest}${lib.optionalString (v.isTemplated or true) ".gucci.tpl"}"; 88 fpath = v: "secrets/${v.dest}${lib.optionalString v.isTemplated ".gucci.tpl"}";
56 dumpKey = v: 89 dumpKey = v:
57 if v.isDir or false then 90 if v.isDir then
58 '' 91 ''
59 mkdir -p secrets/${v.dest} 92 mkdir -p secrets/${v.dest}
60 cat >> mods <<EOF 93 cat >> mods <<EOF
61 ${v.user or "root"} ${v.group or "root"} ${v.permissions or "0600"} secrets/${v.dest} 94 ${v.user} ${v.group} ${v.permissions} secrets/${v.dest}
62 EOF 95 EOF
63 '' 96 ''
64 else '' 97 else ''
65 mkdir -p secrets/$(dirname ${v.dest}) 98 mkdir -p secrets/$(dirname ${v.dest})
66 echo -n ${lib.strings.escapeShellArg v.text} > ${fpath v} 99 echo -n ${lib.strings.escapeShellArg v.text} > ${fpath v}
67 cat >> mods <<EOF 100 cat >> mods <<EOF
68 ${v.user or "root"} ${v.group or "root"} ${v.permissions or "0600"} ${fpath v} 101 ${v.user} ${v.group} ${v.permissions} ${fpath v}
69 EOF 102 EOF
70 ''; 103 '';
71 secrets = pkgs.runCommand "secrets.tar.enc" { 104 secrets = pkgs.runCommand "secrets.tar.enc" {
@@ -88,7 +121,7 @@
88 ''; 121 '';
89 pathChmodExcl = 122 pathChmodExcl =
90 let 123 let
91 dirs = builtins.filter (v: v.isDir or false) keys; 124 dirs = builtins.filter (v: v.isDir) keys;
92 exclPath = builtins.concatStringsSep " -o " (map (d: " -path $TMP/${d.dest}") dirs); 125 exclPath = builtins.concatStringsSep " -o " (map (d: " -path $TMP/${d.dest}") dirs);
93 in 126 in
94 lib.optionalString (builtins.length dirs > 0) " -not \\( ${exclPath} \\) "; 127 lib.optionalString (builtins.length dirs > 0) " -not \\( ${exclPath} \\) ";