2023-09-02 16:26:45 +00:00
|
|
|
{ nixpkgs, self, lib }:
|
2023-08-29 13:00:03 +00:00
|
|
|
{ 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
|
2023-09-03 13:18:29 +00:00
|
|
|
machinesDirs = lib.optionalAttrs (builtins.pathExists "${directory}/machines") (builtins.readDir (directory + /machines));
|
2023-08-29 13:00:03 +00:00
|
|
|
|
|
|
|
machineSettings = machineName:
|
2023-10-24 17:40:48 +00:00
|
|
|
if builtins.getEnv "CLAN_MACHINE_SETTINGS_FILE" != ""
|
|
|
|
then builtins.fromJSON (builtins.readFile (builtins.getEnv "CLAN_MACHINE_SETTINGS_FILE"))
|
|
|
|
else
|
|
|
|
lib.optionalAttrs (builtins.pathExists "${directory}/machines/${machineName}/settings.json")
|
|
|
|
(builtins.fromJSON
|
|
|
|
(builtins.readFile (directory + /machines/${machineName}/settings.json)));
|
2023-08-29 13:00:03 +00:00
|
|
|
|
2023-09-28 12:13:23 +00:00
|
|
|
# TODO: remove default system once we have a hardware-config mechanism
|
2023-09-20 16:08:47 +00:00
|
|
|
nixosConfiguration = { system ? "x86_64-linux", name }: nixpkgs.lib.nixosSystem {
|
|
|
|
modules = [
|
|
|
|
self.nixosModules.clanCore
|
|
|
|
(machineSettings name)
|
|
|
|
(machines.${name} or { })
|
|
|
|
{
|
|
|
|
clanCore.machineName = name;
|
|
|
|
clanCore.clanDir = directory;
|
2023-09-28 12:13:23 +00:00
|
|
|
nixpkgs.hostPlatform = lib.mkForce system;
|
2023-09-20 16:08:47 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
inherit specialArgs;
|
|
|
|
};
|
|
|
|
|
2023-09-27 15:25:17 +00:00
|
|
|
allMachines = machinesDirs // machines;
|
2023-09-20 16:08:47 +00:00
|
|
|
|
2023-09-27 15:25:17 +00:00
|
|
|
supportedSystems = [
|
2023-09-20 16:08:47 +00:00
|
|
|
"x86_64-linux"
|
|
|
|
"aarch64-linux"
|
|
|
|
"riscv64-linux"
|
|
|
|
"x86_64-darwin"
|
|
|
|
"aarch64-darwin"
|
|
|
|
];
|
|
|
|
|
2023-09-27 15:25:17 +00:00
|
|
|
nixosConfigurations = lib.mapAttrs (name: _: nixosConfiguration { inherit name; }) allMachines;
|
|
|
|
|
|
|
|
# This instantiates nixos for each system that we support:
|
2023-09-27 15:25:17 +00:00
|
|
|
# configPerSystem = <system>.<machine>.nixosConfiguration
|
2023-09-27 15:25:17 +00:00
|
|
|
# We need this to build nixos secret generators for each system
|
2023-09-28 12:13:23 +00:00
|
|
|
configsPerSystem = builtins.listToAttrs
|
2023-09-27 15:25:17 +00:00
|
|
|
(builtins.map
|
|
|
|
(system: lib.nameValuePair system
|
|
|
|
(lib.mapAttrs (name: _: nixosConfiguration { inherit name system; }) allMachines))
|
|
|
|
supportedSystems);
|
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit nixosConfigurations;
|
|
|
|
|
2023-09-20 16:08:47 +00:00
|
|
|
clanInternals = {
|
2023-09-29 09:56:02 +00:00
|
|
|
machines = configsPerSystem;
|
2023-10-04 06:27:00 +00:00
|
|
|
all-machines-json = lib.mapAttrs
|
|
|
|
(system: configs: nixpkgs.legacyPackages.${system}.writers.writeJSON "machines.json" (lib.mapAttrs (_: m: m.config.system.clan.deployment.data) configs))
|
|
|
|
configsPerSystem;
|
2023-09-20 16:08:47 +00:00
|
|
|
};
|
2023-09-27 15:25:17 +00:00
|
|
|
}
|