specialisation: replace nesting with named configurations
Co-authored-by: worldofpeace <worldofpeace@protonmail.ch>
This commit is contained in:
co-authored by
worldofpeace
parent
807ca93fad
commit
ec2d28e323
@@ -4,6 +4,5 @@ with lib;
|
||||
|
||||
{
|
||||
boot.loader.grub.device = mkOverride 0 "nodev";
|
||||
nesting.children = mkOverride 0 [];
|
||||
nesting.clone = mkOverride 0 [];
|
||||
specialisation = mkOverride 0 {};
|
||||
}
|
||||
|
||||
@@ -11,21 +11,16 @@ let
|
||||
# you can provide an easy way to boot the same configuration
|
||||
# as you use, but with another kernel
|
||||
# !!! fix this
|
||||
cloner = inheritParent: list:
|
||||
map (childConfig:
|
||||
children = mapAttrs (childName: childConfig:
|
||||
(import ../../../lib/eval-config.nix {
|
||||
inherit baseModules;
|
||||
system = config.nixpkgs.initialSystem;
|
||||
modules =
|
||||
(optionals inheritParent modules)
|
||||
(optionals childConfig.inheritParentConfig modules)
|
||||
++ [ ./no-clone.nix ]
|
||||
++ [ childConfig ];
|
||||
++ [ childConfig.configuration ];
|
||||
}).config.system.build.toplevel
|
||||
) list;
|
||||
|
||||
children =
|
||||
cloner false config.nesting.children
|
||||
++ cloner true config.nesting.clone;
|
||||
) config.specialisation;
|
||||
|
||||
systemBuilder =
|
||||
let
|
||||
@@ -77,12 +72,9 @@ let
|
||||
echo -n "$nixosLabel" > $out/nixos-version
|
||||
echo -n "${config.boot.kernelPackages.stdenv.hostPlatform.system}" > $out/system
|
||||
|
||||
mkdir $out/fine-tune
|
||||
childCount=0
|
||||
for i in $children; do
|
||||
childCount=$(( childCount + 1 ))
|
||||
ln -s $i $out/fine-tune/child-$childCount
|
||||
done
|
||||
mkdir $out/specialisation
|
||||
${concatStringsSep "\n"
|
||||
(mapAttrsToList (name: path: "ln -s ${path} $out/specialisation/${name}") children)}
|
||||
|
||||
mkdir $out/bin
|
||||
export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive"
|
||||
@@ -112,7 +104,6 @@ let
|
||||
shell = "${pkgs.bash}/bin/sh";
|
||||
su = "${pkgs.shadow.su}/bin/su";
|
||||
|
||||
inherit children;
|
||||
kernelParams = config.boot.kernelParams;
|
||||
installBootLoader =
|
||||
config.system.build.installBootLoader
|
||||
@@ -143,6 +134,11 @@ let
|
||||
in
|
||||
|
||||
{
|
||||
imports = [
|
||||
(mkRemovedOptionModule [ "nesting" "clone" ] "Use `specialisation.«name» = { inheritParentConfig = true; configuration = { ... }; }` instead.")
|
||||
(mkRemovedOptionModule [ "nesting" "children" ] "Use `specialisation.«name».configuration = { ... }` instead.")
|
||||
];
|
||||
|
||||
options = {
|
||||
|
||||
system.build = mkOption {
|
||||
@@ -154,26 +150,35 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
nesting.children = mkOption {
|
||||
default = [];
|
||||
specialisation = mkOption {
|
||||
default = {};
|
||||
example = lib.literalExample "{ fewJobsManyCores.configuration = { nix.buildCores = 0; nix.maxJobs = 1; }; }";
|
||||
description = ''
|
||||
Additional configurations to build.
|
||||
'';
|
||||
};
|
||||
Additional configurations to build. If
|
||||
<literal>inheritParentConfig</literal> is true, the system
|
||||
will be based on the overall system configuration.
|
||||
|
||||
nesting.clone = mkOption {
|
||||
default = [];
|
||||
description = ''
|
||||
Additional configurations to build based on the current
|
||||
configuration which then has a lower priority.
|
||||
|
||||
To switch to a cloned configuration (e.g. <literal>child-1</literal>)
|
||||
at runtime, run
|
||||
To switch to a specialised configuration
|
||||
(e.g. <literal>fewJobsManyCores</literal>) at runtime, run:
|
||||
|
||||
<programlisting>
|
||||
# sudo /run/current-system/fine-tune/child-1/bin/switch-to-configuration test
|
||||
# sudo /run/current-system/specialisation/fewJobsManyCores/bin/switch-to-configuration test
|
||||
</programlisting>
|
||||
'';
|
||||
type = types.attrsOf (types.submodule (
|
||||
{ ... }: {
|
||||
options.inheritParentConfig = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Include the entire system's configuration. Set to false to make a completely differently configured system.";
|
||||
};
|
||||
|
||||
options.configuration = mkOption {
|
||||
default = {};
|
||||
description = "Arbitrary NixOS configuration options.";
|
||||
};
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
system.boot.loader.id = mkOption {
|
||||
|
||||
Reference in New Issue
Block a user