From 397d6ab765b57a78bb8e5b3c26d56c80e8eab796 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Sun, 5 Nov 2023 20:11:51 +0100 Subject: [PATCH] initial support for multiple servers --- configuration.nix | 8 +++- flake.nix | 38 +++++++++++++------ .../jefke.nix | 0 3 files changed, 32 insertions(+), 14 deletions(-) rename hardware-configuration.nix => hardware-configuration/jefke.nix (100%) diff --git a/configuration.nix b/configuration.nix index e99ad9d..9247800 100644 --- a/configuration.nix +++ b/configuration.nix @@ -1,6 +1,10 @@ -{pkgs, ...}: { +{ + pkgs, + server, + ... +}: { imports = [ - ./hardware-configuration.nix + server.hardware-configuration ]; boot.loader = { diff --git a/flake.nix b/flake.nix index 86c591c..301d2cd 100644 --- a/flake.nix +++ b/flake.nix @@ -5,18 +5,32 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; }; - outputs = { - self, - nixpkgs, - ... - } @ attrs: { - formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.alejandra; - nixosConfigurations.jefke = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - specialArgs = attrs; - modules = [ - ./configuration.nix - ]; + outputs = {nixpkgs, ...}: let + servers = { + jefke = { + hardware-configuration = import ./hardware-configuration/jefke.nix; + system-arch = "x86_64-linux"; + }; }; + serverNames = builtins.attrNames servers; + serverWithNameAttr = name: (builtins.getAttr name servers) // {name = name;}; + + genNixosConfigurations = config: + nixpkgs.lib.genAttrs serverNames ( + serverName: + nixpkgs.lib.nixosSystem (config (serverWithNameAttr serverName)) + ); + in { + formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.alejandra; + + nixosConfigurations = genNixosConfigurations ( + server: { + system = server.system-arch; + specialArgs = {inherit server;}; + modules = [ + ./configuration.nix + ]; + } + ); }; } diff --git a/hardware-configuration.nix b/hardware-configuration/jefke.nix similarity index 100% rename from hardware-configuration.nix rename to hardware-configuration/jefke.nix