2006-12-11 18:36:57 +01:00
|
|
|
{ platform ? __currentSystem
|
|
|
|
, stage2Init ? ""
|
2006-12-11 17:10:23 +01:00
|
|
|
, configuration
|
2006-11-12 19:48:47 +01:00
|
|
|
}:
|
2006-11-04 13:00:05 +01:00
|
|
|
|
2006-11-02 18:56:50 +01:00
|
|
|
rec {
|
|
|
|
|
2006-12-11 16:47:30 +01:00
|
|
|
# Make a configuration object from which we can retrieve option
|
|
|
|
# values.
|
2007-01-08 23:41:41 +01:00
|
|
|
config = import ./config.nix pkgs configuration;
|
2006-12-11 16:47:30 +01:00
|
|
|
|
|
|
|
|
2006-12-11 18:36:57 +01:00
|
|
|
pkgs = import ../pkgs/top-level/all-packages.nix {system = platform;};
|
2006-11-02 18:56:50 +01:00
|
|
|
|
2006-11-28 11:45:21 +01:00
|
|
|
pkgsDiet = import ../pkgs/top-level/all-packages.nix {
|
2006-12-11 18:36:57 +01:00
|
|
|
system = platform;
|
2006-11-02 23:48:01 +01:00
|
|
|
bootStdenv = pkgs.useDietLibC pkgs.stdenv;
|
|
|
|
};
|
|
|
|
|
2006-11-28 11:45:21 +01:00
|
|
|
pkgsStatic = import ../pkgs/top-level/all-packages.nix {
|
2006-12-11 18:36:57 +01:00
|
|
|
system = platform;
|
2006-11-03 14:35:02 +01:00
|
|
|
bootStdenv = pkgs.makeStaticBinaries pkgs.stdenv;
|
|
|
|
};
|
|
|
|
|
2006-11-28 11:45:21 +01:00
|
|
|
stdenvLinuxStuff = import ../pkgs/stdenv/linux {
|
2006-11-02 18:56:50 +01:00
|
|
|
system = pkgs.stdenv.system;
|
2006-11-28 11:45:21 +01:00
|
|
|
allPackages = import ../pkgs/top-level/all-packages.nix;
|
2006-11-02 18:56:50 +01:00
|
|
|
};
|
|
|
|
|
2006-11-17 17:38:24 +01:00
|
|
|
nix = pkgs.nixUnstable; # we need the exportReferencesGraph feature
|
|
|
|
|
2006-11-02 23:48:01 +01:00
|
|
|
|
2006-12-19 23:12:44 +01:00
|
|
|
rootModules =
|
2006-12-23 00:34:42 +01:00
|
|
|
(config.get ["boot" "initrd" "extraKernelModules"]) ++
|
|
|
|
(config.get ["boot" "initrd" "kernelModules"]);
|
2006-12-19 23:12:44 +01:00
|
|
|
|
|
|
|
|
2006-11-03 01:36:08 +01:00
|
|
|
# Determine the set of modules that we need to mount the root FS.
|
2006-11-28 11:45:21 +01:00
|
|
|
modulesClosure = import ../helpers/modules-closure.nix {
|
2006-11-03 12:47:40 +01:00
|
|
|
inherit (pkgs) stdenv kernel module_init_tools;
|
2006-12-19 23:12:44 +01:00
|
|
|
inherit rootModules;
|
2006-11-03 01:36:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-03 14:35:02 +01:00
|
|
|
# Some additional utilities needed in stage 1, notably mount. We
|
|
|
|
# don't want to bring in all of util-linux, so we just copy what we
|
|
|
|
# need.
|
2006-12-10 23:43:04 +01:00
|
|
|
extraUtils = pkgs.runCommand "extra-utils"
|
|
|
|
{ buildInputs = [pkgs.nukeReferences];
|
|
|
|
inherit (pkgsStatic) utillinux;
|
2007-01-10 13:42:28 +01:00
|
|
|
inherit (pkgsDiet) udev;
|
2006-12-10 23:43:04 +01:00
|
|
|
inherit (pkgs) splashutils;
|
|
|
|
e2fsprogs = pkgs.e2fsprogsDiet;
|
2007-01-10 13:42:28 +01:00
|
|
|
allowedReferences = []; # prevent accidents like glibc being included in the initrd
|
2006-12-10 23:43:04 +01:00
|
|
|
}
|
|
|
|
"
|
2006-11-24 13:13:11 +01:00
|
|
|
ensureDir $out/bin
|
|
|
|
cp $utillinux/bin/mount $utillinux/bin/umount $utillinux/sbin/pivot_root $out/bin
|
|
|
|
cp -p $e2fsprogs/sbin/fsck* $e2fsprogs/sbin/e2fsck $out/bin
|
2006-11-27 02:35:34 +01:00
|
|
|
cp $splashutils/bin/splash_helper $out/bin
|
2007-01-10 13:42:28 +01:00
|
|
|
cp $udev/sbin/udevd $udev/sbin/udevtrigger $udev/sbin/udevsettle $out/bin
|
2006-11-24 13:13:11 +01:00
|
|
|
nuke-refs $out/bin/*
|
|
|
|
";
|
2006-11-03 14:35:02 +01:00
|
|
|
|
|
|
|
|
2006-11-02 23:48:01 +01:00
|
|
|
# The init script of boot stage 1 (loading kernel modules for
|
|
|
|
# mounting the root FS).
|
2006-11-28 11:45:21 +01:00
|
|
|
bootStage1 = import ../boot/boot-stage-1.nix {
|
2006-12-10 23:29:44 +01:00
|
|
|
inherit (pkgs) substituteAll;
|
2006-11-03 12:47:40 +01:00
|
|
|
inherit (pkgsDiet) module_init_tools;
|
2006-11-03 14:35:02 +01:00
|
|
|
inherit extraUtils;
|
2006-12-11 17:10:23 +01:00
|
|
|
autoDetectRootDevice = config.get ["boot" "autoDetectRootDevice"];
|
2006-12-21 01:16:20 +01:00
|
|
|
rootDevice =
|
2007-01-10 15:07:10 +01:00
|
|
|
let rootFS =
|
|
|
|
(pkgs.library.findSingle (fs: fs.mountPoint == "/")
|
|
|
|
(abort "No root mount point declared.")
|
|
|
|
(config.get ["fileSystems"]));
|
|
|
|
in if rootFS ? device then rootFS.device else "LABEL=" + rootFS.label;
|
2006-12-11 17:10:23 +01:00
|
|
|
rootLabel = config.get ["boot" "rootLabel"];
|
2006-11-13 12:41:27 +01:00
|
|
|
inherit stage2Init;
|
2006-12-19 23:12:44 +01:00
|
|
|
modulesDir = modulesClosure;
|
|
|
|
modules = rootModules;
|
2006-12-10 23:29:44 +01:00
|
|
|
staticShell = stdenvLinuxStuff.bootstrapTools.bash;
|
2006-11-02 23:48:01 +01:00
|
|
|
staticTools = stdenvLinuxStuff.staticTools;
|
|
|
|
};
|
2006-11-02 18:56:50 +01:00
|
|
|
|
2006-11-02 23:48:01 +01:00
|
|
|
|
|
|
|
# The closure of the init script of boot stage 1 is what we put in
|
|
|
|
# the initial RAM disk.
|
2006-11-28 11:45:21 +01:00
|
|
|
initialRamdisk = import ../boot/make-initrd.nix {
|
2006-11-17 15:13:21 +01:00
|
|
|
inherit (pkgs) stdenv cpio;
|
2006-11-27 02:35:34 +01:00
|
|
|
contents = [
|
|
|
|
{ object = bootStage1;
|
|
|
|
symlink = "/init";
|
|
|
|
}
|
|
|
|
{ object = extraUtils;
|
|
|
|
suffix = "/bin/splash_helper";
|
|
|
|
symlink = "/sbin/splash_helper";
|
|
|
|
}
|
2006-11-28 11:45:21 +01:00
|
|
|
{ object = import ../helpers/unpack-theme.nix {
|
2006-11-27 02:35:34 +01:00
|
|
|
inherit (pkgs) stdenv;
|
2007-01-08 23:41:41 +01:00
|
|
|
theme = config.get ["services" "ttyBackgrounds" "defaultTheme"];
|
2006-11-27 02:35:34 +01:00
|
|
|
};
|
|
|
|
symlink = "/etc/splash";
|
|
|
|
}
|
|
|
|
];
|
2006-11-02 18:56:50 +01:00
|
|
|
};
|
|
|
|
|
2006-11-02 23:48:01 +01:00
|
|
|
|
2006-11-08 10:31:45 +01:00
|
|
|
# The installer.
|
2006-11-28 11:45:21 +01:00
|
|
|
nixosInstaller = import ../installer/nixos-installer.nix {
|
2006-12-10 23:43:04 +01:00
|
|
|
inherit (pkgs) stdenv runCommand substituteAll;
|
2006-11-17 17:38:24 +01:00
|
|
|
inherit nix;
|
2007-01-09 22:19:06 +01:00
|
|
|
nixpkgsURL = config.get ["installer" "nixpkgsURL"];
|
2006-11-08 10:31:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-19 21:07:45 +01:00
|
|
|
# The services (Upstart) configuration for the system.
|
2006-12-11 16:32:10 +01:00
|
|
|
upstartJobs = import ./upstart.nix {
|
2007-01-08 23:41:41 +01:00
|
|
|
inherit config pkgs nix;
|
2006-11-19 22:03:22 +01:00
|
|
|
};
|
|
|
|
|
2006-12-09 03:51:42 +01:00
|
|
|
|
2006-12-11 16:32:10 +01:00
|
|
|
# The static parts of /etc.
|
|
|
|
etc = import ./etc.nix {
|
|
|
|
inherit pkgs upstartJobs;
|
2006-12-09 03:51:42 +01:00
|
|
|
};
|
|
|
|
|
2006-12-11 16:47:30 +01:00
|
|
|
|
|
|
|
# The wrapper setuid programs (since we can't have setuid programs
|
|
|
|
# in the Nix store).
|
2006-11-28 18:34:27 +01:00
|
|
|
setuidWrapper = import ../helpers/setuid {
|
|
|
|
inherit (pkgs) stdenv;
|
|
|
|
wrapperDir = "/var/setuid-wrappers";
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-12-09 20:25:23 +01:00
|
|
|
# The packages you want in the boot environment.
|
|
|
|
fullPath = [
|
|
|
|
pkgs.bash
|
|
|
|
pkgs.bzip2
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.cpio
|
2007-01-10 18:09:00 +01:00
|
|
|
pkgs.cron
|
2006-12-09 20:25:23 +01:00
|
|
|
pkgs.curl
|
|
|
|
pkgs.e2fsprogs
|
|
|
|
pkgs.findutils
|
2006-12-23 23:43:39 +01:00
|
|
|
pkgs.glibc # for ldd, getent
|
2006-12-09 20:25:23 +01:00
|
|
|
pkgs.gnugrep
|
|
|
|
pkgs.gnused
|
|
|
|
pkgs.gnutar
|
|
|
|
pkgs.grub
|
|
|
|
pkgs.gzip
|
|
|
|
pkgs.iputils
|
|
|
|
pkgs.less
|
2006-12-24 02:07:28 +01:00
|
|
|
pkgs.lvm2
|
2007-01-09 18:27:26 +01:00
|
|
|
pkgs.man
|
2007-01-11 01:06:46 +01:00
|
|
|
pkgs.mdadm
|
2006-12-09 20:25:23 +01:00
|
|
|
pkgs.module_init_tools
|
|
|
|
pkgs.nano
|
|
|
|
pkgs.netcat
|
|
|
|
pkgs.nettools
|
2006-12-23 23:43:39 +01:00
|
|
|
pkgs.ntp
|
2006-12-09 20:25:23 +01:00
|
|
|
pkgs.perl
|
|
|
|
pkgs.procps
|
2006-12-11 02:03:26 +01:00
|
|
|
pkgs.pwdutils
|
2006-12-09 20:25:23 +01:00
|
|
|
pkgs.rsync
|
|
|
|
pkgs.strace
|
|
|
|
pkgs.sysklogd
|
|
|
|
pkgs.udev
|
|
|
|
pkgs.upstart
|
|
|
|
pkgs.utillinux
|
|
|
|
# pkgs.vim
|
|
|
|
nix
|
|
|
|
nixosInstaller
|
|
|
|
setuidWrapper
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
# The script that activates the configuration, i.e., it sets up
|
|
|
|
# /etc, accounts, etc. It doesn't do anything that can only be done
|
|
|
|
# at boot time (such as start `init').
|
2006-12-10 23:29:44 +01:00
|
|
|
activateConfiguration = pkgs.substituteAll {
|
2006-12-09 20:25:23 +01:00
|
|
|
src = ./activate-configuration.sh;
|
|
|
|
isExecutable = true;
|
|
|
|
|
|
|
|
inherit etc;
|
|
|
|
inherit (pkgs) kernel;
|
2006-12-11 17:10:23 +01:00
|
|
|
readOnlyRoot = config.get ["boot" "readOnlyRoot"];
|
2006-12-18 20:46:48 +01:00
|
|
|
hostName = config.get ["networking" "hostName"];
|
2006-12-09 20:25:23 +01:00
|
|
|
wrapperDir = setuidWrapper.wrapperDir;
|
|
|
|
|
2006-12-16 22:48:12 +01:00
|
|
|
path = [
|
|
|
|
pkgs.coreutils pkgs.gnugrep pkgs.findutils
|
|
|
|
pkgs.glibc # needed for getent
|
|
|
|
pkgs.pwdutils
|
|
|
|
];
|
2006-12-10 23:29:44 +01:00
|
|
|
|
2006-12-09 20:25:23 +01:00
|
|
|
# We don't want to put all of `startPath' and `path' in $PATH, since
|
|
|
|
# then we get an embarrassingly long $PATH. So use the user
|
|
|
|
# environment builder to make a directory with symlinks to those
|
|
|
|
# packages.
|
|
|
|
fullPath = pkgs.buildEnv {
|
|
|
|
name = "boot-stage-2-path";
|
|
|
|
paths = fullPath;
|
2007-01-09 18:27:26 +01:00
|
|
|
pathsToLink = ["/bin" "/sbin" "/man" "/share"];
|
2006-12-09 20:25:23 +01:00
|
|
|
ignoreCollisions = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-04 01:01:13 +01:00
|
|
|
# The init script of boot stage 2, which is supposed to do
|
|
|
|
# everything else to bring up the system.
|
2006-11-28 11:45:21 +01:00
|
|
|
bootStage2 = import ../boot/boot-stage-2.nix {
|
2006-12-10 23:29:44 +01:00
|
|
|
inherit (pkgs) substituteAll coreutils
|
|
|
|
utillinux kernel udev upstart;
|
2006-12-09 20:25:23 +01:00
|
|
|
inherit activateConfiguration;
|
2006-12-11 17:10:23 +01:00
|
|
|
readOnlyRoot = config.get ["boot" "readOnlyRoot"];
|
2006-12-10 23:29:44 +01:00
|
|
|
upstartPath = [
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.findutils
|
|
|
|
pkgs.gnugrep
|
|
|
|
pkgs.gnused
|
2006-12-11 01:52:36 +01:00
|
|
|
pkgs.upstart
|
2006-12-10 23:29:44 +01:00
|
|
|
];
|
2006-11-27 17:26:51 +01:00
|
|
|
};
|
|
|
|
|
2006-12-11 18:36:57 +01:00
|
|
|
|
|
|
|
# Script to build the Grub menu containing the current and previous
|
|
|
|
# system configurations.
|
|
|
|
grubMenuBuilder = pkgs.substituteAll {
|
|
|
|
src = ../installer/grub-menu-builder.sh;
|
|
|
|
isExecutable = true;
|
|
|
|
inherit (pkgs) bash;
|
|
|
|
path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
# Putting it all together. This builds a store object containing
|
|
|
|
# symlinks to the various parts of the built configuration (the
|
|
|
|
# kernel, the Upstart services, the init scripts, etc.) as well as a
|
|
|
|
# script `switch-to-configuration' that activates the configuration
|
|
|
|
# and makes it bootable.
|
2007-01-04 11:21:25 +01:00
|
|
|
system = pkgs.stdenv.mkDerivation {
|
2006-12-11 18:36:57 +01:00
|
|
|
name = "system";
|
|
|
|
builder = ./system.sh;
|
|
|
|
switchToConfiguration = ./switch-to-configuration.sh;
|
|
|
|
inherit (pkgs) grub coreutils gnused gnugrep diffutils findutils;
|
|
|
|
grubDevice = config.get ["boot" "grubDevice"];
|
|
|
|
kernelParams =
|
|
|
|
(config.get ["boot" "kernelParams"]) ++
|
|
|
|
(config.get ["boot" "extraKernelParams"]);
|
|
|
|
inherit bootStage2;
|
|
|
|
inherit activateConfiguration;
|
|
|
|
inherit grubMenuBuilder;
|
|
|
|
inherit etc;
|
|
|
|
kernel = pkgs.kernel + "/vmlinuz";
|
|
|
|
initrd = initialRamdisk + "/initrd";
|
|
|
|
# Most of these are needed by grub-install.
|
2006-12-18 17:27:56 +01:00
|
|
|
path = [
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.gnused
|
|
|
|
pkgs.gnugrep
|
|
|
|
pkgs.findutils
|
|
|
|
pkgs.diffutils
|
|
|
|
pkgs.upstart # for initctl
|
|
|
|
];
|
2006-12-11 18:36:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-02 18:56:50 +01:00
|
|
|
}
|