From 8331aa846fdb96f15c03f35faa3720919541c3cb Mon Sep 17 00:00:00 2001 From: transcaffeine Date: Wed, 2 Apr 2025 20:12:28 +0200 Subject: [PATCH] feat: switch to automatic nixosConfiguration population --- flake.lock | 34 ++++++++++++++++++++++++++++++++++ flake.nix | 13 +++++-------- hosts/default.nix | 20 ++++++++++++++++++++ 3 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 hosts/default.nix diff --git a/flake.lock b/flake.lock index 005d94f..ea82eb6 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,23 @@ { "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": { "locked": { "lastModified": 1743420942, @@ -32,8 +50,24 @@ "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": { "inputs": { + "flake-parts": "flake-parts", "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs" } diff --git a/flake.nix b/flake.nix index d79b5a0..432eb45 100644 --- a/flake.nix +++ b/flake.nix @@ -2,16 +2,13 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; nixos-hardware.url = "github:NixOS/nixos-hardware/master"; + flake-parts.url = "github:hercules-ci/flake-parts"; }; - outputs = inputs @ { self, nixpkgs, ... }: { - nixosConfigurations.backstage = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ./hosts/backstage - ]; - specialArgs = { inherit inputs; }; - }; + outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + ./hosts + ]; }; } diff --git a/hosts/default.nix b/hosts/default.nix new file mode 100644 index 0000000..72d9e0b --- /dev/null +++ b/hosts/default.nix @@ -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: { + imports = [ + (./. + "/${name}") + ]; + }); +in +{ + nixosConfigurations = lib.mapAttrs (host: hostConfig: lib.nixosSystem { + system = "x86_64-linux"; + modules = hostConfig; + specialArgs = { inherit inputs; }; + }) hosts; +}