2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, modules, baseModules, ... }:
|
2012-03-18 18:53:50 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2009-05-27 10:00:45 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
|
|
# This attribute is responsible for creating boot entries for
|
2009-05-27 10:00:45 +01:00
|
|
|
# child configuration. They are only (directly) accessible
|
|
|
|
# when the parent configuration is boot default. For example,
|
2011-09-14 19:20:50 +01:00
|
|
|
# you can provide an easy way to boot the same configuration
|
2009-05-27 10:00:45 +01:00
|
|
|
# as you use, but with another kernel
|
|
|
|
# !!! fix this
|
2020-03-05 22:07:20 +00:00
|
|
|
children = mapAttrs (childName: childConfig:
|
2009-12-05 19:21:57 +00:00
|
|
|
(import ../../../lib/eval-config.nix {
|
2010-05-08 18:18:26 +01:00
|
|
|
inherit baseModules;
|
2020-03-04 14:24:22 +00:00
|
|
|
system = config.nixpkgs.initialSystem;
|
2010-05-08 18:18:26 +01:00
|
|
|
modules =
|
2020-03-05 22:07:20 +00:00
|
|
|
(optionals childConfig.inheritParentConfig modules)
|
2010-05-08 18:18:26 +01:00
|
|
|
++ [ ./no-clone.nix ]
|
2020-03-05 22:07:20 +00:00
|
|
|
++ [ childConfig.configuration ];
|
2009-12-05 19:21:57 +00:00
|
|
|
}).config.system.build.toplevel
|
2020-03-05 22:07:20 +00:00
|
|
|
) config.specialisation;
|
2009-05-27 10:00:45 +01:00
|
|
|
|
2009-09-29 10:50:38 +01:00
|
|
|
systemBuilder =
|
|
|
|
let
|
Making modular my previous changes for armv5tel. I updated the way to use
grub. Its options are no more inside 'boot', but inside 'boot.loader.grub'.
I added a new bootloader configuration for nixos, generationsDir. It creates
/boot/default/{init,initrd,kernel,system} symlinks, and the same for the generations
in /boot/system-$gen/{init,initrd,kernel,system}.
I can program the u-boot loader to load /boot/default files always, and have
a minimal nixos boot loader installer functionality. Additionally, I can refer
to the other system generations easily, with a simple 'ls' in /boot.
svn path=/nixos/trunk/; revision=17460
2009-09-27 22:51:37 +01:00
|
|
|
kernelPath = "${config.boot.kernelPackages.kernel}/" +
|
|
|
|
"${config.system.boot.loader.kernelFile}";
|
2015-11-15 00:00:00 +00:00
|
|
|
initrdPath = "${config.system.build.initialRamdisk}/" +
|
|
|
|
"${config.system.boot.loader.initrdFile}";
|
2010-08-24 14:27:28 +01:00
|
|
|
in ''
|
2012-03-18 18:53:50 +00:00
|
|
|
mkdir $out
|
2009-05-27 10:00:45 +01:00
|
|
|
|
2013-11-27 15:54:20 +00:00
|
|
|
# Containers don't have their own kernel or initrd. They boot
|
|
|
|
# directly into stage 2.
|
|
|
|
${optionalString (!config.boot.isContainer) ''
|
|
|
|
if [ ! -f ${kernelPath} ]; then
|
|
|
|
echo "The bootloader cannot find the proper kernel image."
|
|
|
|
echo "(Expecting ${kernelPath})"
|
|
|
|
false
|
|
|
|
fi
|
2010-09-12 23:43:45 +01:00
|
|
|
|
2013-11-27 15:54:20 +00:00
|
|
|
ln -s ${kernelPath} $out/kernel
|
|
|
|
ln -s ${config.system.modulesTree} $out/kernel-modules
|
2019-04-24 18:24:16 +01:00
|
|
|
${optionalString (config.hardware.deviceTree.package != null) ''
|
|
|
|
ln -s ${config.hardware.deviceTree.package} $out/dtbs
|
2017-02-12 00:56:29 +00:00
|
|
|
''}
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2013-11-27 15:54:20 +00:00
|
|
|
echo -n "$kernelParams" > $out/kernel-params
|
|
|
|
|
2015-11-15 00:00:00 +00:00
|
|
|
ln -s ${initrdPath} $out/initrd
|
2013-11-27 15:54:20 +00:00
|
|
|
|
2017-04-02 19:45:44 +01:00
|
|
|
ln -s ${config.system.build.initialRamdiskSecretAppender}/bin/append-initrd-secrets $out
|
|
|
|
|
2015-08-24 23:27:06 +01:00
|
|
|
ln -s ${config.hardware.firmware}/lib/firmware $out/firmware
|
2013-11-27 15:54:20 +00:00
|
|
|
''}
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 19:19:15 +01:00
|
|
|
echo "$activationScript" > $out/activate
|
|
|
|
substituteInPlace $out/activate --subst-var out
|
|
|
|
chmod u+x $out/activate
|
|
|
|
unset activationScript
|
2010-09-13 23:10:25 +01:00
|
|
|
|
|
|
|
cp ${config.system.build.bootStage2} $out/init
|
|
|
|
substituteInPlace $out/init --subst-var-by systemConfig $out
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-05-27 10:00:45 +01:00
|
|
|
ln -s ${config.system.build.etc}/etc $out/etc
|
|
|
|
ln -s ${config.system.path} $out/sw
|
2012-08-02 20:11:29 +01:00
|
|
|
ln -s "$systemd" $out/systemd
|
2009-05-27 10:00:45 +01:00
|
|
|
|
2012-04-14 18:09:59 +01:00
|
|
|
echo -n "$configurationName" > $out/configuration-name
|
2013-01-16 12:17:57 +00:00
|
|
|
echo -n "systemd ${toString config.systemd.package.interfaceVersion}" > $out/init-interface-version
|
2015-09-18 17:50:48 +01:00
|
|
|
echo -n "$nixosLabel" > $out/nixos-version
|
2020-03-20 16:55:44 +00:00
|
|
|
echo -n "${config.boot.kernelPackages.stdenv.hostPlatform.system}" > $out/system
|
2009-05-27 10:00:45 +01:00
|
|
|
|
2020-03-05 22:07:20 +00:00
|
|
|
mkdir $out/specialisation
|
|
|
|
${concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (name: path: "ln -s ${path} $out/specialisation/${name}") children)}
|
2009-05-27 10:00:45 +01:00
|
|
|
|
2012-03-18 18:53:50 +00:00
|
|
|
mkdir $out/bin
|
2017-11-18 22:33:24 +00:00
|
|
|
export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive"
|
2012-08-02 20:11:29 +01:00
|
|
|
substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration
|
2009-05-27 10:00:45 +01:00
|
|
|
chmod +x $out/bin/switch-to-configuration
|
2010-04-28 15:55:26 +01:00
|
|
|
|
2015-06-04 09:34:48 +01:00
|
|
|
echo -n "${toString config.system.extraDependencies}" > $out/extra-dependencies
|
|
|
|
|
2010-04-28 15:55:26 +01:00
|
|
|
${config.system.extraSystemBuilderCmds}
|
2009-05-27 10:00:45 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
# Putting it all together. This builds a store path containing
|
|
|
|
# symlinks to the various parts of the built configuration (the
|
2013-10-31 12:26:06 +00:00
|
|
|
# kernel, systemd units, init scripts, etc.) as well as a script
|
|
|
|
# `switch-to-configuration' that activates the configuration and
|
|
|
|
# makes it bootable.
|
2018-09-24 20:40:59 +01:00
|
|
|
baseSystem = pkgs.stdenvNoCC.mkDerivation {
|
2018-09-24 20:43:55 +01:00
|
|
|
name = let hn = config.networking.hostName;
|
|
|
|
nn = if (hn != "") then hn else "unnamed";
|
|
|
|
in "nixos-system-${nn}-${config.system.nixos.label}";
|
|
|
|
preferLocalBuild = true;
|
|
|
|
allowSubstitutes = false;
|
|
|
|
buildCommand = systemBuilder;
|
|
|
|
|
|
|
|
inherit (pkgs) utillinux coreutils;
|
|
|
|
systemd = config.systemd.package;
|
|
|
|
shell = "${pkgs.bash}/bin/sh";
|
2018-10-03 11:31:08 +01:00
|
|
|
su = "${pkgs.shadow.su}/bin/su";
|
2018-09-24 20:43:55 +01:00
|
|
|
|
|
|
|
kernelParams = config.boot.kernelParams;
|
|
|
|
installBootLoader =
|
|
|
|
config.system.build.installBootLoader
|
|
|
|
or "echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2; true";
|
|
|
|
activationScript = config.system.activationScripts.script;
|
|
|
|
nixosLabel = config.system.nixos.label;
|
|
|
|
|
|
|
|
configurationName = config.boot.loader.grub.configurationName;
|
|
|
|
|
|
|
|
# Needed by switch-to-configuration.
|
|
|
|
|
|
|
|
perl = "${pkgs.perl}/bin/perl " + (concatMapStringsSep " " (lib: "-I${lib}/${pkgs.perl.libPrefix}") (with pkgs.perlPackages; [ FileSlurp NetDBus XMLParser XMLTwig ]));
|
2018-09-24 20:40:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
# Handle assertions and warnings
|
|
|
|
|
|
|
|
failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
|
|
|
|
|
|
|
|
baseSystemAssertWarn = if failedAssertions != []
|
|
|
|
then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
2019-02-23 18:06:51 +00:00
|
|
|
else showWarnings config.warnings baseSystem;
|
2009-05-27 10:00:45 +01:00
|
|
|
|
2014-06-05 17:43:26 +01:00
|
|
|
# Replace runtime dependencies
|
|
|
|
system = fold ({ oldDependency, newDependency }: drv:
|
|
|
|
pkgs.replaceDependency { inherit oldDependency newDependency drv; }
|
2018-09-24 20:40:59 +01:00
|
|
|
) baseSystemAssertWarn config.system.replaceRuntimeDependencies;
|
2009-05-27 10:00:45 +01:00
|
|
|
|
2013-09-04 12:05:09 +01:00
|
|
|
in
|
2009-05-27 10:00:45 +01:00
|
|
|
|
2013-09-04 12:05:09 +01:00
|
|
|
{
|
2020-03-05 22:07:20 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "nesting" "clone" ] "Use `specialisation.«name» = { inheritParentConfig = true; configuration = { ... }; }` instead.")
|
|
|
|
(mkRemovedOptionModule [ "nesting" "children" ] "Use `specialisation.«name».configuration = { ... }` instead.")
|
|
|
|
];
|
|
|
|
|
2013-09-04 12:05:09 +01:00
|
|
|
options = {
|
|
|
|
|
|
|
|
system.build = mkOption {
|
2013-10-23 15:59:33 +01:00
|
|
|
internal = true;
|
2013-09-04 12:05:09 +01:00
|
|
|
default = {};
|
2016-10-09 00:41:01 +01:00
|
|
|
type = types.attrs;
|
2013-09-04 12:05:09 +01:00
|
|
|
description = ''
|
|
|
|
Attribute set of derivations used to setup the system.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-03-05 22:07:20 +00:00
|
|
|
specialisation = mkOption {
|
|
|
|
default = {};
|
|
|
|
example = lib.literalExample "{ fewJobsManyCores.configuration = { nix.buildCores = 0; nix.maxJobs = 1; }; }";
|
2013-09-04 12:05:09 +01:00
|
|
|
description = ''
|
2020-03-05 22:07:20 +00:00
|
|
|
Additional configurations to build. If
|
|
|
|
<literal>inheritParentConfig</literal> is true, the system
|
|
|
|
will be based on the overall system configuration.
|
2018-09-01 15:12:35 +01:00
|
|
|
|
2020-03-05 22:07:20 +00:00
|
|
|
To switch to a specialised configuration
|
|
|
|
(e.g. <literal>fewJobsManyCores</literal>) at runtime, run:
|
2018-09-01 15:12:35 +01:00
|
|
|
|
|
|
|
<programlisting>
|
2020-03-05 22:07:20 +00:00
|
|
|
# sudo /run/current-system/specialisation/fewJobsManyCores/bin/switch-to-configuration test
|
2018-09-01 15:12:35 +01:00
|
|
|
</programlisting>
|
2013-09-04 12:05:09 +01:00
|
|
|
'';
|
2020-03-05 22:07:20 +00:00
|
|
|
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.";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
2013-09-04 12:05:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
system.boot.loader.id = mkOption {
|
2013-10-23 15:59:33 +01:00
|
|
|
internal = true;
|
2013-09-04 12:05:09 +01:00
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Id string of the used bootloader.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
system.boot.loader.kernelFile = mkOption {
|
2013-10-23 15:59:33 +01:00
|
|
|
internal = true;
|
2018-08-20 19:20:57 +01:00
|
|
|
default = pkgs.stdenv.hostPlatform.platform.kernelTarget;
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-09-04 12:05:09 +01:00
|
|
|
description = ''
|
|
|
|
Name of the kernel file to be passed to the bootloader.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-15 00:00:00 +00:00
|
|
|
system.boot.loader.initrdFile = mkOption {
|
|
|
|
internal = true;
|
|
|
|
default = "initrd";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Name of the initrd file to be passed to the bootloader.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-09-04 12:05:09 +01:00
|
|
|
system.copySystemConfiguration = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2013-09-04 12:05:09 +01:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If enabled, copies the NixOS configuration file
|
2016-02-28 09:06:27 +00:00
|
|
|
(usually <filename>/etc/nixos/configuration.nix</filename>)
|
|
|
|
and links it from the resulting system
|
|
|
|
(getting to <filename>/run/current-system/configuration.nix</filename>).
|
|
|
|
Note that only this single file is copied, even if it imports others.
|
2013-09-04 12:05:09 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
system.extraSystemBuilderCmds = mkOption {
|
2013-10-28 15:14:15 +00:00
|
|
|
type = types.lines;
|
2013-09-04 12:05:09 +01:00
|
|
|
internal = true;
|
2013-10-23 15:59:33 +01:00
|
|
|
default = "";
|
2013-09-04 12:05:09 +01:00
|
|
|
description = ''
|
|
|
|
This code will be added to the builder creating the system store path.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-06-04 09:34:48 +01:00
|
|
|
system.extraDependencies = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
A list of packages that should be included in the system
|
|
|
|
closure but not otherwise made available to users. This is
|
|
|
|
primarily used by the installation tests.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-06-05 17:43:26 +01:00
|
|
|
system.replaceRuntimeDependencies = mkOption {
|
|
|
|
default = [];
|
2016-01-17 18:34:55 +00:00
|
|
|
example = lib.literalExample "[ ({ original = pkgs.openssl; replacement = pkgs.callPackage /path/to/openssl { }; }) ]";
|
2014-06-05 17:43:26 +01:00
|
|
|
type = types.listOf (types.submodule (
|
2018-07-20 21:56:59 +01:00
|
|
|
{ ... }: {
|
2014-06-05 17:43:26 +01:00
|
|
|
options.original = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "The original package to override.";
|
|
|
|
};
|
|
|
|
|
|
|
|
options.replacement = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "The replacement package.";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
apply = map ({ original, replacement, ... }: {
|
|
|
|
oldDependency = original;
|
|
|
|
newDependency = replacement;
|
|
|
|
});
|
|
|
|
description = ''
|
|
|
|
List of packages to override without doing a full rebuild.
|
|
|
|
The original derivation and replacement derivation must have the same
|
|
|
|
name length, and ideally should have close-to-identical directory layout.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-09-04 12:05:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
|
|
system.extraSystemBuilderCmds =
|
|
|
|
optionalString
|
|
|
|
config.system.copySystemConfiguration
|
2016-02-28 09:06:27 +00:00
|
|
|
''ln -s '${import ../../../lib/from-env.nix "NIXOS_CONFIG" <nixos-config>}' \
|
|
|
|
"$out/configuration.nix"
|
|
|
|
'';
|
2013-09-04 12:05:09 +01:00
|
|
|
|
|
|
|
system.build.toplevel = system;
|
|
|
|
|
|
|
|
};
|
2010-09-12 23:43:45 +01:00
|
|
|
|
2009-05-27 10:00:45 +01:00
|
|
|
}
|