From 92a4e3d3325b154da46a3a381712e39e537e7ffb Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 1 May 2024 18:58:39 +0200 Subject: [PATCH] Restructure the interna of the flake --- flake.nix | 49 ++++++++++++++++++++++++++++++------------- lib/configuration.nix | 25 ++++++++++++++++++++++ lib/system.nix | 40 ----------------------------------- 3 files changed, 59 insertions(+), 55 deletions(-) create mode 100644 lib/configuration.nix delete mode 100644 lib/system.nix diff --git a/flake.nix b/flake.nix index 60fedb6..38bd268 100644 --- a/flake.nix +++ b/flake.nix @@ -8,25 +8,12 @@ outputs = { self, nixpkgs, flake-utils }: let - system = import ./lib/system.nix { - inherit nixpkgs; - }; systems = [ { name = "nixos"; } ]; - in { - nixosConfigurations = builtins.listToAttrs - ( - builtins.map ( - { name, ... }@config: - { - inherit name; - value = system config; - }) - systems); - } // + in flake-utils.lib.eachDefaultSystem ( system: let @@ -39,5 +26,37 @@ nixos-rebuild ]; }); - }); + } + ) // + { + nixosConfigurations = builtins.listToAttrs + ( + builtins.map ( + { name, system ? "x86_64-linux", ... }@config: + { + inherit name; + + value = nixpkgs.lib.nixosSystem { + inherit system; + + modules = [ + ({ ... }: { config._module.args = { machineConfig = config; }; }) + ./lib/configuration.nix + + ( + let + configCandidate = ./lib/machines/${name}.nix; + machineConfigPath = + if builtins.pathExists configCandidate + then + configCandidate + else + ./lib/hardware/base.nix; + in + machineConfigPath) + ]; + }; + }) + systems); + }; } diff --git a/lib/configuration.nix b/lib/configuration.nix new file mode 100644 index 0000000..460868e --- /dev/null +++ b/lib/configuration.nix @@ -0,0 +1,25 @@ +{ machineConfig, ... }: { + imports = [ + ./modules/custom-build-vm.nix + ]; + + config = { + system.stateVersion = "23.11"; + + virtualisation = + let + vmConfig = { + virtualisation = { + sharedHostKeys = true; + virt-viewer = true; + }; + }; + in { + vmVariant = vmConfig; + vmVariantWithBootLoader = vmConfig; + }; + + # Networking + networking.hostName = machineConfig.name; + }; +} diff --git a/lib/system.nix b/lib/system.nix deleted file mode 100644 index 451dccc..0000000 --- a/lib/system.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ nixpkgs }: - { name, dualBoot ? false } : - let - lib = nixpkgs.lib; - configPath = ./machines/${name}.nix; - machineConfig = - if builtins.pathExists configPath then - configPath - else - ./hardware/base.nix; - in lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ( - { config, pkgs, lib, ... }: { - imports = [ - machineConfig - ./modules/custom-build-vm.nix - ]; - - system.stateVersion = "23.11"; - - virtualisation = - let - vmConfig = { - virtualisation = { - sharedHostKeys = true; - virt-viewer = true; - }; - }; - in { - vmVariant = vmConfig; - vmVariantWithBootLoader = vmConfig; - }; - - # Networking - networking.hostName = name; - }) - ]; - }