2023-05-14 09:50:01 +00:00
|
|
|
# SOPS configuration:
|
|
|
|
# docs: https://github.com/Mic92/sops-nix
|
|
|
|
#
|
|
|
|
# for each new user you want to edit sops files:
|
|
|
|
# create a private age key from ssh key:
|
|
|
|
# $ mkdir -p ~/.config/sops/age; ssh-to-age -private-key -i ~/.ssh/id_ed25519 > ~/.config/sops/age/keys.txt; chmod 600 ~/.config/sops/age/keys.txt
|
|
|
|
# if the private key was password protected, then first decrypt it:
|
|
|
|
# $ cp ~/.ssh/id_ed25519 /tmp/id_ed25519
|
|
|
|
# $ ssh-keygen -p -N "" -f /tmp/id_ed25519
|
|
|
|
#
|
|
|
|
# for each user you want to decrypt secrets:
|
|
|
|
# $ cat ~/.ssh/id_ed25519.pub | ssh-to-age
|
|
|
|
# add the result to .sops.yaml
|
|
|
|
# since we specify ssh pubkeys in the nix config, you can just grep for `ssh-ed25519` here and use those instead
|
|
|
|
#
|
|
|
|
# for each host you want to decrypt secrets:
|
|
|
|
# $ cat /etc/ssh/ssh_host_ed25519_key.pub | ssh-to-age
|
|
|
|
# add the result to .sops.yaml
|
|
|
|
# $ sops updatekeys secrets/example.yaml
|
|
|
|
#
|
|
|
|
# to create a new secret:
|
|
|
|
# $ sops secrets/example.yaml
|
|
|
|
# control access below (sops.secret.<x>.owner = ...)
|
|
|
|
#
|
|
|
|
# to read a secret:
|
|
|
|
# $ cat /run/secrets/example_key
|
2022-06-07 00:25:33 +00:00
|
|
|
|
2023-05-14 09:50:01 +00:00
|
|
|
{ config, lib, sane-lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib.strings) hasSuffix removeSuffix;
|
2023-06-28 03:57:57 +00:00
|
|
|
secretsForHost = host: let
|
|
|
|
extraAttrsForPath = path: lib.optionalAttrs (sane-lib.path.isChild "guest" path) {
|
|
|
|
owner = "guest";
|
|
|
|
};
|
|
|
|
in sane-lib.joinAttrsets (
|
2023-05-14 09:50:01 +00:00
|
|
|
map
|
|
|
|
(path: lib.optionalAttrs (hasSuffix ".bin" path) (sane-lib.nameValueToAttrs {
|
|
|
|
name = removeSuffix ".bin" path;
|
|
|
|
value = {
|
|
|
|
sopsFile = ../../secrets/${host}/${path};
|
|
|
|
format = "binary";
|
2023-06-28 03:57:57 +00:00
|
|
|
} // (extraAttrsForPath path);
|
2023-05-14 09:50:01 +00:00
|
|
|
}))
|
|
|
|
(sane-lib.enumerateFilePaths ../../secrets/${host})
|
|
|
|
);
|
|
|
|
in
|
2022-06-07 00:25:33 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
# sops.age.sshKeyPaths = [ "/home/colin/.ssh/id_ed25519_dec" ];
|
2022-10-23 13:48:39 +00:00
|
|
|
sops.gnupg.sshKeyPaths = []; # disable RSA key import
|
2022-06-07 00:25:33 +00:00
|
|
|
# This is using an age key that is expected to already be in the filesystem
|
|
|
|
# sops.age.keyFile = "/home/colin/.ssh/age.pub";
|
|
|
|
# sops.age.keyFile = "/var/lib/sops-nix/key.txt";
|
|
|
|
# This will generate a new key if the key specified above does not exist
|
|
|
|
# sops.age.generateKey = true;
|
|
|
|
# This is the actual specification of the secrets.
|
2022-06-10 00:41:03 +00:00
|
|
|
# sops.secrets.example_key = {
|
|
|
|
# owner = config.users.users.colin.name;
|
|
|
|
# };
|
2022-06-07 00:25:33 +00:00
|
|
|
# sops.secrets."myservice/my_subdir/my_secret" = {};
|
2022-12-26 08:09:58 +00:00
|
|
|
|
2023-05-14 09:50:01 +00:00
|
|
|
sops.secrets = lib.mkMerge [
|
|
|
|
(secretsForHost "common")
|
|
|
|
(secretsForHost config.networking.hostName)
|
|
|
|
{
|
|
|
|
"jackett_apikey".owner = config.users.users.colin.name;
|
|
|
|
"mx-sanebot-env".owner = config.users.users.colin.name;
|
|
|
|
"snippets".owner = config.users.users.colin.name;
|
2023-06-22 02:27:47 +00:00
|
|
|
"transmission_passwd".owner = config.users.users.colin.name;
|
2023-05-14 09:50:01 +00:00
|
|
|
}
|
|
|
|
];
|
2022-06-07 00:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|