dotfiles/modules/systems.nix
Magic_RB 634dafdf5a
Attempt to make evaluation of hydraJobs not OOM...
Signed-off-by: Magic_RB <magic_rb@redalder.org>
2023-04-03 18:45:12 +02:00

85 lines
2 KiB
Nix

# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
{
inputs,
lib,
withSystem,
self,
roots,
config,
...
}:
let
inherit (lib)
isFunction
isPath
isString
typeOf
mapAttrsToList
id
const
filterAttrs
hasSuffix
foldr
mergeAttrs
mapAttrs
seq
deepSeq
;
seqVal = v: seq v v;
deepSeqVal = v: deepSeq v v;
mkNixos = {
system,
name,
}: module: let
module' =
if isFunction module
then module
else if isPath module || isString module
then import module
else throw "Expected `function`, `path` or `string`, but got `${typeOf module}`";
in
withSystem system
({pkgs, ...}:
inputs.nixpkgs.lib.nixosSystem
{
inherit system;
specialArgs = {
inherit self inputs roots;
config' = config;
};
modules = [
module'
({config, ...}: {
networking.hostName = name;
nixpkgs.overlays = mapAttrsToList (const id) self.overlays;
nixpkgs.pkgs = import inputs.nixpkgs {
inherit system;
inherit (config.nixpkgs) overlays config;
};
})
];
});
eachNixosSystem = path: let
all = builtins.readDir path;
filtered = filterAttrs (n: v: hasSuffix ".nix" n || v == "directory" ) all;
systemFiles = mapAttrsToList (n: _: n) filtered;
systems = map (file: import "${path}/${file}") systemFiles;
systemConfigurations =
map
(
system: {
${system.name} = mkNixos {inherit (system) name system;} system.module;
}
)
systems;
in
foldr mergeAttrs {} systemConfigurations;
in {
flake.nixosConfigurations = eachNixosSystem (roots.nixos + "/systems");
flake.hydraJobs = deepSeqVal mapAttrs (n: v: seqVal v.config.system.build.toplevel) (eachNixosSystem (roots.nixos + "/systems"));
}