From 5402eeffc6e3fae5bfaa57e1d9fab8c723fa048e Mon Sep 17 00:00:00 2001 From: Frede Braendstrup Date: Sat, 23 Mar 2024 11:14:00 +0100 Subject: [PATCH] nix: make system configurations dynamic --- {systems => common}/base.nix | 0 {systems => common}/desktop.nix | 0 flake.nix | 31 ++++++++++++------------------- systems/dt.nix | 1 + systems/ideapad.nix | 1 + systems/yoga.nix | 2 +- 6 files changed, 15 insertions(+), 20 deletions(-) rename {systems => common}/base.nix (100%) rename {systems => common}/desktop.nix (100%) diff --git a/systems/base.nix b/common/base.nix similarity index 100% rename from systems/base.nix rename to common/base.nix diff --git a/systems/desktop.nix b/common/desktop.nix similarity index 100% rename from systems/desktop.nix rename to common/desktop.nix diff --git a/flake.nix b/flake.nix index 21f1891..81040e9 100644 --- a/flake.nix +++ b/flake.nix @@ -16,26 +16,19 @@ let overlays = [ neovim-nightly-overlay.overlay ]; - base = [ { nixpkgs.overlays = overlays; } ./systems/base.nix ]; + base = [ { nixpkgs.overlays = overlays; } ./common/base.nix ]; + createSystem = (system-file: + let name = nixpkgs.lib.strings.removeSuffix ".nix" system-file; + in { + inherit name; + value = nixpkgs.lib.nixosSystem { + specialArgs = { inherit inputs; }; + modules = base ++ [ (./systems + "/${system-file}") ]; + }; + }); in { - nixosConfigurations = { - dt = nixpkgs.lib.nixosSystem { - specialArgs = { inherit inputs; }; - modules = base ++ [ ./systems/desktop.nix ./systems/dt.nix ]; - }; - yoga = nixpkgs.lib.nixosSystem { - specialArgs = { inherit inputs; }; - modules = base ++ [ ./systems/desktop.nix ./systems/yoga.nix ]; - }; - ideapad = nixpkgs.lib.nixosSystem { - specialArgs = { inherit inputs; }; - modules = base ++ [ ./systems/desktop.nix ./systems/ideapad.nix ]; - }; - server = nixpkgs.lib.nixosSystem { - specialArgs = { inherit inputs; }; - modules = base ++ [ ./systems/server.nix ./modules/ssh.nix ]; - }; - }; + nixosConfigurations = builtins.listToAttrs + (map createSystem (builtins.attrNames (builtins.readDir ./systems))); formatter."x86_64-linux" = nixpkgs.legacyPackages."x86_64-linux".nixfmt; }; diff --git a/systems/dt.nix b/systems/dt.nix index 700d830..31adf84 100644 --- a/systems/dt.nix +++ b/systems/dt.nix @@ -1,5 +1,6 @@ { config, lib, modulesPath, ... }: { imports = [ + ../common/desktop.nix ../modules/default-system-layout.nix (modulesPath + "/installer/scan/not-detected.nix") ]; diff --git a/systems/ideapad.nix b/systems/ideapad.nix index 1a7f157..5abafb8 100644 --- a/systems/ideapad.nix +++ b/systems/ideapad.nix @@ -1,5 +1,6 @@ { config, lib, modulesPath, ... }: { imports = [ + ../common/desktop.nix ../modules/default-system-layout.nix (modulesPath + "/installer/scan/not-detected.nix") ]; diff --git a/systems/yoga.nix b/systems/yoga.nix index 555e557..bd4938a 100644 --- a/systems/yoga.nix +++ b/systems/yoga.nix @@ -1,6 +1,6 @@ { config, lib, modulesPath, ... }: { - imports = [ + ../common/desktop.nix ../modules/default-system-layout.nix (modulesPath + "/installer/scan/not-detected.nix") ];