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-10 06:20:44 +01:00
|
|
|
{ config, lib, flakelight, moduleArgs, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
2023-10-24 05:21:36 +02:00
|
|
|
inherit (builtins) isAttrs mapAttrs;
|
2023-08-25 06:14:55 +02:00
|
|
|
inherit (lib) foldl mapAttrsToList mergeOneOption mkIf mkOption mkOptionType
|
|
|
|
recursiveUpdate;
|
|
|
|
inherit (lib.types) lazyAttrsOf;
|
2023-10-24 05:21:36 +02:00
|
|
|
inherit (flakelight.types) optFunctionTo;
|
2023-08-25 06:14:55 +02:00
|
|
|
|
|
|
|
nixosConfiguration = mkOptionType {
|
|
|
|
name = "nixosConfiguration";
|
|
|
|
description = "nixosConfiguration";
|
|
|
|
descriptionClass = "noun";
|
|
|
|
check = x: isAttrs x
|
|
|
|
&& x ? config.nixpkgs.system
|
|
|
|
&& x ? config.system.build.toplevel;
|
|
|
|
merge = mergeOneOption;
|
|
|
|
};
|
2023-12-05 09:12:04 +01:00
|
|
|
|
2024-01-10 06:20:44 +01:00
|
|
|
configs = mapAttrs (_: f: f moduleArgs) config.nixosConfigurations;
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.nixosConfigurations = mkOption {
|
2023-10-24 05:21:36 +02:00
|
|
|
type = lazyAttrsOf (optFunctionTo nixosConfiguration);
|
2023-08-25 06:14:55 +02:00
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
config.outputs = mkIf (config.nixosConfigurations != { }) {
|
2023-12-05 09:12:04 +01:00
|
|
|
nixosConfigurations = configs;
|
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
|
|
|
})
|
2023-12-05 09:12:04 +01:00
|
|
|
configs);
|
2023-08-25 06:14:55 +02:00
|
|
|
};
|
|
|
|
}
|