2006-11-12 19:48:47 +01:00
|
|
|
{ system ? __currentSystem
|
|
|
|
, autoDetectRootDevice ? false
|
|
|
|
, rootDevice ? ""
|
|
|
|
, rootLabel ? ""
|
2006-11-13 12:41:27 +01:00
|
|
|
, stage2Init
|
|
|
|
, readOnlyRoot
|
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-11-28 11:45:21 +01:00
|
|
|
pkgs = import ../pkgs/top-level/all-packages.nix {inherit system;};
|
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-11-04 13:00:05 +01:00
|
|
|
inherit system;
|
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-11-04 13:00:05 +01:00
|
|
|
inherit system;
|
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-11-27 02:35:34 +01:00
|
|
|
# Splash configuration.
|
|
|
|
splashThemes = import ./splash-themes.nix {
|
|
|
|
inherit (pkgs) fetchurl;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
rootModules = ["ide-cd" "ide-disk" "ide-generic"];
|
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;
|
|
|
|
inherit (pkgs) splashutils;
|
|
|
|
e2fsprogs = pkgs.e2fsprogsDiet;
|
|
|
|
}
|
|
|
|
"
|
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
|
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-11-12 19:48:47 +01:00
|
|
|
inherit autoDetectRootDevice rootDevice rootLabel;
|
2006-11-13 12:41:27 +01:00
|
|
|
inherit stage2Init;
|
2006-11-03 12:47:40 +01:00
|
|
|
modules = modulesClosure;
|
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;
|
|
|
|
theme = splashThemes.splashScreen;
|
|
|
|
};
|
|
|
|
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;
|
2006-11-08 10:31:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-19 21:07:45 +01:00
|
|
|
# The services (Upstart) configuration for the system.
|
2006-11-28 11:45:21 +01:00
|
|
|
upstartJobs = import ../upstart-jobs/gather.nix {
|
2006-12-10 23:43:04 +01:00
|
|
|
inherit (pkgs) runCommand;
|
2006-11-19 21:07:45 +01:00
|
|
|
|
2006-11-19 22:03:22 +01:00
|
|
|
jobs = map makeJob [
|
2006-11-19 21:07:45 +01:00
|
|
|
# Syslogd.
|
2006-11-28 11:45:21 +01:00
|
|
|
(import ../upstart-jobs/syslogd.nix {
|
2006-11-19 22:03:22 +01:00
|
|
|
inherit (pkgs) sysklogd;
|
2006-11-19 21:07:45 +01:00
|
|
|
})
|
2006-11-19 23:05:49 +01:00
|
|
|
|
2006-11-20 18:28:08 +01:00
|
|
|
# Hardware scan; loads modules for PCI devices.
|
2006-11-28 11:45:21 +01:00
|
|
|
(import ../upstart-jobs/hardware-scan.nix {
|
2006-11-20 18:28:08 +01:00
|
|
|
inherit (pkgs) kernel module_init_tools;
|
|
|
|
})
|
|
|
|
|
2006-11-20 18:06:44 +01:00
|
|
|
# Network interfaces.
|
2006-11-28 11:45:21 +01:00
|
|
|
(import ../upstart-jobs/network-interfaces.nix {
|
2006-11-20 18:28:08 +01:00
|
|
|
inherit (pkgs) nettools kernel module_init_tools;
|
2006-11-20 18:06:44 +01:00
|
|
|
})
|
|
|
|
|
2006-11-19 23:05:49 +01:00
|
|
|
# DHCP client.
|
2006-11-28 11:45:21 +01:00
|
|
|
(import ../upstart-jobs/dhclient.nix {
|
2006-12-10 23:29:44 +01:00
|
|
|
inherit (pkgs) nettools;
|
2006-11-19 23:05:49 +01:00
|
|
|
dhcp = pkgs.dhcpWrapper;
|
|
|
|
})
|
2006-11-20 21:50:52 +01:00
|
|
|
|
2006-11-23 18:43:28 +01:00
|
|
|
# SSH daemon.
|
2006-11-28 11:45:21 +01:00
|
|
|
(import ../upstart-jobs/sshd.nix {
|
2006-11-23 18:43:28 +01:00
|
|
|
inherit (pkgs) openssh;
|
|
|
|
})
|
|
|
|
|
2006-12-09 04:11:14 +01:00
|
|
|
# Nix daemon - required for multi-user Nix.
|
|
|
|
(import ../upstart-jobs/nix-daemon.nix {
|
|
|
|
inherit nix;
|
|
|
|
})
|
|
|
|
|
2006-11-28 23:27:56 +01:00
|
|
|
# X server.
|
|
|
|
(import ../upstart-jobs/xserver.nix {
|
2006-12-10 23:29:44 +01:00
|
|
|
inherit (pkgs) substituteAll;
|
2006-11-28 23:27:56 +01:00
|
|
|
inherit (pkgs.xorg) xorgserver xf86inputkeyboard xf86inputmouse xf86videovesa;
|
|
|
|
})
|
|
|
|
|
2006-11-27 00:00:30 +01:00
|
|
|
# Transparent TTY backgrounds.
|
2006-11-28 11:45:21 +01:00
|
|
|
(import ../upstart-jobs/tty-backgrounds.nix {
|
2006-11-27 00:00:30 +01:00
|
|
|
inherit (pkgs) stdenv splashutils;
|
2006-11-27 02:35:34 +01:00
|
|
|
backgrounds = splashThemes.ttyBackgrounds;
|
2006-11-27 00:00:30 +01:00
|
|
|
})
|
|
|
|
|
2006-11-20 21:50:52 +01:00
|
|
|
# Handles the maintenance/stalled event (single-user shell).
|
2006-11-28 11:45:21 +01:00
|
|
|
(import ../upstart-jobs/maintenance-shell.nix {
|
2006-11-20 21:50:52 +01:00
|
|
|
inherit (pkgs) bash;
|
|
|
|
})
|
|
|
|
|
2006-11-24 01:34:50 +01:00
|
|
|
# Ctrl-alt-delete action.
|
2006-11-28 11:45:21 +01:00
|
|
|
(import ../upstart-jobs/ctrl-alt-delete.nix)
|
2006-11-24 01:34:50 +01:00
|
|
|
|
2006-11-19 22:03:22 +01:00
|
|
|
]
|
|
|
|
|
2006-11-23 23:53:16 +01:00
|
|
|
# Handles the reboot/halt events.
|
|
|
|
++ (map
|
2006-11-28 11:45:21 +01:00
|
|
|
(event: makeJob (import ../upstart-jobs/halt.nix {
|
2006-12-11 01:52:36 +01:00
|
|
|
inherit (pkgs) bash utillinux;
|
2006-11-23 23:53:16 +01:00
|
|
|
inherit event;
|
|
|
|
}))
|
|
|
|
["reboot" "halt" "system-halt" "power-off"]
|
|
|
|
)
|
|
|
|
|
2006-11-19 22:03:22 +01:00
|
|
|
# The terminals on ttyX.
|
|
|
|
++ (map
|
2006-11-28 11:45:21 +01:00
|
|
|
(ttyNumber: makeJob (import ../upstart-jobs/mingetty.nix {
|
2006-12-11 01:52:36 +01:00
|
|
|
inherit (pkgs) mingetty pam_login;
|
2006-11-19 22:03:22 +01:00
|
|
|
inherit ttyNumber;
|
|
|
|
}))
|
|
|
|
[1 2 3 4 5 6]
|
|
|
|
)
|
|
|
|
|
|
|
|
# For the builtin logd job.
|
|
|
|
++ [pkgs.upstart];
|
|
|
|
};
|
|
|
|
|
2006-12-09 03:51:42 +01:00
|
|
|
|
|
|
|
etc = import ../helpers/make-etc.nix {
|
|
|
|
inherit (pkgs) stdenv;
|
|
|
|
|
|
|
|
configFiles = [
|
|
|
|
|
|
|
|
{ # TCP/UDP port assignments.
|
|
|
|
source = pkgs.iana_etc + "/etc/services";
|
|
|
|
target = "services";
|
|
|
|
}
|
|
|
|
|
|
|
|
{ # IP protocol numbers.
|
|
|
|
source = pkgs.iana_etc + "/etc/protocols";
|
|
|
|
target = "protocols";
|
|
|
|
}
|
|
|
|
|
|
|
|
{ # Hostname-to-IP mappings.
|
|
|
|
source = ./etc/hosts;
|
|
|
|
target = "hosts";
|
|
|
|
}
|
|
|
|
|
|
|
|
{ # Name Service Switch configuration file. Required by the C library.
|
|
|
|
source = ./etc/nsswitch.conf;
|
|
|
|
target = "nsswitch.conf";
|
|
|
|
}
|
|
|
|
|
|
|
|
{ # Configuration file for the system logging daemon.
|
|
|
|
source = ./etc/syslog.conf;
|
|
|
|
target = "syslog.conf";
|
|
|
|
}
|
|
|
|
|
|
|
|
{ # Friendly greeting on the virtual consoles.
|
|
|
|
source = ./etc/issue;
|
|
|
|
target = "issue";
|
|
|
|
}
|
|
|
|
|
|
|
|
{ # Configuration for pwdutils (login, passwd, useradd, etc.).
|
|
|
|
# You cannot login without it!
|
|
|
|
source = ./etc/login.defs;
|
|
|
|
target = "login.defs";
|
|
|
|
}
|
|
|
|
|
|
|
|
{ # SSH daemon configuration.
|
|
|
|
source = ./etc/sshd_config;
|
|
|
|
target = "ssh/sshd_config";
|
|
|
|
}
|
2006-12-09 20:25:23 +01:00
|
|
|
|
|
|
|
{ # The Upstart events defined above.
|
|
|
|
source = upstartJobs + "/etc/event.d";
|
|
|
|
target = "event.d";
|
|
|
|
}
|
|
|
|
|
2006-12-09 03:51:42 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2006-11-19 22:03:22 +01:00
|
|
|
|
2006-11-28 11:45:21 +01:00
|
|
|
makeJob = import ../upstart-jobs/make-job.nix {
|
2006-12-10 23:43:04 +01:00
|
|
|
inherit (pkgs) runCommand;
|
2006-11-19 21:07:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
|
pkgs.curl
|
|
|
|
pkgs.e2fsprogs
|
|
|
|
pkgs.findutils
|
|
|
|
pkgs.gnugrep
|
|
|
|
pkgs.gnused
|
|
|
|
pkgs.gnutar
|
|
|
|
pkgs.grub
|
|
|
|
pkgs.gzip
|
|
|
|
pkgs.iputils
|
|
|
|
pkgs.less
|
|
|
|
pkgs.module_init_tools
|
|
|
|
pkgs.nano
|
|
|
|
pkgs.netcat
|
|
|
|
pkgs.nettools
|
|
|
|
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 readOnlyRoot;
|
|
|
|
inherit (pkgs) kernel;
|
|
|
|
hostName = config.get ["networking" "hostname"];
|
|
|
|
wrapperDir = setuidWrapper.wrapperDir;
|
|
|
|
accounts = ../helpers/accounts.sh;
|
|
|
|
|
2006-12-10 23:29:44 +01:00
|
|
|
path = [pkgs.coreutils pkgs.gnugrep pkgs.findutils];
|
|
|
|
|
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;
|
|
|
|
pathsToLink = ["/bin" "/sbin" "/man/man1" "/share/man/man1"];
|
|
|
|
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-11-13 12:41:27 +01:00
|
|
|
inherit readOnlyRoot;
|
2006-12-09 20:25:23 +01:00
|
|
|
inherit activateConfiguration;
|
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-11-28 11:45:21 +01:00
|
|
|
lib = pkgs.library;
|
2006-11-27 17:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
config = rec {
|
|
|
|
|
|
|
|
# The user configuration.
|
|
|
|
config = {
|
|
|
|
networking = {
|
2006-12-09 01:06:18 +01:00
|
|
|
hostname = "nixos";
|
2006-11-27 17:26:51 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# The option declarations, i.e., option names with defaults and
|
|
|
|
# documentation.
|
|
|
|
declarations = import ./options.nix;
|
|
|
|
|
|
|
|
# Get the option named `name' from the user configuration, using
|
|
|
|
# its default value if it's not defined.
|
|
|
|
get = name:
|
|
|
|
let
|
|
|
|
sameName = lib.filter (opt: lib.eqLists opt.name name) declarations;
|
|
|
|
default =
|
|
|
|
if sameName == []
|
|
|
|
then abort ("Undeclared option `" + printName name + "'.")
|
|
|
|
else if !builtins.head sameName ? default
|
|
|
|
then abort ("Option `" + printName name + "' has no default.")
|
|
|
|
else (builtins.head sameName).default;
|
|
|
|
in lib.getAttr name default config;
|
|
|
|
|
|
|
|
printName = name: lib.concatStrings (lib.intersperse "." name);
|
|
|
|
|
2006-11-04 01:01:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-02 18:56:50 +01:00
|
|
|
}
|