feat: use flake-parts and auto-generate nixosConfigurations for all hosts

This commit is contained in:
transcaffeine 2025-04-02 20:12:28 +02:00
parent 4c89c45e3e
commit e9a7e56e02
Signed by: transcaffeine
GPG Key ID: 03624C433676E465
3 changed files with 62 additions and 8 deletions

View File

@ -1,5 +1,23 @@
{ {
"nodes": { "nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1743550720,
"narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "c621e8422220273271f52058f618c94e405bb0f5",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixos-hardware": { "nixos-hardware": {
"locked": { "locked": {
"lastModified": 1743420942, "lastModified": 1743420942,
@ -32,8 +50,24 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-lib": {
"locked": {
"lastModified": 1743296961,
"narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts",
"nixos-hardware": "nixos-hardware", "nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }

View File

@ -2,16 +2,16 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
nixos-hardware.url = "github:NixOS/nixos-hardware/master"; nixos-hardware.url = "github:NixOS/nixos-hardware/master";
flake-parts.url = "github:hercules-ci/flake-parts";
}; };
outputs = inputs @ { self, nixpkgs, ... }: { outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
nixosConfigurations.backstage = nixpkgs.lib.nixosSystem { systems = [
system = "x86_64-linux"; "x86_64-linux"
modules = [ ];
./hosts/backstage imports = [
]; ./hosts
specialArgs = { inherit inputs; }; ];
};
}; };
} }

20
hosts/default.nix Normal file
View File

@ -0,0 +1,20 @@
{inputs, self, ...}:
let
inherit (inputs.nixpkgs) lib;
isDirectory = _name: type: type == "directory";
hostNames = builtins.attrNames (
lib.filterAttrs isDirectory (builtins.readDir ./.)
);
hosts = lib.genAttrs hostNames (name: {
modules = [
(./. + "/${name}")
];
});
in
{
flake.nixosConfigurations = lib.mapAttrs (host: hostConfig: lib.nixosSystem {
inherit (hostConfig) modules;
system = "x86_64-linux";
specialArgs = { inherit inputs; };
}) hosts;
}