diff --git a/hosts/andromache/meta.nix b/hosts/andromache/meta.nix index 171cb53..63285bf 100644 --- a/hosts/andromache/meta.nix +++ b/hosts/andromache/meta.nix @@ -1,8 +1,8 @@ { system = "x86_64-linux"; - role = "desktop"; tags = [ "personal" ]; host = { + role = "desktop"; username = "h"; highRam = true; admin = true; diff --git a/hosts/astyanax/meta.nix b/hosts/astyanax/meta.nix index 3b7f792..06db80e 100644 --- a/hosts/astyanax/meta.nix +++ b/hosts/astyanax/meta.nix @@ -1,8 +1,8 @@ { system = "x86_64-linux"; - role = "laptop"; tags = [ "personal" ]; host = { + role = "laptop"; username = "h"; highRam = true; admin = true; diff --git a/hosts/eetion-02/meta.nix b/hosts/eetion-02/meta.nix index 6b1e816..7d1c360 100644 --- a/hosts/eetion-02/meta.nix +++ b/hosts/eetion-02/meta.nix @@ -1,8 +1,8 @@ { system = "aarch64-linux"; - role = "embedded"; tags = [ "lab" ]; host = { + role = "embedded"; username = "h"; }; } diff --git a/hosts/eetion/meta.nix b/hosts/eetion/meta.nix index 6b1e816..7d1c360 100644 --- a/hosts/eetion/meta.nix +++ b/hosts/eetion/meta.nix @@ -1,8 +1,8 @@ { system = "aarch64-linux"; - role = "embedded"; tags = [ "lab" ]; host = { + role = "embedded"; username = "h"; }; } diff --git a/hosts/hecuba/meta.nix b/hosts/hecuba/meta.nix index a84611f..25c041d 100644 --- a/hosts/hecuba/meta.nix +++ b/hosts/hecuba/meta.nix @@ -1,9 +1,9 @@ { system = "x86_64-linux"; - role = "server"; tags = [ "lab" ]; deploy.autoRollback = true; host = { + role = "server"; username = "h"; }; } diff --git a/hosts/vm/meta.nix b/hosts/vm/meta.nix index 61e7dd2..f1e9d2c 100644 --- a/hosts/vm/meta.nix +++ b/hosts/vm/meta.nix @@ -1,8 +1,8 @@ { system = "x86_64-linux"; - role = "vm"; tags = [ "lab" ]; host = { + role = "vm"; username = "h"; }; } diff --git a/modules/common/default.nix b/modules/common/default.nix index 006c103..3d24c11 100644 --- a/modules/common/default.nix +++ b/modules/common/default.nix @@ -1,92 +1,23 @@ -{ - inputs, - outputs, - dotsPath, - myUtils, - config, - ... -}: +{ lib, ... }: -let - inherit (inputs.nixpkgs) lib; - homeDir = ../../home/hosts + "/${config.host.name}"; -in { imports = [ - inputs.home-manager.nixosModules.default + ./embedded.nix + ./home-manager.nix ./host.nix + ./nix.nix + ./nixpkgs.nix + ./upgrades.nix ]; - options.nixpkgs.allowedUnfree = lib.mkOption { - type = lib.types.listOf lib.types.str; - default = [ ]; - }; - config = { system.stateVersion = lib.mkDefault "25.05"; boot.zfs.forceImportRoot = lib.mkDefault false; - nix = { - nixPath = [ "nixpkgs=${inputs.nixpkgs}" ]; # https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md - optimise = { - automatic = true; - dates = [ "05:00" ]; - }; - gc = { - automatic = true; - dates = "weekly"; - options = lib.mkDefault "--delete-older-than 30d"; - }; - settings.experimental-features = [ - "nix-command" - "flakes" - ]; - settings.trusted-public-keys = [ - "nix-signing-key:M6ouQRFl/bZ5QQrceQUyar6P7o8qg4wwVkxD1SSLL2k=" - ]; - }; - - system.autoUpgrade = { - enable = true; - flags = [ - "--recreate-lock-file" - "--commit-lock-file" - "--print-build-logs" - "--refresh" - ]; - dates = "05:00"; - randomizedDelaySec = "45min"; - allowReboot = false; - }; - - nixpkgs.config.allowUnfreePredicate = - pkg: builtins.elem (lib.getName pkg) config.nixpkgs.allowedUnfree; - environment.defaultPackages = lib.mkForce [ ]; environment.pathsToLink = [ "/share/applications" "/share/xdg-desktop-portal" ]; - - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - extraSpecialArgs = { - inherit - inputs - outputs - dotsPath - myUtils - ; - }; - sharedModules = [ - { - host.username = lib.mkDefault config.host.username; - } - ]; - users = lib.optionalAttrs (builtins.pathExists homeDir) { - ${config.host.username} = import homeDir; - }; - }; }; } diff --git a/modules/common/embedded.nix b/modules/common/embedded.nix new file mode 100644 index 0000000..3f66f7a --- /dev/null +++ b/modules/common/embedded.nix @@ -0,0 +1,15 @@ +{ lib, config, ... }: + +{ + config = lib.mkIf (config.host.role == "embedded") { + system.autoUpgrade.enable = false; + nix.settings.max-jobs = 0; + + zramSwap = { + enable = true; + memoryPercent = 100; + }; + + services.journald.settings.Journal.SystemMaxUse = "100M"; + }; +} diff --git a/modules/common/home-manager.nix b/modules/common/home-manager.nix new file mode 100644 index 0000000..0b09f51 --- /dev/null +++ b/modules/common/home-manager.nix @@ -0,0 +1,37 @@ +{ + inputs, + outputs, + dotsPath, + myUtils, + config, + lib, + ... +}: + +let + homeDir = ../../home/hosts + "/${config.host.name}"; +in +{ + imports = [ inputs.home-manager.nixosModules.default ]; + + config.home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + extraSpecialArgs = { + inherit + inputs + outputs + dotsPath + myUtils + ; + }; + sharedModules = [ + { + host.username = lib.mkDefault config.host.username; + } + ]; + users = lib.optionalAttrs (builtins.pathExists homeDir) { + ${config.host.username} = import homeDir; + }; + }; +} diff --git a/modules/common/host.nix b/modules/common/host.nix index dbf7101..027c262 100644 --- a/modules/common/host.nix +++ b/modules/common/host.nix @@ -10,6 +10,16 @@ type = lib.types.str; }; + role = lib.mkOption { + type = lib.types.enum [ + "desktop" + "embedded" + "laptop" + "server" + "vm" + ]; + }; + tags = lib.mkOption { type = lib.types.listOf lib.types.str; default = [ ]; diff --git a/modules/common/nix.nix b/modules/common/nix.nix new file mode 100644 index 0000000..18c90d5 --- /dev/null +++ b/modules/common/nix.nix @@ -0,0 +1,23 @@ +{ inputs, lib, ... }: + +{ + config.nix = { + nixPath = [ "nixpkgs=${inputs.nixpkgs}" ]; # https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md + optimise = { + automatic = true; + dates = [ "05:00" ]; + }; + gc = { + automatic = true; + dates = "weekly"; + options = lib.mkDefault "--delete-older-than 30d"; + }; + settings.experimental-features = [ + "nix-command" + "flakes" + ]; + settings.trusted-public-keys = [ + "nix-signing-key:M6ouQRFl/bZ5QQrceQUyar6P7o8qg4wwVkxD1SSLL2k=" + ]; + }; +} diff --git a/modules/common/nixpkgs.nix b/modules/common/nixpkgs.nix new file mode 100644 index 0000000..f8991d7 --- /dev/null +++ b/modules/common/nixpkgs.nix @@ -0,0 +1,11 @@ +{ lib, config, ... }: + +{ + options.nixpkgs.allowedUnfree = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + }; + + config.nixpkgs.config.allowUnfreePredicate = + pkg: builtins.elem (lib.getName pkg) config.nixpkgs.allowedUnfree; +} diff --git a/modules/common/upgrades.nix b/modules/common/upgrades.nix new file mode 100644 index 0000000..ff02a45 --- /dev/null +++ b/modules/common/upgrades.nix @@ -0,0 +1,16 @@ +{ lib, ... }: + +{ + config.system.autoUpgrade = { + enable = lib.mkDefault true; + flags = [ + "--recreate-lock-file" + "--commit-lock-file" + "--print-build-logs" + "--refresh" + ]; + dates = "05:00"; + randomizedDelaySec = "45min"; + allowReboot = false; + }; +}