2006-12-11 17:36:57 +00:00
|
|
|
{ platform ? __currentSystem
|
|
|
|
, stage2Init ? ""
|
2006-12-11 16:10:23 +00:00
|
|
|
, configuration
|
2006-11-12 18:48:47 +00:00
|
|
|
}:
|
2006-11-04 12:00:05 +00:00
|
|
|
|
2006-11-02 17:56:50 +00:00
|
|
|
rec {
|
|
|
|
|
2006-12-11 15:47:30 +00:00
|
|
|
# Make a configuration object from which we can retrieve option
|
|
|
|
# values.
|
2007-01-08 22:41:41 +00:00
|
|
|
config = import ./config.nix pkgs configuration;
|
2006-12-11 15:47:30 +00:00
|
|
|
|
|
|
|
|
2006-12-11 17:36:57 +00:00
|
|
|
pkgs = import ../pkgs/top-level/all-packages.nix {system = platform;};
|
2006-11-02 17:56:50 +00:00
|
|
|
|
2006-11-28 10:45:21 +00:00
|
|
|
pkgsDiet = import ../pkgs/top-level/all-packages.nix {
|
2006-12-11 17:36:57 +00:00
|
|
|
system = platform;
|
2006-11-02 22:48:01 +00:00
|
|
|
bootStdenv = pkgs.useDietLibC pkgs.stdenv;
|
|
|
|
};
|
|
|
|
|
2006-11-28 10:45:21 +00:00
|
|
|
pkgsStatic = import ../pkgs/top-level/all-packages.nix {
|
2006-12-11 17:36:57 +00:00
|
|
|
system = platform;
|
2006-11-03 13:35:02 +00:00
|
|
|
bootStdenv = pkgs.makeStaticBinaries pkgs.stdenv;
|
|
|
|
};
|
|
|
|
|
2006-11-28 10:45:21 +00:00
|
|
|
stdenvLinuxStuff = import ../pkgs/stdenv/linux {
|
2006-11-02 17:56:50 +00:00
|
|
|
system = pkgs.stdenv.system;
|
2006-11-28 10:45:21 +00:00
|
|
|
allPackages = import ../pkgs/top-level/all-packages.nix;
|
2006-11-02 17:56:50 +00:00
|
|
|
};
|
|
|
|
|
2006-11-17 16:38:24 +00:00
|
|
|
nix = pkgs.nixUnstable; # we need the exportReferencesGraph feature
|
|
|
|
|
2006-11-02 22:48:01 +00:00
|
|
|
|
2006-12-19 22:12:44 +00:00
|
|
|
rootModules =
|
2006-12-22 23:34:42 +00:00
|
|
|
(config.get ["boot" "initrd" "extraKernelModules"]) ++
|
|
|
|
(config.get ["boot" "initrd" "kernelModules"]);
|
2006-12-19 22:12:44 +00:00
|
|
|
|
|
|
|
|
2006-11-03 00:36:08 +00:00
|
|
|
# Determine the set of modules that we need to mount the root FS.
|
2006-11-28 10:45:21 +00:00
|
|
|
modulesClosure = import ../helpers/modules-closure.nix {
|
2006-11-03 11:47:40 +00:00
|
|
|
inherit (pkgs) stdenv kernel module_init_tools;
|
2006-12-19 22:12:44 +00:00
|
|
|
inherit rootModules;
|
2006-11-03 00:36:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-03 13:35:02 +00: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 22:43:04 +00:00
|
|
|
extraUtils = pkgs.runCommand "extra-utils"
|
|
|
|
{ buildInputs = [pkgs.nukeReferences];
|
|
|
|
inherit (pkgsStatic) utillinux;
|
2007-01-10 12:42:28 +00:00
|
|
|
inherit (pkgsDiet) udev;
|
2006-12-10 22:43:04 +00:00
|
|
|
e2fsprogs = pkgs.e2fsprogsDiet;
|
2007-01-10 12:42:28 +00:00
|
|
|
allowedReferences = []; # prevent accidents like glibc being included in the initrd
|
2006-12-10 22:43:04 +00:00
|
|
|
}
|
|
|
|
"
|
2006-11-24 12:13:11 +00: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
|
2007-01-10 12:42:28 +00:00
|
|
|
cp $udev/sbin/udevd $udev/sbin/udevtrigger $udev/sbin/udevsettle $out/bin
|
2006-11-24 12:13:11 +00:00
|
|
|
nuke-refs $out/bin/*
|
|
|
|
";
|
2006-11-03 13:35:02 +00:00
|
|
|
|
|
|
|
|
2006-11-02 22:48:01 +00:00
|
|
|
# The init script of boot stage 1 (loading kernel modules for
|
|
|
|
# mounting the root FS).
|
2006-11-28 10:45:21 +00:00
|
|
|
bootStage1 = import ../boot/boot-stage-1.nix {
|
2006-12-10 22:29:44 +00:00
|
|
|
inherit (pkgs) substituteAll;
|
2006-11-03 11:47:40 +00:00
|
|
|
inherit (pkgsDiet) module_init_tools;
|
2006-11-03 13:35:02 +00:00
|
|
|
inherit extraUtils;
|
2006-12-11 16:10:23 +00:00
|
|
|
autoDetectRootDevice = config.get ["boot" "autoDetectRootDevice"];
|
2007-02-06 16:53:36 +00:00
|
|
|
fileSystems =
|
|
|
|
pkgs.lib.filter
|
|
|
|
(fs: fs.mountPoint == "/" || (fs ? neededForBoot && fs.neededForBoot))
|
|
|
|
(config.get ["fileSystems"]);
|
2006-12-11 16:10:23 +00:00
|
|
|
rootLabel = config.get ["boot" "rootLabel"];
|
2006-11-13 11:41:27 +00:00
|
|
|
inherit stage2Init;
|
2006-12-19 22:12:44 +00:00
|
|
|
modulesDir = modulesClosure;
|
|
|
|
modules = rootModules;
|
2006-12-10 22:29:44 +00:00
|
|
|
staticShell = stdenvLinuxStuff.bootstrapTools.bash;
|
2006-11-02 22:48:01 +00:00
|
|
|
staticTools = stdenvLinuxStuff.staticTools;
|
|
|
|
};
|
2006-11-02 17:56:50 +00:00
|
|
|
|
2006-11-02 22:48:01 +00:00
|
|
|
|
|
|
|
# The closure of the init script of boot stage 1 is what we put in
|
|
|
|
# the initial RAM disk.
|
2006-11-28 10:45:21 +00:00
|
|
|
initialRamdisk = import ../boot/make-initrd.nix {
|
2007-01-23 14:37:42 +00:00
|
|
|
inherit (pkgs) perl stdenv cpio;
|
2006-11-27 01:35:34 +00:00
|
|
|
contents = [
|
|
|
|
{ object = bootStage1;
|
|
|
|
symlink = "/init";
|
|
|
|
}
|
2007-01-22 18:58:04 +00:00
|
|
|
] ++ (if config.get ["boot" "initrd" "enableSplashScreen"] then [
|
2007-01-23 13:44:41 +00:00
|
|
|
{ object = pkgs.runCommand "splashutils" {} "
|
|
|
|
ensureDir $out/bin
|
|
|
|
cp ${pkgs.splashutils}/bin/splash_helper $out/bin
|
|
|
|
";
|
2006-11-27 01:35:34 +00:00
|
|
|
suffix = "/bin/splash_helper";
|
|
|
|
symlink = "/sbin/splash_helper";
|
|
|
|
}
|
2006-11-28 10:45:21 +00:00
|
|
|
{ object = import ../helpers/unpack-theme.nix {
|
2006-11-27 01:35:34 +00:00
|
|
|
inherit (pkgs) stdenv;
|
2007-01-08 22:41:41 +00:00
|
|
|
theme = config.get ["services" "ttyBackgrounds" "defaultTheme"];
|
2006-11-27 01:35:34 +00:00
|
|
|
};
|
|
|
|
symlink = "/etc/splash";
|
|
|
|
}
|
2007-01-22 18:58:04 +00:00
|
|
|
] else []);
|
2006-11-02 17:56:50 +00:00
|
|
|
};
|
|
|
|
|
2006-11-02 22:48:01 +00:00
|
|
|
|
2006-11-08 09:31:45 +00:00
|
|
|
# The installer.
|
2007-02-06 10:46:36 +00:00
|
|
|
nixosInstall = import ../installer/nixos-install.nix {
|
2007-02-06 13:09:25 +00:00
|
|
|
inherit (pkgs) perl runCommand substituteAll;
|
2006-11-17 16:38:24 +00:00
|
|
|
inherit nix;
|
2007-01-09 21:19:06 +00:00
|
|
|
nixpkgsURL = config.get ["installer" "nixpkgsURL"];
|
2006-11-08 09:31:45 +00:00
|
|
|
};
|
|
|
|
|
2007-02-06 13:09:25 +00:00
|
|
|
nixosRebuild = import ../installer/nixos-rebuild.nix {
|
|
|
|
inherit (pkgs) substituteAll;
|
2007-02-06 14:13:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nixosCheckout = import ../installer/nixos-checkout.nix {
|
|
|
|
inherit (pkgs) substituteAll;
|
2007-02-06 13:09:25 +00:00
|
|
|
};
|
|
|
|
|
2006-11-08 09:31:45 +00:00
|
|
|
|
2007-01-15 17:19:41 +00:00
|
|
|
# NSS modules. Hacky!
|
2007-01-16 16:09:43 +00:00
|
|
|
nssModules =
|
|
|
|
if config.get ["users" "ldap" "enable"] then [pkgs.nss_ldap] else [];
|
2007-01-15 17:19:41 +00:00
|
|
|
|
|
|
|
nssModulesPath = pkgs.lib.concatStrings (pkgs.lib.intersperse ":"
|
|
|
|
(map (mod: mod + "/lib") nssModules));
|
|
|
|
|
|
|
|
|
2007-03-04 01:16:24 +00:00
|
|
|
# Wrapper around modprobe to set the path to the modules.
|
|
|
|
modprobe = pkgs.substituteAll {
|
|
|
|
dir = "sbin";
|
|
|
|
src = ./modprobe;
|
|
|
|
isExecutable = true;
|
|
|
|
inherit (pkgs) kernel module_init_tools;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-19 20:07:45 +00:00
|
|
|
# The services (Upstart) configuration for the system.
|
2007-03-30 12:59:43 +00:00
|
|
|
upstartJobs = import ../upstart-jobs/default.nix {
|
2007-03-04 01:16:24 +00:00
|
|
|
inherit config pkgs nix modprobe nssModulesPath;
|
2006-11-19 21:03:22 +00:00
|
|
|
};
|
|
|
|
|
2006-12-09 02:51:42 +00:00
|
|
|
|
2006-12-11 15:32:10 +00:00
|
|
|
# The static parts of /etc.
|
2007-03-30 12:59:43 +00:00
|
|
|
etc = import ../etc/default.nix {
|
2007-03-20 13:30:14 +00:00
|
|
|
inherit config pkgs upstartJobs systemPath wrapperDir defaultShell;
|
2007-03-30 12:55:09 +00:00
|
|
|
extraEtc = pkgs.lib.concatLists (map (job: job.extraEtc) upstartJobs.jobs);
|
2006-12-09 02:51:42 +00:00
|
|
|
};
|
|
|
|
|
2006-12-11 15:47:30 +00:00
|
|
|
|
|
|
|
# The wrapper setuid programs (since we can't have setuid programs
|
2007-01-15 14:43:56 +00:00
|
|
|
# in the Nix store).
|
|
|
|
wrapperDir = "/var/setuid-wrappers";
|
|
|
|
|
2006-11-28 17:34:27 +00:00
|
|
|
setuidWrapper = import ../helpers/setuid {
|
|
|
|
inherit (pkgs) stdenv;
|
2007-01-15 14:43:56 +00:00
|
|
|
inherit wrapperDir;
|
2006-11-28 17:34:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-12-09 19:25:23 +00:00
|
|
|
# The packages you want in the boot environment.
|
2007-01-15 14:43:56 +00:00
|
|
|
systemPathList = [
|
2007-03-04 01:16:24 +00:00
|
|
|
modprobe # must take precedence over module_init_tools
|
2007-03-20 10:40:45 +00:00
|
|
|
pkgs.bashInteractive # bash with ncurses support
|
2006-12-09 19:25:23 +00:00
|
|
|
pkgs.bzip2
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.cpio
|
2007-01-10 17:09:00 +00:00
|
|
|
pkgs.cron
|
2006-12-09 19:25:23 +00:00
|
|
|
pkgs.curl
|
|
|
|
pkgs.e2fsprogs
|
|
|
|
pkgs.findutils
|
2006-12-23 22:43:39 +00:00
|
|
|
pkgs.glibc # for ldd, getent
|
2006-12-09 19:25:23 +00:00
|
|
|
pkgs.gnugrep
|
|
|
|
pkgs.gnused
|
|
|
|
pkgs.gnutar
|
|
|
|
pkgs.grub
|
|
|
|
pkgs.gzip
|
|
|
|
pkgs.iputils
|
|
|
|
pkgs.less
|
2006-12-24 01:07:28 +00:00
|
|
|
pkgs.lvm2
|
2007-01-09 17:27:26 +00:00
|
|
|
pkgs.man
|
2007-01-11 00:06:46 +00:00
|
|
|
pkgs.mdadm
|
2006-12-09 19:25:23 +00:00
|
|
|
pkgs.module_init_tools
|
|
|
|
pkgs.nano
|
|
|
|
pkgs.netcat
|
|
|
|
pkgs.nettools
|
2006-12-23 22:43:39 +00:00
|
|
|
pkgs.ntp
|
2007-02-19 22:33:44 +00:00
|
|
|
pkgs.openssh
|
|
|
|
pkgs.pciutils
|
2006-12-09 19:25:23 +00:00
|
|
|
pkgs.perl
|
|
|
|
pkgs.procps
|
2006-12-11 01:03:26 +00:00
|
|
|
pkgs.pwdutils
|
2006-12-09 19:25:23 +00:00
|
|
|
pkgs.rsync
|
|
|
|
pkgs.strace
|
2007-01-11 15:32:48 +00:00
|
|
|
pkgs.su
|
2006-12-09 19:25:23 +00:00
|
|
|
pkgs.sysklogd
|
2007-05-23 14:29:34 +00:00
|
|
|
pkgs.sysvtools
|
2007-04-20 08:51:41 +00:00
|
|
|
pkgs.time
|
2006-12-09 19:25:23 +00:00
|
|
|
pkgs.udev
|
|
|
|
pkgs.upstart
|
|
|
|
pkgs.utillinux
|
|
|
|
# pkgs.vim
|
2007-03-28 21:15:23 +00:00
|
|
|
pkgs.wirelesstools
|
2006-12-09 19:25:23 +00:00
|
|
|
nix
|
2007-02-06 10:46:36 +00:00
|
|
|
nixosInstall
|
2007-02-06 13:09:25 +00:00
|
|
|
nixosRebuild
|
2007-02-06 14:13:12 +00:00
|
|
|
nixosCheckout
|
2006-12-09 19:25:23 +00:00
|
|
|
setuidWrapper
|
2007-03-01 00:36:00 +00:00
|
|
|
]
|
2007-04-07 21:44:26 +00:00
|
|
|
++ pkgs.lib.concatLists (map (job: job.extraPath) upstartJobs.jobs)
|
|
|
|
++ (config.get ["environment" "extraPackages"]) pkgs;
|
2006-12-09 19:25:23 +00:00
|
|
|
|
|
|
|
|
2007-01-15 14:43:56 +00: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.
|
|
|
|
systemPath = pkgs.buildEnv {
|
|
|
|
name = "system-path";
|
|
|
|
paths = systemPathList;
|
|
|
|
pathsToLink = ["/bin" "/sbin" "/man" "/share"];
|
|
|
|
ignoreCollisions = true;
|
|
|
|
};
|
|
|
|
|
2007-03-20 13:30:14 +00:00
|
|
|
|
|
|
|
defaultShell = "/var/run/current-system/sw/bin/bash";
|
|
|
|
|
2007-01-15 14:43:56 +00:00
|
|
|
|
2006-12-09 19:25:23 +00:00
|
|
|
# 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 22:29:44 +00:00
|
|
|
activateConfiguration = pkgs.substituteAll {
|
2006-12-09 19:25:23 +00:00
|
|
|
src = ./activate-configuration.sh;
|
|
|
|
isExecutable = true;
|
|
|
|
|
2007-03-20 13:30:14 +00:00
|
|
|
inherit etc wrapperDir systemPath modprobe defaultShell;
|
2006-12-09 19:25:23 +00:00
|
|
|
inherit (pkgs) kernel;
|
2006-12-11 16:10:23 +00:00
|
|
|
readOnlyRoot = config.get ["boot" "readOnlyRoot"];
|
2006-12-18 19:46:48 +00:00
|
|
|
hostName = config.get ["networking" "hostName"];
|
2007-04-07 21:44:26 +00:00
|
|
|
setuidPrograms =
|
|
|
|
config.get ["security" "setuidPrograms"] ++
|
|
|
|
config.get ["security" "extraSetuidPrograms"];
|
2007-02-28 16:58:35 +00:00
|
|
|
maxJobs = config.get ["nix" "maxJobs"];
|
2006-12-09 19:25:23 +00:00
|
|
|
|
2006-12-16 21:48:12 +00:00
|
|
|
path = [
|
|
|
|
pkgs.coreutils pkgs.gnugrep pkgs.findutils
|
|
|
|
pkgs.glibc # needed for getent
|
|
|
|
pkgs.pwdutils
|
|
|
|
];
|
2007-03-20 10:40:45 +00:00
|
|
|
|
|
|
|
bash = pkgs.bashInteractive;
|
2006-12-09 19:25:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-04 00:01:13 +00:00
|
|
|
# The init script of boot stage 2, which is supposed to do
|
|
|
|
# everything else to bring up the system.
|
2006-11-28 10:45:21 +00:00
|
|
|
bootStage2 = import ../boot/boot-stage-2.nix {
|
2007-03-06 00:45:33 +00:00
|
|
|
inherit (pkgs) substituteAll writeText coreutils
|
2006-12-10 22:29:44 +00:00
|
|
|
utillinux kernel udev upstart;
|
2006-12-09 19:25:23 +00:00
|
|
|
inherit activateConfiguration;
|
2006-12-11 16:10:23 +00:00
|
|
|
readOnlyRoot = config.get ["boot" "readOnlyRoot"];
|
2006-12-10 22:29:44 +00:00
|
|
|
upstartPath = [
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.findutils
|
|
|
|
pkgs.gnugrep
|
|
|
|
pkgs.gnused
|
2006-12-11 00:52:36 +00:00
|
|
|
pkgs.upstart
|
2006-12-10 22:29:44 +00:00
|
|
|
];
|
2007-03-06 00:45:33 +00:00
|
|
|
bootLocal = config.get ["boot" "localCommands"];
|
2006-11-27 16:26:51 +00:00
|
|
|
};
|
|
|
|
|
2006-12-11 17:36:57 +00: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];
|
2007-02-09 16:19:29 +00:00
|
|
|
copyKernels = config.get ["boot" "copyKernels"];
|
2006-12-11 17:36:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
# 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 10:21:25 +00:00
|
|
|
system = pkgs.stdenv.mkDerivation {
|
2006-12-11 17:36:57 +00: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;
|
2007-03-20 13:01:53 +00:00
|
|
|
inherit systemPath;
|
2006-12-11 17:36:57 +00:00
|
|
|
kernel = pkgs.kernel + "/vmlinuz";
|
|
|
|
initrd = initialRamdisk + "/initrd";
|
|
|
|
# Most of these are needed by grub-install.
|
2006-12-18 16:27:56 +00:00
|
|
|
path = [
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.gnused
|
|
|
|
pkgs.gnugrep
|
|
|
|
pkgs.findutils
|
|
|
|
pkgs.diffutils
|
|
|
|
pkgs.upstart # for initctl
|
|
|
|
];
|
2006-12-11 17:36:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-02 17:56:50 +00:00
|
|
|
}
|