clan-core/lib/build-clan/default.nix

33 lines
1.2 KiB
Nix
Raw Normal View History

{ nixpkgs, self, lib }:
{ directory # The directory containing the machines subdirectory
, specialArgs ? { } # Extra arguments to pass to nixosSystem i.e. useful to make self available
, machines ? { } # allows to include machine-specific modules i.e. machines.${name} = { ... }
}:
let
machinesDirs = lib.optionalAttrs (builtins.pathExists "${directory}/machines") (builtins.readDir (directory + /machines));
machineSettings = machineName:
lib.optionalAttrs (builtins.pathExists "${directory}/machines/${machineName}/settings.json")
builtins.fromJSON
(builtins.readFile (directory + /machines/${machineName}/settings.json));
nixosConfigurations = lib.mapAttrs
(name: _:
nixpkgs.lib.nixosSystem {
modules = [
self.nixosModules.clanCore
(machineSettings name)
(machines.${name} or { })
2023-09-03 11:09:35 +00:00
{
clanCore.machineName = name;
clanCore.clanDir = directory;
2023-09-03 11:09:35 +00:00
# TODO: remove this once we have a hardware-config mechanism
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
}
2023-08-29 20:29:32 +00:00
];
2023-09-03 11:09:35 +00:00
inherit specialArgs;
})
(machinesDirs // machines);
in
nixosConfigurations