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.
This commit is contained in:
Gabriel Arazas 2023-12-25 19:54:54 +08:00
parent 3fa45623ed
commit a29b1ee5e0
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
2 changed files with 23 additions and 20 deletions

View File

@ -82,6 +82,7 @@
# purposes. The format used here is whatever formats nixos-generators # purposes. The format used here is whatever formats nixos-generators
# support. # support.
images = import ./setups/nixos.nix { inherit lib inputs; }; images = import ./setups/nixos.nix { inherit lib inputs; };
images' = listImagesWithSystems images;
# A set of users with their metadata to be deployed with home-manager. # A set of users with their metadata to be deployed with home-manager.
users = import ./setups/home-manager.nix { inherit lib inputs; }; 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 # A list of NixOS configurations from the `./hosts` folder. It also has
# some sensible default configurations. # some sensible default configurations.
nixosConfigurations = nixosConfigurations = let
validImages = lib.filterAttrs (name: metadata:
metadata.format == null || metadata ? deploy) images;
in
lib.mapAttrs lib.mapAttrs
(host: metadata: (host: metadata:
mkHost { mkHost {
extraModules = [ (hostSpecificModule host metadata) ]; extraModules = [ (hostSpecificModule host metadata) ];
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs"; nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs";
}) })
(listImagesWithSystems images); (listImagesWithSystems validImages);
# We're going to make our custom modules available for our flake. Whether # 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. # 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 # This contains images that are meant to be built and distributed
# somewhere else including those NixOS configurations that are built as # somewhere else including those NixOS configurations that are built as
# an ISO. # an ISO.
images = images = forAllSystems (system: let
forAllSystems (system: validImages = lib.filterAttrs (host: metadata:
system == metadata._system && metadata.format != null) images';
in
lib.mapAttrs'
(host: metadata:
let 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 in
lib.mapAttrs' lib.nameValuePair name (mkImage {
(host: metadata: inherit nixpkgs-channel format;
let extraModules = [ (hostSpecificModule host metadata) ];
name = metadata._name; }))
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs"; validImages);
format = metadata.format or "iso";
in
lib.nameValuePair name (mkImage {
inherit nixpkgs-channel format;
extraModules = [ (hostSpecificModule host metadata) ];
}))
images');
# My several development shells for usual type of projects. This is much # My several development shells for usual type of projects. This is much
# more preferable than installing all of the packages at the system # more preferable than installing all of the packages at the system

View File

@ -10,7 +10,7 @@
{ {
ni = { ni = {
systems = [ "x86_64-linux" ]; systems = [ "x86_64-linux" ];
format = "iso"; format = null;
modules = [ modules = [
inputs.nur.nixosModules.nur inputs.nur.nixosModules.nur
inputs.nix-index-database.nixosModules.nix-index inputs.nix-index-database.nixosModules.nix-index
@ -35,7 +35,7 @@
plover = { plover = {
systems = [ "x86_64-linux" ]; systems = [ "x86_64-linux" ];
format = "iso"; format = null;
domain = "foodogsquared.one"; domain = "foodogsquared.one";
deploy = { deploy = {
hostname = "plover.foodogsquared.one"; hostname = "plover.foodogsquared.one";
@ -62,7 +62,7 @@
winnowing = { winnowing = {
systems = [ "x86_64-linux" ]; systems = [ "x86_64-linux" ];
format = "iso"; format = null;
modules = [ modules = [
inputs.nixos-wsl.nixosModules.default inputs.nixos-wsl.nixosModules.default
]; ];