You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nixos-template-base/lib.nix

51 lines
1.4 KiB
Nix

let
lib = with import <nixpkgs> {}; pkgs.lib;
profiles = {
isDesktopEnvironment = {
awesome = true;
internetSuite = true;
graphical = true;
multimediaSuite = true;
officeSuite = true;
pulseaudio = true;
securitySuite = true;
};
isWorkstation = {
docker = true;
developpement = true;
developpement-elm = true;
developpement-haskell = true;
developpement-java = true;
developpement-rust = true;
};
#isServer = {
#};
};
in
with lib; rec{
# Apply the profiles (pre-defined + custom) to the whole directory
applyProfilesToDirectory = customProfiles: directory:
lib.mapAttrs (applyProfilesToMachine customProfiles) directory;
# Apply the profiles (pre-defined + custom) to a machine
applyProfilesToMachine = customProfiles: machineName: machineOptions:
{ configurationFlags = lib.recursiveUpdate (generateFlagsSet customProfiles machineOptions.profiles) machineOptions.configurationFlags;
configurationOptions = machineOptions.configurationOptions;
profiles = machineOptions.profiles;
};
# Generate a set of configuration flags based on profiles
generateFlagsSet = customProfiles: machineProfiles:
let
allProfiles = recursiveUpdate profiles customProfiles;
conditionalFlags = name: value:
if machineProfiles.${name}
then value
else {};
in
foldr (a: b: a // b) {} (mapAttrsToList conditionalFlags allProfiles);
}