From 66aa9cd407fb7c8822c95478f69e235731c1bc3e Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 18 Aug 2022 21:55:47 +0200 Subject: [PATCH] refactor: extract machine setup --- flake.nix | 92 +++++++++++++++---------------------------------------- 1 file changed, 24 insertions(+), 68 deletions(-) diff --git a/flake.nix b/flake.nix index 7afdb8c..5ee2ab9 100644 --- a/flake.nix +++ b/flake.nix @@ -12,77 +12,33 @@ let user = "mandlm"; theme = "dark"; # dark or light + + buildMachineConfig = machineName: nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = inputs; + modules = [ + ./configuration.nix + ./users.nix + ./machines/${machineName}/configuration.nix + ./machines/${machineName}/hardware-configuration.nix + + home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { inherit user theme; }; + home-manager.users.${user} = { + imports = [ ./home-${user}.nix ]; + }; + } + ]; + }; in { nixosConfigurations = { - nixos-vm = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - specialArgs = inputs; - modules = [ - ./configuration.nix - ./users.nix - ./machines/nixos-vm/configuration.nix - ./machines/nixos-vm/hardware-configuration.nix - - home-manager.nixosModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { inherit user theme; }; - home-manager.users.${user} = { - imports = [ ./home-${user}.nix ]; - }; - } - ]; - }; - - apache = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - specialArgs = inputs; - modules = [ - ./configuration.nix - ./users.nix - ./machines/apache/configuration.nix - ./machines/apache/hardware-configuration.nix - - home-manager.nixosModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { inherit user theme; }; - home-manager.users.${user} = { - imports = [ - ./home-${user}.nix - ./machines/apache/home-${user}.nix - ]; - }; - } - ]; - }; - - p330 = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - specialArgs = inputs; - modules = [ - ./configuration.nix - ./users.nix - ./machines/p330/configuration.nix - ./machines/p330/hardware-configuration.nix - - home-manager.nixosModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { inherit user theme; }; - home-manager.users.${user} = { - imports = [ - ./home-${user}.nix - ./machines/p330/home-${user}.nix - ]; - }; - } - ]; - }; + nixos-vm = buildMachineConfig ("nixos-vm"); + apache = buildMachineConfig ("apache"); + p330 = buildMachineConfig ("p330"); }; }; }