summaryrefslogtreecommitdiff
path: root/modules/nixos/traits
diff options
context:
space:
mode:
authorseth <[email protected]>2024-10-27 20:12:19 -0400
committerGitHub <[email protected]>2024-10-28 00:12:19 +0000
commit5ec7ee21e036f7bc1cbdec714271c619cb3fdb3d (patch)
tree3277d8ba68ca466e68c58a8373063010db392d2e /modules/nixos/traits
parent75ec48c5f7dd7877f2294b86764b1fdadc6b7e88 (diff)
modules: restructure (#487)
* seth: remove unused pkgs * modules: restructure from archetypes back to profiles make less actual modules for everything use lib.mkDefault like it's supposed to move mixins out of server * nixos/resolved: use modern options
Diffstat (limited to 'modules/nixos/traits')
-rw-r--r--modules/nixos/traits/default.nix2
-rw-r--r--modules/nixos/traits/nvd-diff.nix27
-rw-r--r--modules/nixos/traits/resolved.nix41
-rw-r--r--modules/nixos/traits/secrets.nix50
4 files changed, 112 insertions, 8 deletions
diff --git a/modules/nixos/traits/default.nix b/modules/nixos/traits/default.nix
index 88a0b8c..1bb92b2 100644
--- a/modules/nixos/traits/default.nix
+++ b/modules/nixos/traits/default.nix
@@ -6,7 +6,9 @@
./containers.nix
./home-manager.nix
./locale.nix
+ ./nvd-diff.nix
./nvidia.nix
+ ./resolved.nix
./secrets.nix
./tailscale.nix
./users
diff --git a/modules/nixos/traits/nvd-diff.nix b/modules/nixos/traits/nvd-diff.nix
new file mode 100644
index 0000000..4c59287
--- /dev/null
+++ b/modules/nixos/traits/nvd-diff.nix
@@ -0,0 +1,27 @@
+{
+ config,
+ lib,
+ pkgs,
+ ...
+}:
+let
+ cfg = config.traits.nvd-diff;
+in
+{
+ options.traits.nvd-diff = {
+ enable = lib.mkEnableOption "showing configuration diffs with NVD on upgrade" // {
+ default = true;
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ system.activationScripts."upgrade-diff" = {
+ supportsDryActivation = true;
+ text = ''
+ ${lib.getExe pkgs.nvd} \
+ --nix-bin-dir=${config.nix.package}/bin \
+ diff /run/current-system "$systemConfig"
+ '';
+ };
+ };
+}
diff --git a/modules/nixos/traits/resolved.nix b/modules/nixos/traits/resolved.nix
new file mode 100644
index 0000000..d6501c9
--- /dev/null
+++ b/modules/nixos/traits/resolved.nix
@@ -0,0 +1,41 @@
+{
+ config,
+ lib,
+ ...
+}:
+let
+ cfg = config.traits.resolved;
+in
+{
+ options.traits.resolved = {
+ enable = lib.mkEnableOption "systemd-resolved as the DNS resolver" // {
+ default = true;
+ };
+
+ networkManagerIntegration = lib.mkEnableOption "integration with network-manager" // {
+ default = config.networking.networkmanager.enable;
+ defaultText = "config.networking.networkmanager.enable";
+ };
+ };
+
+ config = lib.mkIf cfg.enable (
+ lib.mkMerge [
+ {
+ networking.nameservers = [
+ "1.1.1.1#one.one.one.one"
+ "1.0.0.1#one.one.one.one"
+ ];
+
+ services.resolved = {
+ enable = true;
+ dnssec = "allow-downgrade";
+ dnsovertls = "true";
+ };
+ }
+
+ (lib.mkIf cfg.networkManagerIntegration {
+ networking.networkmanager.dns = "systemd-resolved";
+ })
+ ]
+ );
+}
diff --git a/modules/nixos/traits/secrets.nix b/modules/nixos/traits/secrets.nix
index 6624ef8..d7f4e60 100644
--- a/modules/nixos/traits/secrets.nix
+++ b/modules/nixos/traits/secrets.nix
@@ -2,6 +2,7 @@
config,
lib,
inputs,
+ secretsDir,
...
}:
let
@@ -10,17 +11,50 @@ in
{
options.traits.secrets = {
enable = lib.mkEnableOption "secrets management";
- };
-
- imports = [ inputs.agenix.nixosModules.default ];
- config = lib.mkIf cfg.enable {
- _module.args = {
- secretsDir = inputs.self + "/secrets/${config.networking.hostName}";
+ rootUser = lib.mkEnableOption "manage secrets for root user" // {
+ default = true;
};
- age = {
- identityPaths = [ "/etc/age/key" ];
+ hostUser = lib.mkEnableOption "manager secrets for host user (see `profiles.server.hostUser`)" // {
+ default = config.profiles.server.hostUser;
+ defaultText = "config.profiles.server.hostUser";
};
};
+
+ imports = [ inputs.agenix.nixosModules.default ];
+
+ config = lib.mkIf cfg.enable (
+ lib.mkMerge [
+ {
+ _module.args = {
+ secretsDir = inputs.self + "/secrets/${config.networking.hostName}";
+ };
+
+ age = {
+ identityPaths = [ "/etc/age/key" ];
+ };
+ }
+
+ (lib.mkIf cfg.rootUser {
+ age.secrets = {
+ rootPassword.file = secretsDir + "/rootPassword.age";
+ };
+
+ users.users.root = {
+ hashedPasswordFile = config.age.secrets.rootPassword.path;
+ };
+ })
+
+ (lib.mkIf (config.profiles.server.enable && cfg.hostUser) {
+ age.secrets = {
+ userPassword.file = secretsDir + "/userPassword.age";
+ };
+
+ users.users.${config.networking.hostName} = {
+ hashedPasswordFile = config.age.secrets.userPassword.path;
+ };
+ })
+ ]
+ );
}