mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 14:01:34 +01:00
sops: generate the config with nix
This commit is contained in:
parent
021473a99d
commit
5e18975b9b
12 changed files with 85 additions and 74 deletions
53
.sops.yaml
53
.sops.yaml
|
|
@ -1,53 +0,0 @@
|
||||||
keys:
|
|
||||||
- &admin age1mpq8m4p7dnxh5ze3fh7etd2k6sp85zdnmp9te3e9chcw4pw07pcq960zh5
|
|
||||||
|
|
||||||
# Hosts
|
|
||||||
- &alto age1qz04yg4h4g22wxqca2pd5k0z574223f6m5c9jy5ny37nlgcd6u4styf06t
|
|
||||||
- &cirrus age1dnpwfwh0h95r63e5qfjc2gvffw2tr2tx4new7sq2h3qs90kx9fmq322mx4
|
|
||||||
- &cumulus age1dnru7l0agvnw3t9kmx60u4vh5u4tyd49xdve53zspxkznnp9f34qtec9dl
|
|
||||||
- &fern age1sywwrwse76x8yskrsfpwk38fu2cmyx5s9qkf2pgc68cta0vj9psql7dp6e
|
|
||||||
- &north age18x6herevmcuhcmeh47ll6p9ck9zk4ga6gfxwlc8yl49rwjxm7qusylwfgc
|
|
||||||
|
|
||||||
# Users
|
|
||||||
- &seb-fern age190mf9wx4ct7qvne3ly9j3cj9740z5wnfhsl6vsc5wtfyc5pueuas9hnjtr
|
|
||||||
- &seb-north age1p32cyzakxtcx346ej82ftln4r2aw2pcuazq3583s85nzsan4ygqsj32hjf
|
|
||||||
|
|
||||||
creation_rules:
|
|
||||||
# Hosts
|
|
||||||
- path_regex: hosts/alto/secrets.json$
|
|
||||||
key_groups:
|
|
||||||
- age:
|
|
||||||
- *admin
|
|
||||||
- *alto
|
|
||||||
- path_regex: hosts/cirrus/secrets.json$
|
|
||||||
key_groups:
|
|
||||||
- age:
|
|
||||||
- *admin
|
|
||||||
- *cirrus
|
|
||||||
- path_regex: hosts/cumulus/secrets.json$
|
|
||||||
key_groups:
|
|
||||||
- age:
|
|
||||||
- *admin
|
|
||||||
- *cumulus
|
|
||||||
- path_regex: hosts/fern/secrets.json$
|
|
||||||
key_groups:
|
|
||||||
- age:
|
|
||||||
- *admin
|
|
||||||
- *fern
|
|
||||||
- path_regex: hosts/north/secrets.json$
|
|
||||||
key_groups:
|
|
||||||
- age:
|
|
||||||
- *admin
|
|
||||||
- *north
|
|
||||||
|
|
||||||
# Users
|
|
||||||
- path_regex: users/seb/@fern/secrets.json$
|
|
||||||
key_groups:
|
|
||||||
- age:
|
|
||||||
- *admin
|
|
||||||
- *seb-fern
|
|
||||||
- path_regex: users/seb/@north/secrets.json$
|
|
||||||
key_groups:
|
|
||||||
- age:
|
|
||||||
- *admin
|
|
||||||
- *seb-north
|
|
||||||
|
|
@ -74,6 +74,7 @@
|
||||||
./flake/formatter.nix
|
./flake/formatter.nix
|
||||||
./flake/hosts.nix
|
./flake/hosts.nix
|
||||||
./flake/modules.nix
|
./flake/modules.nix
|
||||||
|
./flake/packages.nix
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
37
flake/packages.nix
Normal file
37
flake/packages.nix
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
{ self, ... }:
|
||||||
|
{
|
||||||
|
perSystem =
|
||||||
|
{ pkgs, lib, ... }:
|
||||||
|
{
|
||||||
|
packages.sops-config =
|
||||||
|
let
|
||||||
|
adminKey = "age1mpq8m4p7dnxh5ze3fh7etd2k6sp85zdnmp9te3e9chcw4pw07pcq960zh5";
|
||||||
|
|
||||||
|
mkCreationRule = sopsCfg: {
|
||||||
|
path_regex = sopsCfg.secretsFile;
|
||||||
|
key_groups = lib.singleton {
|
||||||
|
age = [
|
||||||
|
adminKey
|
||||||
|
sopsCfg.agePublicKey
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
hostCreationRules =
|
||||||
|
self.nixosConfigurations
|
||||||
|
|> lib.filterAttrs (_: value: value.config.custom.sops.enable or false)
|
||||||
|
|> lib.mapAttrsToList (_: value: mkCreationRule value.config.custom.sops);
|
||||||
|
|
||||||
|
userCreationRules =
|
||||||
|
self.nixosConfigurations
|
||||||
|
|> lib.filterAttrs (_: value: value.config.home-manager.users.seb.custom.sops.enable or false)
|
||||||
|
|> lib.mapAttrsToList (_: value: mkCreationRule value.config.home-manager.users.seb.custom.sops);
|
||||||
|
|
||||||
|
jsonConfig = { creation_rules = hostCreationRules ++ userCreationRules; } |> builtins.toJSON;
|
||||||
|
in
|
||||||
|
pkgs.runCommand "sops-config" { buildInputs = [ pkgs.yj ]; } ''
|
||||||
|
mkdir $out
|
||||||
|
echo '${jsonConfig}' | yj -jy > $out/sops.yaml
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -8,9 +8,11 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
custom = {
|
custom = {
|
||||||
sops.enable = true;
|
sops = {
|
||||||
|
enable = true;
|
||||||
|
agePublicKey = "age1qz04yg4h4g22wxqca2pd5k0z574223f6m5c9jy5ny37nlgcd6u4styf06t";
|
||||||
|
};
|
||||||
boot.loader.systemdBoot.enable = true;
|
boot.loader.systemdBoot.enable = true;
|
||||||
|
|
||||||
users.seb.enable = true;
|
users.seb.enable = true;
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,11 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
custom = {
|
custom = {
|
||||||
sops.enable = true;
|
sops = {
|
||||||
|
enable = true;
|
||||||
|
agePublicKey = "age1dnpwfwh0h95r63e5qfjc2gvffw2tr2tx4new7sq2h3qs90kx9fmq322mx4";
|
||||||
|
};
|
||||||
boot.loader.grub.enable = true;
|
boot.loader.grub.enable = true;
|
||||||
|
|
||||||
users.seb.enable = true;
|
users.seb.enable = true;
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,11 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
custom = {
|
custom = {
|
||||||
sops.enable = true;
|
sops = {
|
||||||
|
enable = true;
|
||||||
|
agePublicKey = "age1dnru7l0agvnw3t9kmx60u4vh5u4tyd49xdve53zspxkznnp9f34qtec9dl";
|
||||||
|
};
|
||||||
boot.loader.grub.enable = true;
|
boot.loader.grub.enable = true;
|
||||||
|
|
||||||
users.seb.enable = true;
|
users.seb.enable = true;
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,14 @@
|
||||||
boot.kernelPackages = pkgs.linuxPackages_latest;
|
boot.kernelPackages = pkgs.linuxPackages_latest;
|
||||||
|
|
||||||
custom = {
|
custom = {
|
||||||
sops.enable = true;
|
sops = {
|
||||||
|
enable = true;
|
||||||
|
agePublicKey = "age1sywwrwse76x8yskrsfpwk38fu2cmyx5s9qkf2pgc68cta0vj9psql7dp6e";
|
||||||
|
};
|
||||||
boot = {
|
boot = {
|
||||||
loader.systemdBoot.enable = true;
|
loader.systemdBoot.enable = true;
|
||||||
silent = true;
|
silent = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
users.seb = {
|
users.seb = {
|
||||||
enable = true;
|
enable = true;
|
||||||
zsh.enable = true;
|
zsh.enable = true;
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,14 @@
|
||||||
boot.kernelPackages = pkgs.linuxPackages_latest;
|
boot.kernelPackages = pkgs.linuxPackages_latest;
|
||||||
|
|
||||||
custom = {
|
custom = {
|
||||||
sops.enable = true;
|
sops = {
|
||||||
|
enable = true;
|
||||||
|
agePublicKey = "age18x6herevmcuhcmeh47ll6p9ck9zk4ga6gfxwlc8yl49rwjxm7qusylwfgc";
|
||||||
|
};
|
||||||
boot = {
|
boot = {
|
||||||
loader.systemdBoot.enable = true;
|
loader.systemdBoot.enable = true;
|
||||||
silent = true;
|
silent = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
users.seb = {
|
users.seb = {
|
||||||
enable = true;
|
enable = true;
|
||||||
zsh.enable = true;
|
zsh.enable = true;
|
||||||
|
|
|
||||||
|
|
@ -7,30 +7,36 @@
|
||||||
}@moduleArgs:
|
}@moduleArgs:
|
||||||
let
|
let
|
||||||
cfg = config.custom.sops;
|
cfg = config.custom.sops;
|
||||||
|
|
||||||
|
absoluteSecretsPath = "${self}/" + cfg.secretsFile;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ inputs.sops-nix.homeManagerModules.sops ];
|
imports = [ inputs.sops-nix.homeManagerModules.sops ];
|
||||||
|
|
||||||
options.custom.sops = {
|
options.custom.sops = {
|
||||||
enable = lib.mkEnableOption "";
|
enable = lib.mkEnableOption "";
|
||||||
|
agePublicKey = lib.mkOption {
|
||||||
|
type = lib.types.nonEmptyStr;
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
hostName = lib.mkOption {
|
hostName = lib.mkOption {
|
||||||
type = lib.types.nonEmptyStr;
|
type = lib.types.nonEmptyStr;
|
||||||
default = moduleArgs.osConfig.networking.hostName or "";
|
default = moduleArgs.osConfig.networking.hostName or "";
|
||||||
};
|
};
|
||||||
defaultSopsFile = lib.mkOption {
|
secretsFile = lib.mkOption {
|
||||||
type = lib.types.path;
|
type = lib.types.nonEmptyStr;
|
||||||
default = "${self}/users/${config.home.username}/@${cfg.hostName}/secrets.json";
|
default = "users/${config.home.username}/@${cfg.hostName}/secrets.json";
|
||||||
};
|
};
|
||||||
secrets = lib.mkOption {
|
secrets = lib.mkOption {
|
||||||
type = lib.types.anything;
|
type = lib.types.anything;
|
||||||
default = cfg.defaultSopsFile |> builtins.readFile |> builtins.fromJSON;
|
default = absoluteSecretsPath |> builtins.readFile |> builtins.fromJSON;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
sops = {
|
sops = {
|
||||||
age.sshKeyPaths = [ "${config.home.homeDirectory}/.ssh/id_ed25519" ];
|
age.sshKeyPaths = [ "${config.home.homeDirectory}/.ssh/id_ed25519" ];
|
||||||
inherit (cfg) defaultSopsFile;
|
defaultSopsFile = absoluteSecretsPath;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,26 +7,32 @@
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.custom.sops;
|
cfg = config.custom.sops;
|
||||||
|
|
||||||
|
absoluteSecretsPath = "${self}/" + cfg.secretsFile;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ inputs.sops-nix.nixosModules.sops ];
|
imports = [ inputs.sops-nix.nixosModules.sops ];
|
||||||
|
|
||||||
options.custom.sops = {
|
options.custom.sops = {
|
||||||
enable = lib.mkEnableOption "";
|
enable = lib.mkEnableOption "";
|
||||||
defaultSopsFile = lib.mkOption {
|
agePublicKey = lib.mkOption {
|
||||||
type = lib.types.path;
|
type = lib.types.nonEmptyStr;
|
||||||
default = "${self}/hosts/${config.networking.hostName}/secrets.json";
|
default = "";
|
||||||
|
};
|
||||||
|
secretsFile = lib.mkOption {
|
||||||
|
type = lib.types.nonEmptyStr;
|
||||||
|
default = "hosts/${config.networking.hostName}/secrets.json";
|
||||||
};
|
};
|
||||||
secrets = lib.mkOption {
|
secrets = lib.mkOption {
|
||||||
type = lib.types.anything;
|
type = lib.types.anything;
|
||||||
default = cfg.defaultSopsFile |> builtins.readFile |> builtins.fromJSON;
|
default = absoluteSecretsPath |> builtins.readFile |> builtins.fromJSON;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
sops = {
|
sops = {
|
||||||
age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
|
age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
|
||||||
inherit (cfg) defaultSopsFile;
|
defaultSopsFile = absoluteSecretsPath;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ _: {
|
||||||
home.stateVersion = "24.11";
|
home.stateVersion = "24.11";
|
||||||
|
|
||||||
custom = {
|
custom = {
|
||||||
|
sops.agePublicKey = "age190mf9wx4ct7qvne3ly9j3cj9740z5wnfhsl6vsc5wtfyc5pueuas9hnjtr";
|
||||||
theme = "light";
|
theme = "light";
|
||||||
programs.brightnessctl.enable = true;
|
programs.brightnessctl.enable = true;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@
|
||||||
|
|
||||||
home.stateVersion = "23.11";
|
home.stateVersion = "23.11";
|
||||||
|
|
||||||
custom.theme = "dark";
|
custom = {
|
||||||
|
sops.agePublicKey = "age1p32cyzakxtcx346ej82ftln4r2aw2pcuazq3583s85nzsan4ygqsj32hjf";
|
||||||
|
theme = "dark";
|
||||||
|
};
|
||||||
|
|
||||||
home.packages = [
|
home.packages = [
|
||||||
pkgs.ffmpeg
|
pkgs.ffmpeg
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue