refactor(configurations): add default nixos module

This commit is contained in:
Mohammad Rafiq 2025-07-06 23:56:11 +08:00
parent aef828b713
commit 95fea9184e
No known key found for this signature in database
7 changed files with 36 additions and 46 deletions

View file

@ -8,9 +8,17 @@ The list of generated files are:
- [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.
`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.

View file

@ -9,12 +9,20 @@
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.
`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.
'';
};

View file

@ -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 { })
];

View file

@ -1,10 +1,15 @@
let
testCfg = {
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; };
};
in
{
@ -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;
};
};

View file

@ -9,5 +9,5 @@ let
in
{
imports = [ hm.flakeModules.home-manager ];
flake.modules.nixos.common = globalCfg;
flake.modules.nixos.default = globalCfg;
}

View file

@ -1,7 +0,0 @@
{
flake.modules.nixos.networking =
{ hostName, ... }:
{
networking = { inherit hostName; };
};
}

View file

@ -1,9 +0,0 @@
{
flake.profiles.nixos.common =
{ hostName, ... }:
{
boot.loader.systemd-boot.enable = true;
system.stateVersion = "25.05";
networking = { inherit hostName; };
};
}