From a114034e0e0df835b8c07d056497d529a0a03b97 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 4 Nov 2024 02:09:15 -0600 Subject: [PATCH] refactor: reworked all maps --- config/default.nix | 91 ++++++++++----------- nixos/modules/locale.nix | 33 ++++---- nixos/modules/services/acme.nix | 55 ++++++------- nixos/modules/services/castopod.nix | 6 +- nixos/modules/services/default.nix | 50 +++++------ nixos/modules/services/forgejo.nix | 6 +- nixos/modules/services/mastodon/default.nix | 7 +- nixos/modules/services/minecraft.nix | 5 +- nixos/modules/services/nextcloud.nix | 5 +- nixos/modules/services/peertube.nix | 9 +- nixos/modules/services/vaultwarden.nix | 5 +- nixos/modules/services/wiki.nix | 6 +- profiles/user0/configs/desktop.nix | 22 ++--- profiles/user0/configs/laptop.nix | 16 ++-- profiles/user0/configs/server.nix | 10 ++- profiles/user1/configs/desktop.nix | 16 ++-- profiles/user1/configs/laptop.nix | 16 ++-- systems/desktop/default.nix | 23 +++--- systems/laptop/default.nix | 23 +++--- systems/server/default.nix | 23 +++--- 20 files changed, 220 insertions(+), 207 deletions(-) diff --git a/config/default.nix b/config/default.nix index e545082..4b66b0d 100755 --- a/config/default.nix +++ b/config/default.nix @@ -1,41 +1,4 @@ {lib, ...}: let - deviceNames = [ - "desktop" - "laptop" - "nas" - "phone" - "printer0" - "printer1" - "server" - "tablet" - ]; - instanceNames = [ - "acme" - "caddy" - "castopod" - "forgejo" - "jellyfin" - "mastodon" - "matrix" - "minecraft" - "nextcloud" - "nginx" - "ollama" - "owncast" - "peertube" - "postgresql" - "samba" - "syncthing" - "synology" - "vaultwarden" - "web" - "wiki" - "writefreely" - ]; - userNames = [ - "user0" - "user1" - ]; stringType = lib.mkOption { type = lib.types.str; }; @@ -60,11 +23,16 @@ in let peopleSubmodule = lib.types.submodule { options = - builtins.listToAttrs (map (name: { + builtins.listToAttrs ( + map (name: { inherit name; value = stringType; }) - userNames) + [ + "user0" + "user1" + ] + ) // { user = lib.mkOption { type = lib.types.attrsOf userSubmodule; @@ -83,14 +51,33 @@ in let }; serviceSubmodule = lib.types.submodule { options = - builtins.listToAttrs ( - map - (name: { + builtins.listToAttrs (map (name: { inherit name; value = stringType; }) - instanceNames - ) + [ + "acme" + "caddy" + "castopod" + "forgejo" + "jellyfin" + "mastodon" + "matrix" + "minecraft" + "nextcloud" + "nginx" + "ollama" + "owncast" + "peertube" + "postgresql" + "samba" + "syncthing" + "synology" + "vaultwarden" + "web" + "wiki" + "writefreely" + ]) // { instance = lib.mkOption { type = lib.types.attrsOf instanceSubmodule; @@ -117,14 +104,20 @@ in let }; systemSubmodule = lib.types.submodule { options = - builtins.listToAttrs ( - map - (name: { + builtins.listToAttrs (map (name: { inherit name; value = stringType; }) - deviceNames - ) + [ + "desktop" + "laptop" + "nas" + "phone" + "printer0" + "printer1" + "server" + "tablet" + ]) // { device = lib.mkOption { type = lib.types.attrsOf deviceSubmodule; diff --git a/nixos/modules/locale.nix b/nixos/modules/locale.nix index 10ce022..07b202f 100755 --- a/nixos/modules/locale.nix +++ b/nixos/modules/locale.nix @@ -3,28 +3,25 @@ i18n = let locale = "en_CA.UTF-8"; - extraSettings = [ - "LC_ADDRESS" - "LC_IDENTIFICATION" - "LC_MEASUREMENT" - "LC_MONETARY" - "LC_NAME" - "LC_NUMERIC" - "LC_PAPER" - "LC_TELEPHONE" - "LC_TIME" - ]; in { defaultLocale = locale; - extraLocaleSettings = builtins.listToAttrs ( - map ( - option: { + extraLocaleSettings = + builtins.listToAttrs + (map (option: { name = option; value = locale; - } - ) - extraSettings - ); + }) + [ + "LC_ADDRESS" + "LC_IDENTIFICATION" + "LC_MEASUREMENT" + "LC_MONETARY" + "LC_NAME" + "LC_NUMERIC" + "LC_PAPER" + "LC_TELEPHONE" + "LC_TIME" + ]); }; } diff --git a/nixos/modules/services/acme.nix b/nixos/modules/services/acme.nix index d2017c7..0ffac3e 100755 --- a/nixos/modules/services/acme.nix +++ b/nixos/modules/services/acme.nix @@ -18,34 +18,6 @@ directory = instance.acme.paths.path0; environmentFile = config.sops.secrets."dns/namecheap".path; }; - - domain0SubdomainNames = [ - "nextcloud" - "jellyfin" - "minecraft" - "ollama" - "syncthing" - "vaultwarden" - ]; - - domain1SubdomainNames = [ - "wiki" - "nextcloud" - "castopod" - "forgejo" - "matrix" - "owncast" - "peertube" - "writefreely" - ]; - - domainRoot = [ - domain0 - domain1 - ]; - - domain0Subdomains = map instanceName domain0SubdomainNames; - domain1Subdomains = map instanceName domain1SubdomainNames; in { security.acme = { acceptTerms = true; @@ -58,17 +30,38 @@ in { name = "${prefix}.${domain0}"; value = dnsConfig; }) - domain0Subdomains) + map + instanceName [ + "nextcloud" + "jellyfin" + "minecraft" + "ollama" + "syncthing" + "vaultwarden" + ]) ++ (map (prefix: { name = "${prefix}.${domain1}"; value = dnsConfig; }) - domain1Subdomains) + map + instanceName [ + "wiki" + "nextcloud" + "castopod" + "forgejo" + "matrix" + "owncast" + "peertube" + "writefreely" + ]) ++ (map (name: { name = name; value = dnsConfig; }) - domainRoot) + [ + domain0 + domain1 + ]) ); }; diff --git a/nixos/modules/services/castopod.nix b/nixos/modules/services/castopod.nix index 27ef6ed..d0b3e5e 100755 --- a/nixos/modules/services/castopod.nix +++ b/nixos/modules/services/castopod.nix @@ -59,7 +59,6 @@ in { }; sops = let - sopsSecrets = ["smtp" "database"]; sopsPath = secret: { path = "${service.sops.path0}/${service.name}-${secret}"; owner = service.name; @@ -72,7 +71,10 @@ in { name = "${service.name}-${secret}"; value = sopsPath secret; }) - sopsSecrets + [ + "smtp" + "database" + ] ); }; diff --git a/nixos/modules/services/default.nix b/nixos/modules/services/default.nix index 2a11793..06e103e 100755 --- a/nixos/modules/services/default.nix +++ b/nixos/modules/services/default.nix @@ -1,27 +1,27 @@ -let - serviceFolders = [ - "mastodon" - ]; - - serviceFiles = [ - "acme" - "caddy" - "jellyfin" - "logrotate" - "minecraft" - "ollama" - "peertube" - "postgresql" - "owncast" - "samba" - "vaultwarden" - "wiki" - # "forgejo" - # "castopod" - # "nextcloud" - ]; -in { +{ imports = - (map (folder: ./${folder}) serviceFolders) - ++ (map (file: ./${file}.nix) serviceFiles); + (map + (folder: ./${folder}) + [ + "mastodon" + ]) + ++ (map + (file: ./${file}.nix) + [ + "acme" + "caddy" + "jellyfin" + "logrotate" + "minecraft" + "ollama" + "peertube" + "postgresql" + "owncast" + "samba" + "vaultwarden" + "wiki" + # "forgejo" + # "castopod" + # "nextcloud" + ]); } diff --git a/nixos/modules/services/forgejo.nix b/nixos/modules/services/forgejo.nix index 213676b..4db63fa 100755 --- a/nixos/modules/services/forgejo.nix +++ b/nixos/modules/services/forgejo.nix @@ -64,7 +64,6 @@ in { }; }; sops = let - sopsSecrets = ["smtp" "database"]; sopsPath = secret: { path = "${service.sops.path0}/${service.name}-${secret}"; owner = service.name; @@ -77,7 +76,10 @@ in { name = "${service.name}-${secret}"; value = sopsPath secret; }) - sopsSecrets + [ + "smtp" + "database" + ] ); }; diff --git a/nixos/modules/services/mastodon/default.nix b/nixos/modules/services/mastodon/default.nix index 4f36485..853d601 100755 --- a/nixos/modules/services/mastodon/default.nix +++ b/nixos/modules/services/mastodon/default.nix @@ -146,7 +146,6 @@ in { systemd.services.caddy.serviceConfig.ReadWriteDirectories = lib.mkForce ["/var/lib/caddy" "/run/mastodon-web"]; sops = let - sopsSecrets = ["smtp" "database" "redis"]; sopsPath = secret: { path = "${service.sops.path0}/${service.name}-${secret}"; owner = service.name; @@ -159,7 +158,11 @@ in { name = "${service.name}-${secret}"; value = sopsPath secret; }) - sopsSecrets + [ + "smtp" + "database" + "redis" + ] ); }; diff --git a/nixos/modules/services/minecraft.nix b/nixos/modules/services/minecraft.nix index 59d6357..9973298 100755 --- a/nixos/modules/services/minecraft.nix +++ b/nixos/modules/services/minecraft.nix @@ -50,7 +50,6 @@ in { }; }; sops = let - sopsSecrets = ["pass"]; sopsPath = secret: { path = "${service.sops.path0}/${service.name}-${secret}"; owner = service.name; @@ -63,7 +62,9 @@ in { name = "${service.name}-${secret}"; value = sopsPath secret; }) - sopsSecrets + [ + "pass" + ] ); }; diff --git a/nixos/modules/services/nextcloud.nix b/nixos/modules/services/nextcloud.nix index f1499b0..77af7cd 100755 --- a/nixos/modules/services/nextcloud.nix +++ b/nixos/modules/services/nextcloud.nix @@ -75,7 +75,6 @@ in { }; sops = let - sopsSecrets = ["pass"]; sopsPath = secret: { path = "${service.sops.path0}/${service.name}-${secret}"; owner = service.name; @@ -88,7 +87,9 @@ in { name = "${service.name}-${secret}"; value = sopsPath secret; }) - sopsSecrets + [ + "pass" + ] ); }; diff --git a/nixos/modules/services/peertube.nix b/nixos/modules/services/peertube.nix index ba3b070..77ee99f 100755 --- a/nixos/modules/services/peertube.nix +++ b/nixos/modules/services/peertube.nix @@ -81,7 +81,6 @@ in { }; sops = let - sopsSecrets = ["smtp" "database" "redis" "root" "secret"]; sopsPath = secret: { path = "${service.sops.path0}/${service.name}-${secret}-pass"; owner = service.name; @@ -94,7 +93,13 @@ in { name = "${service.name}-${secret}"; value = sopsPath secret; }) - sopsSecrets + [ + "smtp" + "database" + "redis" + "root" + "secret" + ] ); }; diff --git a/nixos/modules/services/vaultwarden.nix b/nixos/modules/services/vaultwarden.nix index f86abea..8896368 100755 --- a/nixos/modules/services/vaultwarden.nix +++ b/nixos/modules/services/vaultwarden.nix @@ -61,7 +61,6 @@ in { }; sops = let - sopsSecrets = ["env"]; sopsPath = secret: { path = "${service.sops.path0}/${service.name}-${secret}"; owner = service.name; @@ -74,7 +73,9 @@ in { name = "${service.name}/${secret}"; value = sopsPath secret; }) - sopsSecrets + [ + "env" + ] ); }; diff --git a/nixos/modules/services/wiki.nix b/nixos/modules/services/wiki.nix index 9e9e427..d5ba5a3 100755 --- a/nixos/modules/services/wiki.nix +++ b/nixos/modules/services/wiki.nix @@ -49,7 +49,6 @@ in { }; sops = let - sopsSecrets = ["pass" "ssh"]; sopsPath = secret: { path = "${service.sops.path0}/${secret}"; owner = "root"; @@ -62,7 +61,10 @@ in { name = "${service.name}/${secret}"; value = sopsPath secret; }) - sopsSecrets + [ + "pass" + "ssh" + ] ); }; diff --git a/profiles/user0/configs/desktop.nix b/profiles/user0/configs/desktop.nix index 19495f5..bd83834 100755 --- a/profiles/user0/configs/desktop.nix +++ b/profiles/user0/configs/desktop.nix @@ -1,16 +1,18 @@ {flake, ...}: let inherit (flake) self; - moduleNames = [ - "desktop" - "entertainment" - "productionArt" - "productionAudio" - "productionVideo" - "productionWriting" - "shared" - ]; - moduleImports = map (module: self.homeModules.${module}) moduleNames; + moduleImports = + map + (module: self.homeModules.${module}) + [ + "desktop" + "entertainment" + "productionArt" + "productionAudio" + "productionVideo" + "productionWriting" + "shared" + ]; in { imports = moduleImports; } diff --git a/profiles/user0/configs/laptop.nix b/profiles/user0/configs/laptop.nix index e84fccc..29a0c64 100755 --- a/profiles/user0/configs/laptop.nix +++ b/profiles/user0/configs/laptop.nix @@ -1,13 +1,15 @@ {flake, ...}: let inherit (flake) self; - moduleNames = [ - "entertainment" - "desktop" - "productionWriting" - "shared" - ]; - moduleImports = map (module: self.homeModules.${module}) moduleNames; + moduleImports = + map + (module: self.homeModules.${module}) + [ + "entertainment" + "desktop" + "productionWriting" + "shared" + ]; in { imports = moduleImports; } diff --git a/profiles/user0/configs/server.nix b/profiles/user0/configs/server.nix index b0e9fc8..a2625e5 100755 --- a/profiles/user0/configs/server.nix +++ b/profiles/user0/configs/server.nix @@ -1,10 +1,12 @@ {flake, ...}: let inherit (flake) self; - moduleNames = [ - "shared" - ]; - moduleImports = map (module: self.homeModules.${module}) moduleNames; + moduleImports = + map + (module: self.homeModules.${module}) + [ + "shared" + ]; in { imports = moduleImports; } diff --git a/profiles/user1/configs/desktop.nix b/profiles/user1/configs/desktop.nix index 09a9b2d..1fc4f4b 100755 --- a/profiles/user1/configs/desktop.nix +++ b/profiles/user1/configs/desktop.nix @@ -1,13 +1,15 @@ {flake, ...}: let inherit (flake) self; - moduleNames = [ - "desktop" - "entertainment" - "productionWriting" - "shared" - ]; - moduleImports = map (module: self.homeModules.${module}) moduleNames; + moduleImports = + map + (module: self.homeModules.${module}) + [ + "desktop" + "entertainment" + "productionWriting" + "shared" + ]; in { imports = moduleImports; } diff --git a/profiles/user1/configs/laptop.nix b/profiles/user1/configs/laptop.nix index 09a9b2d..1fc4f4b 100755 --- a/profiles/user1/configs/laptop.nix +++ b/profiles/user1/configs/laptop.nix @@ -1,13 +1,15 @@ {flake, ...}: let inherit (flake) self; - moduleNames = [ - "desktop" - "entertainment" - "productionWriting" - "shared" - ]; - moduleImports = map (module: self.homeModules.${module}) moduleNames; + moduleImports = + map + (module: self.homeModules.${module}) + [ + "desktop" + "entertainment" + "productionWriting" + "shared" + ]; in { imports = moduleImports; } diff --git a/systems/desktop/default.nix b/systems/desktop/default.nix index 339814a..83a9e05 100755 --- a/systems/desktop/default.nix +++ b/systems/desktop/default.nix @@ -1,14 +1,15 @@ -{lib, ...}: let - desktopFiles = [ - "boot" - "filesystem" - "graphics" - "hardware" - "networking" - "sops" - ]; -in { - imports = map (file: ./${file}.nix) desktopFiles; +{lib, ...}: { + imports = + map + (file: ./${file}.nix) + [ + "boot" + "filesystem" + "graphics" + "hardware" + "networking" + "sops" + ]; nixpkgs.hostPlatform = lib.mkForce "x86_64-linux"; system.stateVersion = lib.mkForce "24.05"; } diff --git a/systems/laptop/default.nix b/systems/laptop/default.nix index 590495e..83a9e05 100755 --- a/systems/laptop/default.nix +++ b/systems/laptop/default.nix @@ -1,14 +1,15 @@ -{lib, ...}: let - laptopFiles = [ - "boot" - "filesystem" - "graphics" - "hardware" - "networking" - "sops" - ]; -in { - imports = map (file: ./${file}.nix) laptopFiles; +{lib, ...}: { + imports = + map + (file: ./${file}.nix) + [ + "boot" + "filesystem" + "graphics" + "hardware" + "networking" + "sops" + ]; nixpkgs.hostPlatform = lib.mkForce "x86_64-linux"; system.stateVersion = lib.mkForce "24.05"; } diff --git a/systems/server/default.nix b/systems/server/default.nix index a3e0971..83a9e05 100755 --- a/systems/server/default.nix +++ b/systems/server/default.nix @@ -1,14 +1,15 @@ -{lib, ...}: let - serverFiles = [ - "boot" - "filesystem" - "graphics" - "hardware" - "networking" - "sops" - ]; -in { - imports = map (file: ./${file}.nix) serverFiles; +{lib, ...}: { + imports = + map + (file: ./${file}.nix) + [ + "boot" + "filesystem" + "graphics" + "hardware" + "networking" + "sops" + ]; nixpkgs.hostPlatform = lib.mkForce "x86_64-linux"; system.stateVersion = lib.mkForce "24.05"; }