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
|
2014-04-14 15:26:48 +01:00
|
|
|
|
cloner = inheritParent: list:
|
2009-10-30 11:57:23 +00:00
|
|
|
|
map (childConfig:
|
2009-12-05 19:21:57 +00:00
|
|
|
|
(import ../../../lib/eval-config.nix {
|
2010-05-08 18:18:26 +01:00
|
|
|
|
inherit baseModules;
|
|
|
|
|
modules =
|
|
|
|
|
(optionals inheritParent modules)
|
|
|
|
|
++ [ ./no-clone.nix ]
|
|
|
|
|
++ [ childConfig ];
|
2009-12-05 19:21:57 +00:00
|
|
|
|
}).config.system.build.toplevel
|
2010-05-08 18:18:26 +01:00
|
|
|
|
) list;
|
|
|
|
|
|
|
|
|
|
children =
|
|
|
|
|
cloner false config.nesting.children
|
|
|
|
|
++ cloner true config.nesting.clone;
|
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}";
|
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
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
2013-11-27 15:54:20 +00:00
|
|
|
|
echo -n "$kernelParams" > $out/kernel-params
|
|
|
|
|
|
|
|
|
|
ln -s ${config.system.build.initialRamdisk}/initrd $out/initrd
|
|
|
|
|
|
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
|
2014-04-19 12:02:13 +01:00
|
|
|
|
echo -n "$system" > $out/system
|
2009-05-27 10:00:45 +01:00
|
|
|
|
|
|
|
|
|
mkdir $out/fine-tune
|
2012-03-18 18:53:50 +00:00
|
|
|
|
childCount=0
|
2010-09-13 19:19:15 +01:00
|
|
|
|
for i in $children; do
|
2012-03-18 18:53:50 +00:00
|
|
|
|
childCount=$(( childCount + 1 ))
|
|
|
|
|
ln -s $i $out/fine-tune/child-$childCount
|
2009-05-27 10:00:45 +01:00
|
|
|
|
done
|
|
|
|
|
|
2012-03-18 18:53:50 +00:00
|
|
|
|
mkdir $out/bin
|
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
|
|
|
|
'';
|
|
|
|
|
|
2014-04-21 16:46:16 +01:00
|
|
|
|
# Handle assertions
|
|
|
|
|
|
|
|
|
|
failed = map (x: x.message) (filter (x: !x.assertion) config.assertions);
|
|
|
|
|
|
2014-12-15 11:08:31 +00:00
|
|
|
|
showWarnings = res: fold (w: x: builtins.trace "[1;31mwarning: ${w}[0m" x) res config.warnings;
|
2011-09-14 19:20:50 +01:00
|
|
|
|
|
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.
|
2014-06-05 17:43:26 +01:00
|
|
|
|
baseSystem = showWarnings (
|
2014-04-21 16:46:16 +01:00
|
|
|
|
if [] == failed then pkgs.stdenv.mkDerivation {
|
2015-09-18 17:17:22 +01:00
|
|
|
|
name = let hn = config.networking.hostName;
|
|
|
|
|
nn = if (hn != "") then hn else "unnamed";
|
2015-09-18 17:50:48 +01:00
|
|
|
|
in "nixos-system-${nn}-${config.system.nixosLabel}";
|
2014-04-21 16:46:16 +01:00
|
|
|
|
preferLocalBuild = true;
|
2015-07-07 14:01:36 +01:00
|
|
|
|
allowSubstitutes = false;
|
2014-04-21 16:46:16 +01:00
|
|
|
|
buildCommand = systemBuilder;
|
|
|
|
|
|
|
|
|
|
inherit (pkgs) utillinux coreutils;
|
|
|
|
|
systemd = config.systemd.package;
|
|
|
|
|
|
|
|
|
|
inherit children;
|
|
|
|
|
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;
|
2015-09-18 17:50:48 +01:00
|
|
|
|
nixosLabel = config.system.nixosLabel;
|
2014-04-21 16:46:16 +01:00
|
|
|
|
|
|
|
|
|
configurationName = config.boot.loader.grub.configurationName;
|
|
|
|
|
|
|
|
|
|
# Needed by switch-to-configuration.
|
|
|
|
|
perl = "${pkgs.perl}/bin/perl -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl";
|
|
|
|
|
} else throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failed)}");
|
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; }
|
|
|
|
|
) baseSystem 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
|
|
|
|
{
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
|
|
system.build = mkOption {
|
2013-10-23 15:59:33 +01:00
|
|
|
|
internal = true;
|
2013-09-04 12:05:09 +01:00
|
|
|
|
default = {};
|
|
|
|
|
description = ''
|
|
|
|
|
Attribute set of derivations used to setup the system.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nesting.children = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
description = ''
|
|
|
|
|
Additional configurations to build.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nesting.clone = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
description = ''
|
|
|
|
|
Additional configurations to build based on the current
|
2014-11-14 12:05:55 +00:00
|
|
|
|
configuration which then has a lower priority.
|
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;
|
2013-09-04 12:05:09 +01:00
|
|
|
|
default = pkgs.stdenv.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.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 (
|
|
|
|
|
{ options, ... }: {
|
|
|
|
|
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
|
|
|
|
}
|