Newer
Older
# entry point for machine configurations:
# (import <repo-path> { machinesDir=./machines }).<netname>.configurations.<hostname>
{ flakeInputs, flakeOutputs, machinesDir, extraLayersDir }:
#defaultChannel = loadChannel "nixos-unstable";
# helpers :: { *: ? }
helpers = import ./helpers.nix;
# channelsDir :: path
#channelsDir = ./channels;
#loadChannel = name: import (channelsDir + "/${name}") name;
#allChannels = with helpers; keysToAttrs loadChannel (readFilterDir (filterAnd [(not filterDirHidden) filterDirDirs]) channelsDir);
# getMachineChannel :: string -> path
getMachineChannel = _: flakeInputs.nixpkgs;
#getMachineChannel = { name, path }:
# let
# channelFile = path + "/channel.nix";
# in
# if (pathExists channelFile)
# then (import channelFile) allChannels
# else defaultChannel;
# machineChannels :: { *: path }
machineChannels = withMachines getMachineChannel;
machinesDirContents = readDir machinesDir;
machineNames = filter (p: machinesDirContents.${p} == "directory") (attrNames machinesDirContents);
withMachines = lambda: listToAttrs (map (m: {name = m; value = lambda { name = m; path = (machinesDir + "/${m}"); }; }) machineNames);
evaluateConfig = pkgs: args: (import "${pkgs}/nixos/lib/eval-config.nix" args).config;
mkNixosSystemDerivation = { name, path }:
let
system = "x86_64-linux";
mkMachineConfig = { name, path, isIso }: {
imports = [
(import ./configuration.nix {
inherit name path isIso extraLayersDir flakeInputs flakeOutputs system;
channel = machineChannels.${name};
})
];
_module.args.flakeInputs = flakeInputs;
_module.args.flakeOutputs = flakeOutputs;
_module.args.system = system;
};
configuration = mkMachineConfig { inherit name path; isIso = false; };
isoConfiguration = mkMachineConfig { inherit name path; isIso = true; };
iso = (evaluateConfig channel {
inherit system;
modules = [
isoConfiguration
(mkAdditionalIsoConfig name)
}).system.build.isoImage;
sdImage = (evaluateConfig channel {
inherit system;
modules = [
isoConfiguration
(mkAdditionalSdCardConfig name)
];
}).system.build.sdImage;
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
channel.lib.nixosSystem {
inherit system;
modules = [
configuration
{
system.build = {
inherit iso sdImage;
};
}
];
};
mkAdditionalIsoConfig = name: { config, modulesPath, ... }: {
imports = [
"${modulesPath}/installer/cd-dvd/iso-image.nix"
"${modulesPath}/profiles/all-hardware.nix"
"${modulesPath}/profiles/base.nix"
];
isoImage.isoName = "${config.isoImage.isoBaseName}-${config.system.nixos.label}-isohost-${name}.iso";
isoImage.volumeID = substring 0 11 "NIXOS_ISO";
isoImage.makeEfiBootable = true;
isoImage.makeUsbBootable = true;
boot.loader.grub.memtest86.enable = true;
_module.args.isIso = true;
};
mkAdditionalSdCardConfig = name: { config, modulesPath, ... }: {
imports = [
"${modulesPath}/installer/cd-dvd/sd-image.nix"
"${modulesPath}/profiles/all-hardware.nix"
"${modulesPath}/profiles/base.nix"
];
sdImage.populateRootCommands = "";
sdImage.populateFirmwareCommands = "";
boot.loader.grub.enable = false;
boot.loader.generic-extlinux-compatible.enable = true;
_module.args.isIso = true;
};
# TODO remove
# configurations = withMachines mkMachineConfig;
# nixosIsoDerivations = withMachines mkNixosIsoDerivation;
# channels = machineChannels;
nixosSystemDerivations = withMachines mkNixosSystemDerivation;
machineTemplates = withMachines ({name, path}: import (path + /template.nix));