mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-02-07 06:19:00 +00:00
flake.nix: add images
flake output
This commit is contained in:
parent
e4ad727c56
commit
b06a06888f
@ -10,6 +10,8 @@
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (import ../../lib/extras/flake-helpers.nix { inherit lib inputs; }) mkHost mkImage listImagesWithSystems;
|
||||
|
||||
nixosConfigs = import ../../setups/nixos.nix { inherit lib inputs; };
|
||||
|
||||
# A function that generates a NixOS module setting up the baseline
|
||||
@ -138,9 +140,6 @@ in
|
||||
# A list of NixOS configurations from the `./configs/nixos` folder starting
|
||||
# from project root. It also has some sensible default configurations.
|
||||
nixosConfigurations =
|
||||
let
|
||||
inherit (import ../../lib/extras/flake-helpers.nix { inherit lib inputs; }) mkHost listImagesWithSystems;
|
||||
in
|
||||
lib.mapAttrs
|
||||
(user: metadata:
|
||||
mkHost {
|
||||
@ -174,6 +173,39 @@ in
|
||||
inputs.self.nixosConfigurations;
|
||||
};
|
||||
|
||||
perSystem = { system, lib, ... }: {
|
||||
# This contains images that are meant to be built and distributed
|
||||
# somewhere else including those NixOS configurations that are built as
|
||||
# an ISO.
|
||||
images =
|
||||
let
|
||||
validImages = lib.filterAttrs
|
||||
(host: metadata:
|
||||
metadata.format != null && (lib.elem system metadata.systems))
|
||||
nixosConfigs;
|
||||
in
|
||||
lib.mapAttrs'
|
||||
(host: metadata:
|
||||
let
|
||||
name = metadata.hostname or host;
|
||||
nixpkgs-channel = metadata.nixpkgs-channel or "nixpkgs";
|
||||
in
|
||||
lib.nameValuePair name (mkImage {
|
||||
inherit (metadata) format;
|
||||
inherit nixpkgs-channel;
|
||||
extraModules = [
|
||||
(hostSpecificModule host metadata)
|
||||
|
||||
# Forcing the host platform set by the host (if there's any).
|
||||
# Ideally, there shouldn't be.
|
||||
({ lib, ... }: {
|
||||
nixpkgs.hostPlatform = lib.mkForce system;
|
||||
})
|
||||
];
|
||||
}))
|
||||
validImages;
|
||||
};
|
||||
|
||||
_module.args = {
|
||||
inherit defaultNixOSConfig nixosConfigs;
|
||||
};
|
||||
|
@ -92,6 +92,7 @@
|
||||
];
|
||||
|
||||
imports = [
|
||||
./modules/flake-parts
|
||||
./configs/flake-parts
|
||||
];
|
||||
};
|
||||
|
11
modules/flake-parts/default.nix
Normal file
11
modules/flake-parts/default.nix
Normal file
@ -0,0 +1,11 @@
|
||||
# Unlike other custom modules such as from NixOS and home-manager, all
|
||||
# flake-part modules are considered internal so there's no need for an internal
|
||||
# flag. We can just import these directly. Nobody should be using this except
|
||||
# this project (and also my other projects).
|
||||
{ lib, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
./images.nix
|
||||
];
|
||||
}
|
53
modules/flake-parts/images.nix
Normal file
53
modules/flake-parts/images.nix
Normal file
@ -0,0 +1,53 @@
|
||||
# A custom flake-parts module to configure my NixOS images generated with
|
||||
# nixos-generators. For more details, see the "Declarative hosts management"
|
||||
# section from the documentation.
|
||||
{ config, lib, flake-parts-lib, ... }:
|
||||
|
||||
let
|
||||
inherit (flake-parts-lib) mkSubmoduleOptions mkPerSystemOption;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
flake = mkSubmoduleOptions {
|
||||
images = lib.mkOption {
|
||||
type = with lib.types; lazyAttrsOf (attrsOf package);
|
||||
default = { };
|
||||
description = ''
|
||||
An attribute set of per-system NixOS configurations built as an image
|
||||
output supported by
|
||||
[nixos-generators](https://github.com/nix-community/nixos-generators).
|
||||
This is exclusively used for foodogsquared's NixOS setup.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
perSystem = mkPerSystemOption {
|
||||
options = {
|
||||
images = lib.mkOption {
|
||||
type = with lib.types; attrsOf package;
|
||||
default = {};
|
||||
description = ''
|
||||
An attribute set of NixOS configurations built as an image output
|
||||
supported by
|
||||
[nixos-generators](https://github.com/nix-community/nixos-generators).
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
flake.images =
|
||||
lib.mapAttrs
|
||||
(k: v: v.images)
|
||||
(lib.filterAttrs
|
||||
(k: v: v.images != {})
|
||||
config.allSystems
|
||||
);
|
||||
|
||||
perInput = system: flake:
|
||||
lib.optionalAttrs (flake ? images.${system}) {
|
||||
images = flake.images.${system};
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user