refactor(secrets): simplify secrets
This commit is contained in:
@@ -13,10 +13,12 @@ let
|
|||||||
standalone = osConfig == null;
|
standalone = osConfig == null;
|
||||||
in
|
in
|
||||||
lib.optionalAttrs standalone {
|
lib.optionalAttrs standalone {
|
||||||
sops.secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" "anki" [
|
sops.secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" null {
|
||||||
|
anki = [
|
||||||
"sync-user"
|
"sync-user"
|
||||||
"sync-key"
|
"sync-key"
|
||||||
] { };
|
];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
// {
|
// {
|
||||||
warnings = lib.optional (
|
warnings = lib.optional (
|
||||||
|
|||||||
@@ -15,11 +15,13 @@ let
|
|||||||
in
|
in
|
||||||
lib.optionalAttrs standalone {
|
lib.optionalAttrs standalone {
|
||||||
sops = {
|
sops = {
|
||||||
secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" "taskwarrior" [
|
secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" null {
|
||||||
|
taskwarrior = [
|
||||||
"sync-server-url"
|
"sync-server-url"
|
||||||
"sync-server-client-id"
|
"sync-server-client-id"
|
||||||
"sync-encryption-secret"
|
"sync-encryption-secret"
|
||||||
] { };
|
];
|
||||||
|
};
|
||||||
|
|
||||||
templates."taskrc.d/sync" = {
|
templates."taskrc.d/sync" = {
|
||||||
content = ''
|
content = ''
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
{ config, myUtils, ... }:
|
{ config, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (config.secrets) sopsDir;
|
|
||||||
inherit (config.host) username;
|
inherit (config.host) username;
|
||||||
owner = config.users.users.${username}.name;
|
inherit (config.secrets) owner;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
config.sops = {
|
config = {
|
||||||
secrets = myUtils.mkSopsSecrets sopsDir "opencode" [ "api-key" ] { inherit owner; };
|
secrets.groups.opencode = [ "api-key" ];
|
||||||
|
|
||||||
templates."opencode/auth.json" = {
|
sops.templates."opencode/auth.json" = {
|
||||||
inherit owner;
|
inherit owner;
|
||||||
path = "/home/${username}/.local/share/opencode/auth.json";
|
path = "/home/${username}/.local/share/opencode/auth.json";
|
||||||
content = ''
|
content = ''
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
{ config, myUtils, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
inherit (config.secrets) sopsDir;
|
|
||||||
inherit (config.host) username;
|
|
||||||
owner = config.users.users.${username}.name;
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
config.sops = {
|
config.secrets.groups.anki = [
|
||||||
secrets = myUtils.mkSopsSecrets sopsDir "anki" [ "sync-user" "sync-key" ] { inherit owner; };
|
"sync-user"
|
||||||
};
|
"sync-key"
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
myUtils,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.restic-backup;
|
cfg = config.restic-backup;
|
||||||
inherit (config.secrets) sopsDir;
|
|
||||||
mkSopsSecrets = myUtils.mkSopsSecrets sopsDir;
|
|
||||||
host = config.networking.hostName;
|
host = config.networking.hostName;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -27,12 +24,16 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
sops = {
|
secrets.groups = {
|
||||||
secrets = lib.mkMerge [
|
restic = [ "password" ];
|
||||||
(mkSopsSecrets "restic" [ "password" ] { })
|
backblaze-b2 = [
|
||||||
(mkSopsSecrets "backblaze-b2" [ "bucket-name" "account-id" "account-key" ] { })
|
"bucket-name"
|
||||||
|
"account-id"
|
||||||
|
"account-key"
|
||||||
];
|
];
|
||||||
templates = {
|
};
|
||||||
|
|
||||||
|
sops.templates = {
|
||||||
"restic/repo-${host}" = {
|
"restic/repo-${host}" = {
|
||||||
content = "b2:${config.sops.placeholder."backblaze-b2/bucket-name"}:${host}";
|
content = "b2:${config.sops.placeholder."backblaze-b2/bucket-name"}:${host}";
|
||||||
};
|
};
|
||||||
@@ -43,7 +44,6 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
services.restic.backups.home = {
|
services.restic.backups.home = {
|
||||||
repositoryFile = config.sops.templates."restic/repo-${host}".path;
|
repositoryFile = config.sops.templates."restic/repo-${host}".path;
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
myUtils,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.hcloud;
|
cfg = config.hcloud;
|
||||||
inherit (config.host) username;
|
inherit (config.host) username;
|
||||||
inherit (config.secrets) sopsDir;
|
inherit (config.secrets) owner;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.hcloud = {
|
options.hcloud = {
|
||||||
@@ -16,12 +15,10 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
sops.secrets = myUtils.mkSopsSecrets sopsDir "hcloud" [ "api-token" ] {
|
secrets.groups.hcloud = [ "api-token" ];
|
||||||
owner = config.users.users.${username}.name;
|
|
||||||
};
|
|
||||||
|
|
||||||
sops.templates."hcloud/cli.toml" = {
|
sops.templates."hcloud/cli.toml" = {
|
||||||
owner = config.users.users.${username}.name;
|
inherit owner;
|
||||||
path = "/home/${username}/.config/hcloud/cli.toml";
|
path = "/home/${username}/.config/hcloud/cli.toml";
|
||||||
content = ''
|
content = ''
|
||||||
active_context = "server"
|
active_context = "server"
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ let
|
|||||||
inherit (config.host) username;
|
inherit (config.host) username;
|
||||||
inherit (cfg) sopsDir;
|
inherit (cfg) sopsDir;
|
||||||
owner = config.users.users.${username}.name;
|
owner = config.users.users.${username}.name;
|
||||||
mkSopsSecrets = myUtils.mkSopsSecrets sopsDir;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ inputs.sops-nix.nixosModules.sops ];
|
imports = [ inputs.sops-nix.nixosModules.sops ];
|
||||||
@@ -24,6 +23,15 @@ in
|
|||||||
default = "${toString inputs.nix-secrets}/secrets";
|
default = "${toString inputs.nix-secrets}/secrets";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
groups = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf (lib.types.listOf lib.types.str);
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
|
||||||
|
owner = lib.mkOption {
|
||||||
|
type = lib.types.unspecified;
|
||||||
|
};
|
||||||
|
|
||||||
nixSigningKey = {
|
nixSigningKey = {
|
||||||
enable = lib.mkEnableOption "nix signing key configuration";
|
enable = lib.mkEnableOption "nix signing key configuration";
|
||||||
};
|
};
|
||||||
@@ -35,27 +43,28 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
secrets = {
|
||||||
|
inherit owner;
|
||||||
|
groups = {
|
||||||
|
email = [
|
||||||
|
"personal"
|
||||||
|
"work"
|
||||||
|
];
|
||||||
|
nix = lib.optional cfg.nixSigningKey.enable "signing-key";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
sops = {
|
sops = {
|
||||||
# for yubikey, generate as follows:
|
# for yubikey, generate as follows:
|
||||||
# ```
|
# ```
|
||||||
# age-plugin-yubikey --identity > <keyfile-path>
|
# age-plugin-yubikey --identity > <keyfile-path>
|
||||||
# ```
|
# ```
|
||||||
age.keyFile = "/home/${username}/.config/sops/age/keys.txt";
|
age.keyFile = "/home/${username}/.config/sops/age/keys.txt";
|
||||||
|
secrets = myUtils.mkSopsSecrets sopsDir owner cfg.groups;
|
||||||
secrets = lib.mkMerge [
|
|
||||||
(mkSopsSecrets "email" [ "personal" "work" ] { inherit owner; })
|
|
||||||
(lib.mkIf cfg.nixSigningKey.enable {
|
|
||||||
nix-signing-key = {
|
|
||||||
sopsFile = "${sopsDir}/nix.yaml";
|
|
||||||
key = "signing-key";
|
|
||||||
inherit owner;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
nix.settings.secret-key-files = lib.mkIf cfg.nixSigningKey.enable [
|
nix.settings.secret-key-files = lib.mkIf cfg.nixSigningKey.enable [
|
||||||
config.sops.secrets.nix-signing-key.path
|
config.sops.secrets."nix/signing-key".path
|
||||||
];
|
];
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
{ config, myUtils, ... }:
|
{ config, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (config.secrets) sopsDir;
|
inherit (config.secrets) owner;
|
||||||
inherit (config.host) username;
|
|
||||||
owner = config.users.users.${username}.name;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
config.sops = {
|
config = {
|
||||||
secrets = myUtils.mkSopsSecrets sopsDir "taskwarrior" [
|
secrets.groups.taskwarrior = [
|
||||||
"sync-server-url"
|
"sync-server-url"
|
||||||
"sync-server-client-id"
|
"sync-server-client-id"
|
||||||
"sync-encryption-secret"
|
"sync-encryption-secret"
|
||||||
] { inherit owner; };
|
];
|
||||||
|
|
||||||
templates."taskrc.d/sync" = {
|
sops.templates."taskrc.d/sync" = {
|
||||||
inherit owner;
|
inherit owner;
|
||||||
content = ''
|
content = ''
|
||||||
sync.server.url=${config.sops.placeholder."taskwarrior/sync-server-url"}
|
sync.server.url=${config.sops.placeholder."taskwarrior/sync-server-url"}
|
||||||
|
|||||||
@@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
mkSopsSecrets =
|
mkSopsSecrets =
|
||||||
sopsDir: group: names: extraOpts:
|
sopsDir: owner: groups:
|
||||||
|
let
|
||||||
|
opts = lib.optionalAttrs (owner != null) { inherit owner; };
|
||||||
|
mkGroup =
|
||||||
|
group: names:
|
||||||
let
|
let
|
||||||
file = "${group}.yaml";
|
file = "${group}.yaml";
|
||||||
in
|
in
|
||||||
@@ -12,9 +16,11 @@
|
|||||||
sopsFile = "${sopsDir}/${file}";
|
sopsFile = "${sopsDir}/${file}";
|
||||||
key = name;
|
key = name;
|
||||||
}
|
}
|
||||||
// extraOpts;
|
// opts;
|
||||||
}) names
|
}) names
|
||||||
);
|
);
|
||||||
|
in
|
||||||
|
lib.foldl' lib.mergeAttrs { } (lib.mapAttrsToList mkGroup groups);
|
||||||
|
|
||||||
sopsAvailability =
|
sopsAvailability =
|
||||||
config: osConfig:
|
config: osConfig:
|
||||||
|
|||||||
Reference in New Issue
Block a user