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
# 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

View File

@ -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
];