From 95fea9184e55d925b97d69960b8f753d4134e16e Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Sun, 6 Jul 2025 23:56:11 +0800 Subject: [PATCH] refactor(configurations): add default nixos module --- README.md | 14 ++++++++++--- nix/files/readme.nix | 14 ++++++++++--- nix/lib/default.nix | 3 ++- nix/manifest.nix | 33 ++++++++++-------------------- nix/modules/flake/home-manager.nix | 2 +- nix/modules/nixos/networking.nix | 7 ------- nix/profiles/nixos/common.nix | 9 -------- 7 files changed, 36 insertions(+), 46 deletions(-) delete mode 100644 nix/modules/nixos/networking.nix delete mode 100644 nix/profiles/nixos/common.nix diff --git a/README.md b/README.md index bc5eaa5..851ccb2 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,18 @@ The list of generated files are: - [docs/cheatsheet.md](docs/cheatsheet.md) - [README.md](README.md) ## Structure - The system configurations are defined in [`flake.manifest`](nix/manifest.nix). - The attribute `flake.modules.nixos.common` provides options that will be applied to every system. +The system configurations are defined in [`flake.manifest`](nix/manifest.nix). +`flake.manifest.owner` provides the attributes for the administrator user, including username and pubkey. +`flake.manifest.hosts` provides the specifications for the system configurations that should be exposed by the flake as nixosConfigurations. +`flake.modules.nixos.*` provide NixOS options and configurations. +The attribute `flake.modules.nixos.default` provides options that will be applied to every system of that class. You can use it as seen [here](nix/modules/flake/home-manager.nix): ```nix -flake.modules.nixos.common.imports = [ inputs.home-manager.nixosModules.default ]; +flake.modules.nixos.default.imports = [ inputs.home-manager.nixosModules.default ]; ``` + +The other attributes under `flake.modules.nixos` should be opt-in, i.e. provide options that will be set in the profiles. +`flake.profiles.nixos` provides profiles which use the options defined in `flake.modules.nixos` to define different roles for each system, such as graphical, laptop, headless, etc. +Options should not be defined here. +`flake.contracts.nixos.*` will provide contracts, such as reverse proxies or databases, which will configure options on the provider and receiver host. diff --git a/nix/files/readme.nix b/nix/files/readme.nix index cd7ed99..036bcc9 100644 --- a/nix/files/readme.nix +++ b/nix/files/readme.nix @@ -8,13 +8,21 @@ ''; parts."Structure" = # markdown '' - The system configurations are defined in [`flake.manifest`](nix/manifest.nix). - The attribute `flake.modules.nixos.common` provides options that will be applied to every system. + The system configurations are defined in [`flake.manifest`](nix/manifest.nix). + `flake.manifest.owner` provides the attributes for the administrator user, including username and pubkey. + `flake.manifest.hosts` provides the specifications for the system configurations that should be exposed by the flake as nixosConfigurations. + `flake.modules.nixos.*` provide NixOS options and configurations. + The attribute `flake.modules.nixos.default` provides options that will be applied to every system of that class. You can use it as seen [here](nix/modules/flake/home-manager.nix): ```nix - flake.modules.nixos.common.imports = [ inputs.home-manager.nixosModules.default ]; + flake.modules.nixos.default.imports = [ inputs.home-manager.nixosModules.default ]; ``` + + The other attributes under `flake.modules.nixos` should be opt-in, i.e. provide options that will be set in the profiles. + `flake.profiles.nixos` provides profiles which use the options defined in `flake.modules.nixos` to define different roles for each system, such as graphical, laptop, headless, etc. + Options should not be defined here. + `flake.contracts.nixos.*` will provide contracts, such as reverse proxies or databases, which will configure options on the provider and receiver host. ''; }; diff --git a/nix/lib/default.nix b/nix/lib/default.nix index 907ffb6..29a3ae5 100644 --- a/nix/lib/default.nix +++ b/nix/lib/default.nix @@ -5,6 +5,7 @@ ... }: let + cfg = config.flake; inherit (lib.trivial) pipe; inherit (lib.strings) removePrefix hasPrefix; inherit (lib.attrsets) @@ -42,7 +43,7 @@ in ; }; modules = [ - config.flake.profiles.nixos.common + (flattenAttrs cfg.modules.nixos) (mkProfileCfg (value.profiles or [ ])) (value.extraCfg or { }) ]; diff --git a/nix/manifest.nix b/nix/manifest.nix index f8cd607..85f794e 100644 --- a/nix/manifest.nix +++ b/nix/manifest.nix @@ -1,11 +1,16 @@ let - testCfg = { - fileSystems."/" = { - device = "/dev/sda1"; - fsType = "ext4"; + testCfg = + { hostName, ... }: + { + fileSystems."/" = { + device = "/dev/sda1"; + fsType = "ext4"; + }; + nixpkgs.hostPlatform = "x86_64-linux"; + boot.loader.systemd-boot.enable = true; + system.stateVersion = "25.05"; + networking = { inherit hostName; }; }; - nixpkgs.hostPlatform = "x86_64-linux"; - }; in { flake.manifest = { @@ -16,7 +21,6 @@ in pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdsZyY3gu8IGB8MzMnLdh+ClDxQQ2RYG9rkeetIKq8n rafiq"; }; hosts = { - "nixos/test".extraCfg = testCfg; "nixos/nemesis" = { machine = { platform = "amd"; @@ -31,15 +35,6 @@ in } ]; }; - # profiles = with config.flake.profiles.nixos; [ - # graphical - # development - # ]; - # extraModules = with config.flakes.modules.nixos; [ - # sunshine - # sd-webui-forge - # comfy-ui - # ]; extraCfg = testCfg; }; "nixos/apollo" = { @@ -47,12 +42,6 @@ in platform = "intel"; root.drive = "/dev/disk/by-id/nvme-eui.002538d221b47b01"; }; - # profiles = with config.flake.profiles.nixos; [ headless ]; - # extraModules = with config.flakes.modules.nixos; [ - # librechat - # forgejo - # rrv-sh - # ]; extraCfg = testCfg; }; }; diff --git a/nix/modules/flake/home-manager.nix b/nix/modules/flake/home-manager.nix index ff64300..213e4ff 100644 --- a/nix/modules/flake/home-manager.nix +++ b/nix/modules/flake/home-manager.nix @@ -9,5 +9,5 @@ let in { imports = [ hm.flakeModules.home-manager ]; - flake.modules.nixos.common = globalCfg; + flake.modules.nixos.default = globalCfg; } diff --git a/nix/modules/nixos/networking.nix b/nix/modules/nixos/networking.nix deleted file mode 100644 index 1dc3fc6..0000000 --- a/nix/modules/nixos/networking.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ - flake.modules.nixos.networking = - { hostName, ... }: - { - networking = { inherit hostName; }; - }; -} diff --git a/nix/profiles/nixos/common.nix b/nix/profiles/nixos/common.nix deleted file mode 100644 index 2138f02..0000000 --- a/nix/profiles/nixos/common.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - flake.profiles.nixos.common = - { hostName, ... }: - { - boot.loader.systemd-boot.enable = true; - system.stateVersion = "25.05"; - networking = { inherit hostName; }; - }; -}