From a29b1ee5e0c59db135723fe08159aa7554a54c0e Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Mon, 25 Dec 2023 19:54:54 +0800 Subject: [PATCH] flake.nix: filter NixOS config as images and deployments Though there are systems that can be used for both. For now, we'll use the deploy key as a surefire attribute that it is used for deployment while having an intended output image format. The best solution is simply have a conditional config for certain output formats. --- flake.nix | 37 ++++++++++++++++++++----------------- setups/nixos.nix | 6 +++--- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index 949e3e3a..98070011 100644 --- a/flake.nix +++ b/flake.nix @@ -82,6 +82,7 @@ # purposes. The format used here is whatever formats nixos-generators # support. images = import ./setups/nixos.nix { inherit lib inputs; }; + images' = listImagesWithSystems images; # A set of users with their metadata to be deployed with home-manager. users = import ./setups/home-manager.nix { inherit lib inputs; }; @@ -370,14 +371,17 @@ # A list of NixOS configurations from the `./hosts` folder. It also has # some sensible default configurations. - nixosConfigurations = + nixosConfigurations = let + validImages = lib.filterAttrs (name: metadata: + metadata.format == null || metadata ? deploy) images; + in lib.mapAttrs (host: metadata: mkHost { extraModules = [ (hostSpecificModule host metadata) ]; nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs"; }) - (listImagesWithSystems images); + (listImagesWithSystems validImages); # We're going to make our custom modules available for our flake. Whether # or not this is a good thing is debatable, I just want to test it. @@ -419,23 +423,22 @@ # This contains images that are meant to be built and distributed # somewhere else including those NixOS configurations that are built as # an ISO. - images = - forAllSystems (system: + images = forAllSystems (system: let + validImages = lib.filterAttrs (host: metadata: + system == metadata._system && metadata.format != null) images'; + in + lib.mapAttrs' + (host: metadata: let - images' = lib.filterAttrs (host: metadata: (system == metadata._system) && (metadata.format != null)) (listImagesWithSystems images); + name = metadata._name; + nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs"; + format = metadata.format or "iso"; in - lib.mapAttrs' - (host: metadata: - let - name = metadata._name; - nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs"; - format = metadata.format or "iso"; - in - lib.nameValuePair name (mkImage { - inherit nixpkgs-channel format; - extraModules = [ (hostSpecificModule host metadata) ]; - })) - images'); + lib.nameValuePair name (mkImage { + inherit nixpkgs-channel format; + extraModules = [ (hostSpecificModule host metadata) ]; + })) + validImages); # My several development shells for usual type of projects. This is much # more preferable than installing all of the packages at the system diff --git a/setups/nixos.nix b/setups/nixos.nix index 965c0a50..467f38f2 100644 --- a/setups/nixos.nix +++ b/setups/nixos.nix @@ -10,7 +10,7 @@ { ni = { systems = [ "x86_64-linux" ]; - format = "iso"; + format = null; modules = [ inputs.nur.nixosModules.nur inputs.nix-index-database.nixosModules.nix-index @@ -35,7 +35,7 @@ plover = { systems = [ "x86_64-linux" ]; - format = "iso"; + format = null; domain = "foodogsquared.one"; deploy = { hostname = "plover.foodogsquared.one"; @@ -62,7 +62,7 @@ winnowing = { systems = [ "x86_64-linux" ]; - format = "iso"; + format = null; modules = [ inputs.nixos-wsl.nixosModules.default ];