mirror of
https://github.com/nix-community/flakelight.git
synced 2024-11-22 15:33:10 +01:00
4e9f53ff4e
This removes the manual configuration of which options are auto-loaded. Now all options are eligible except for "nixDir" and "_module" as those would cause inf recursions. Additionally, instead of setting name aliases in the nixDir module, a config option is added, enabling other modules to extend the aliases lists.
51 lines
1.7 KiB
Nix
51 lines
1.7 KiB
Nix
# flakelight -- Framework for simplifying flake setup
|
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
{ config, lib, inputs, flakelight, moduleArgs, ... }:
|
|
let
|
|
inherit (builtins) mapAttrs;
|
|
inherit (lib) foldl mapAttrsToList mkIf mkOption recursiveUpdate;
|
|
inherit (lib.types) attrs lazyAttrsOf;
|
|
inherit (flakelight) selectAttr;
|
|
inherit (flakelight.types) optCallWith;
|
|
|
|
# Avoid checking if toplevel is a derivation as it causes the nixos modules
|
|
# to be evaluated.
|
|
isNixos = x: x ? config.system.build.toplevel;
|
|
|
|
mkNixos = hostname: cfg: inputs.nixpkgs.lib.nixosSystem (cfg // {
|
|
specialArgs = {
|
|
inherit inputs hostname;
|
|
inputs' = mapAttrs (_: selectAttr cfg.system) inputs;
|
|
} // cfg.specialArgs or { };
|
|
modules = [ config.propagationModule ] ++ cfg.modules or [ ];
|
|
});
|
|
|
|
configs = mapAttrs
|
|
(hostname: cfg: if isNixos cfg then cfg else mkNixos hostname cfg)
|
|
config.nixosConfigurations;
|
|
in
|
|
{
|
|
options.nixosConfigurations = mkOption {
|
|
type = optCallWith moduleArgs (lazyAttrsOf (optCallWith moduleArgs attrs));
|
|
default = { };
|
|
};
|
|
|
|
config = {
|
|
outputs = mkIf (config.nixosConfigurations != { }) {
|
|
nixosConfigurations = configs;
|
|
checks = foldl recursiveUpdate { } (mapAttrsToList
|
|
(n: v: {
|
|
# Wrapping the drv is needed as computing its name is expensive
|
|
# If not wrapped, it slows down `nix flake show` significantly
|
|
${v.config.nixpkgs.system}."nixos-${n}" = v.pkgs.runCommand
|
|
"check-nixos-${n}"
|
|
{ } "echo ${v.config.system.build.toplevel} > $out";
|
|
})
|
|
configs);
|
|
};
|
|
nixDirAliases.nixosConfigurations = [ "nixos" ];
|
|
};
|
|
}
|