2023-08-27 07:48:57 +02:00
|
|
|
# flakelight -- Framework for simplifying flake setup
|
2023-08-25 06:14:55 +02:00
|
|
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2024-01-14 10:29:16 +01:00
|
|
|
{ config, lib, inputs, flakelight, moduleArgs, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
2024-01-14 10:29:16 +01:00
|
|
|
inherit (builtins) concatLists mapAttrs;
|
|
|
|
inherit (lib) foldl last mapAttrsToList mkIf mkOption recursiveUpdate
|
|
|
|
zipAttrsWith;
|
|
|
|
inherit (lib.types) attrs lazyAttrsOf;
|
2023-10-24 05:21:36 +02:00
|
|
|
inherit (flakelight.types) optFunctionTo;
|
2023-08-25 06:14:55 +02:00
|
|
|
|
2024-01-14 10:29:16 +01:00
|
|
|
# Avoid checking if toplevel is a derivation as it causes the nixos modules
|
|
|
|
# to be evaluated.
|
|
|
|
isNixos = x: x ? config.system.build.toplevel;
|
|
|
|
|
|
|
|
mergeCfg = zipAttrsWith (n: vs:
|
|
|
|
if n == "specialArgs" then
|
|
|
|
foldl (a: b: a // b) { } vs
|
|
|
|
else if n == "modules" then
|
|
|
|
concatLists vs
|
|
|
|
else last vs);
|
|
|
|
|
|
|
|
mkSystem = hostname: cfg:
|
|
|
|
let
|
|
|
|
inherit (cfg) system;
|
|
|
|
in
|
|
|
|
inputs.nixpkgs.lib.nixosSystem (mergeCfg [
|
|
|
|
{
|
|
|
|
specialArgs = {
|
|
|
|
inherit inputs hostname;
|
|
|
|
inputs' = mapAttrs (_: mapAttrs (_: v: v.${system} or { })) inputs;
|
|
|
|
};
|
|
|
|
modules = [ config.propagationModule ];
|
|
|
|
}
|
|
|
|
cfg
|
|
|
|
]);
|
2023-12-05 09:12:04 +01:00
|
|
|
|
2024-01-14 10:29:16 +01:00
|
|
|
systems = mapAttrs
|
|
|
|
(hostname: f:
|
|
|
|
let val = f moduleArgs; in
|
|
|
|
if isNixos val then val else mkSystem hostname val)
|
|
|
|
config.nixosConfigurations;
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.nixosConfigurations = mkOption {
|
2024-01-14 10:29:16 +01:00
|
|
|
type = lazyAttrsOf (optFunctionTo attrs);
|
2023-08-25 06:14:55 +02:00
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
config.outputs = mkIf (config.nixosConfigurations != { }) {
|
2024-01-14 10:29:16 +01:00
|
|
|
nixosConfigurations = systems;
|
2023-08-25 06:14:55 +02:00
|
|
|
checks = foldl recursiveUpdate { } (mapAttrsToList
|
|
|
|
(n: v: {
|
2023-12-05 09:38:45 +01:00
|
|
|
${v.config.nixpkgs.system}."nixos-${n}" = v.pkgs.runCommand
|
|
|
|
"check-nixos-${n}"
|
|
|
|
{ } "echo ${v.config.system.build.toplevel} > $out";
|
2023-08-25 06:14:55 +02:00
|
|
|
})
|
2024-01-14 10:29:16 +01:00
|
|
|
systems);
|
2023-08-25 06:14:55 +02:00
|
|
|
};
|
|
|
|
}
|