* Moving stuff around.

svn path=/nixu/trunk/; revision=7155
This commit is contained in:
Eelco Dolstra 2006-11-27 19:49:05 +00:00
parent 1a0fcfdf1a
commit a9234b5c07
39 changed files with 0 additions and 1843 deletions

View File

@ -1,19 +0,0 @@
To get a Stage 1 shell:
Add "debug1" to the kernel command line.
Switching to maintenance mode:
$ shutdown now
To get out of maintenance mode:
$ initctl emit startup
Updating the current system configuration:
$ nix-env -p /nix/var/nix/profiles/system -f system-configuration.nix -i -A systemConfiguration
$ /nix/var/nix/profiles/system/bin/switch-to-configuration

View File

@ -1,259 +0,0 @@
{ system ? __currentSystem
, autoDetectRootDevice ? false
, rootDevice ? ""
, rootLabel ? ""
, stage2Init
, readOnlyRoot
}:
rec {
pkgs = import ./pkgs/top-level/all-packages.nix {inherit system;};
pkgsDiet = import ./pkgs/top-level/all-packages.nix {
inherit system;
bootStdenv = pkgs.useDietLibC pkgs.stdenv;
};
pkgsStatic = import ./pkgs/top-level/all-packages.nix {
inherit system;
bootStdenv = pkgs.makeStaticBinaries pkgs.stdenv;
};
stdenvLinuxStuff = import ./pkgs/stdenv/linux {
system = pkgs.stdenv.system;
allPackages = import ./pkgs/top-level/all-packages.nix;
};
nix = pkgs.nixUnstable; # we need the exportReferencesGraph feature
# Splash configuration.
splashThemes = import ./splash-themes.nix {
inherit (pkgs) fetchurl;
};
# Determine the set of modules that we need to mount the root FS.
modulesClosure = import ./modules-closure.nix {
inherit (pkgs) stdenv kernel module_init_tools;
rootModules = ["ide-cd" "ide-disk" "ide-generic"];
};
# 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.
extraUtils = pkgs.stdenv.mkDerivation {
name = "extra-utils";
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
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
cp $splashutils/bin/splash_helper $out/bin
nuke-refs $out/bin/*
";
buildInputs = [pkgs.nukeReferences];
inherit (pkgsStatic) utillinux;
inherit (pkgs) splashutils;
e2fsprogs = pkgs.e2fsprogsDiet;
};
# The init script of boot stage 1 (loading kernel modules for
# mounting the root FS).
bootStage1 = import ./boot-stage-1.nix {
inherit (pkgs) genericSubstituter;
inherit (pkgsDiet) module_init_tools;
inherit extraUtils;
inherit autoDetectRootDevice rootDevice rootLabel;
inherit stage2Init;
modules = modulesClosure;
shell = stdenvLinuxStuff.bootstrapTools.bash;
staticTools = stdenvLinuxStuff.staticTools;
};
# The closure of the init script of boot stage 1 is what we put in
# the initial RAM disk.
initialRamdisk = import ./make-initrd.nix {
inherit (pkgs) stdenv cpio;
contents = [
{ object = bootStage1;
symlink = "/init";
}
{ object = extraUtils;
suffix = "/bin/splash_helper";
symlink = "/sbin/splash_helper";
}
{ object = import ./helpers/unpack-theme.nix {
inherit (pkgs) stdenv;
theme = splashThemes.splashScreen;
};
symlink = "/etc/splash";
}
];
};
# The installer.
nixosInstaller = import ./installer.nix {
inherit (pkgs) stdenv genericSubstituter;
inherit nix;
shell = pkgs.bash + "/bin/sh";
};
# The services (Upstart) configuration for the system.
upstartJobs = import ./upstart-jobs/gather.nix {
inherit (pkgs) stdenv;
jobs = map makeJob [
# Syslogd.
(import ./upstart-jobs/syslogd.nix {
inherit (pkgs) sysklogd;
})
# Hardware scan; loads modules for PCI devices.
(import ./upstart-jobs/hardware-scan.nix {
inherit (pkgs) kernel module_init_tools;
})
# Network interfaces.
(import ./upstart-jobs/network-interfaces.nix {
inherit (pkgs) nettools kernel module_init_tools;
})
# DHCP client.
(import ./upstart-jobs/dhclient.nix {
dhcp = pkgs.dhcpWrapper;
})
# SSH daemon.
(import ./upstart-jobs/sshd.nix {
inherit (pkgs) openssh;
})
# Transparent TTY backgrounds.
(import ./upstart-jobs/tty-backgrounds.nix {
inherit (pkgs) stdenv splashutils;
backgrounds = splashThemes.ttyBackgrounds;
})
# Handles the maintenance/stalled event (single-user shell).
(import ./upstart-jobs/maintenance-shell.nix {
inherit (pkgs) bash;
})
# Ctrl-alt-delete action.
(import ./upstart-jobs/ctrl-alt-delete.nix)
]
# Handles the reboot/halt events.
++ (map
(event: makeJob (import ./upstart-jobs/halt.nix {
inherit (pkgs) bash;
inherit event;
}))
["reboot" "halt" "system-halt" "power-off"]
)
# The terminals on ttyX.
++ (map
(ttyNumber: makeJob (import ./upstart-jobs/mingetty.nix {
mingetty = pkgs.mingettyWrapper;
inherit ttyNumber;
}))
[1 2 3 4 5 6]
)
# For the builtin logd job.
++ [pkgs.upstart];
};
makeJob = import ./upstart-jobs/make-job.nix {
inherit (pkgs) stdenv;
};
# The init script of boot stage 2, which is supposed to do
# everything else to bring up the system.
bootStage2 = import ./boot-stage-2.nix {
inherit (pkgs) genericSubstituter coreutils findutils
utillinux kernel udev upstart;
inherit upstartJobs;
shell = pkgs.bash + "/bin/sh";
# Additional stuff; add whatever you want here.
path = [
pkgs.bash
pkgs.bzip2
pkgs.cpio
pkgs.curl
pkgs.e2fsprogs
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
pkgs.rsync
pkgs.shadowutils
pkgs.strace
pkgs.sysklogd
# pkgs.vim
nix
nixosInstaller
];
inherit readOnlyRoot;
hostName = config.get ["networking" "hostname"];
};
lib = import ./pkgs/lib;
config = rec {
# The user configuration.
config = {
networking = {
hostname = "vindaloo";
};
};
# 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);
};
}

View File

@ -1,147 +0,0 @@
#! @shell@
fail() {
# If starting stage 2 failed, start an interactive shell.
echo "Stage 2 failed, starting emergency shell..."
exec @shell@
}
# Print a greeting.
echo
echo "<<< NixOS Stage 1 >>>"
echo
# Set the PATH.
export PATH=/empty
for i in @path@; do
PATH=$PATH:$i/bin
if test -e $i/sbin; then
PATH=$PATH:$i/sbin
fi
done
# Mount special file systems.
mkdir -p /etc # to shut up mount
touch /etc/fstab # idem
mkdir -p /proc
mount -t proc none /proc
mkdir -p /sys
mount -t sysfs none /sys
# Process the kernel command line.
stage2Init=@stage2Init@
for o in $(cat /proc/cmdline); do
case $o in
init=*)
set -- $(IFS==; echo $o)
stage2Init=$2
;;
debugtrace)
# Show each command.
set -x
;;
debug1)
fail
;;
esac
done
# Create device nodes in /dev.
source @makeDevices@
# Load some kernel modules.
export MODULE_DIR=@modules@/lib/modules/
modprobe ide-generic
modprobe ide-disk
modprobe ide-cd
# Try to find and mount the root device.
mkdir /mnt
mkdir /mnt/root
echo "mounting the root device..."
if test -n "@autoDetectRootDevice@"; then
# Look for the root device by label.
echo "probing for the NixOS installation CD..."
for i in /sys/devices/*/*/media; do
if test "$(cat $i)" = "cdrom"; then
# Hopefully `drivename' matches the device created in /dev.
devName=/dev/$(cat $(dirname $i)/drivename)
echo " in $devName..."
if mount -n -o ro -t iso9660 $devName /mnt/root; then
if test -e "/mnt/root/@rootLabel@"; then
found=1
break
fi
umount /mnt/root
fi
fi
done
if test -z "$found"; then
echo "CD not found!"
fail
fi
else
# Hard-coded root device.
rootDevice="@rootDevice@"
# Check the root device.
fsck -C -a "$rootDevice"
fsckResult=$?
if test $(($fsckResult | 2)) = $fsckResult; then
echo "fsck finished, rebooting..."
sleep 3
# reboot -f -d !!! don't have reboot yet
fail
fi
if test $(($fsckResult | 4)) = $fsckResult; then
echo "$rootDevice has unrepaired errors, please fix them manually."
fail
fi
if test $fsckResult -ge 8; then
echo "fsck on $rootDevice failed."
fail
fi
# Mount read-writable.
mount -n -o rw "$rootDevice" /mnt/root || fail
fi
# Start stage 2.
# !!! Note: we can't use pivot_root here (the kernel gods have
# decreed), but we could use run-init from klibc, which deletes all
# files in the initramfs, remounts the target root on /, and chroots.
cd /mnt/root
mount --move . /
umount /proc # cleanup
umount /sys
echo "INIT = $stage2Init"
if test -z "$stage2Init"; then fail; fi
exec chroot . $stage2Init
fail

View File

@ -1,43 +0,0 @@
# This Nix expression builds the script that performs the first stage
# of booting the system: it loads the modules necessary to mount the
# root file system, then calls /init in the root file system to start
# the second boot stage. The closure of the result of this expression
# is supposed to be put into an initial RAM disk (initrd).
{ genericSubstituter, shell, staticTools
, module_init_tools, extraUtils, modules
, # Whether to find root device automatically using its label.
autoDetectRootDevice
, # If not scanning, the root must be specified explicitly.
rootDevice
# If scanning, we need a disk label.
, rootLabel
, # The path of the stage 2 init to call once we've mounted the root
# device.
stage2Init ? "/init"
}:
assert !autoDetectRootDevice -> rootDevice != "";
assert autoDetectRootDevice -> rootLabel != "";
genericSubstituter {
src = ./boot-stage-1-init.sh;
isExecutable = true;
inherit shell modules;
inherit autoDetectRootDevice rootDevice rootLabel;
path = [
staticTools
module_init_tools
extraUtils
];
makeDevices = ./make-devices.sh;
# We only want the path of the stage 2 init, we don't want it as a
# dependency (since then it the stage 2 init would end up in the
# initrd).
stage2Init = toString stage2Init; # !!! doesn't work
}

View File

@ -1,168 +0,0 @@
#! @shell@
# !!! copied from stage 1; remove duplication
# Print a greeting.
echo
echo "<<< NixOS Stage 2 >>>"
echo
# Set the PATH.
export PATH=/empty
for i in @path@; do
PATH=$PATH:$i/bin
if test -e $i/sbin; then
PATH=$PATH:$i/sbin
fi
done
# Mount special file systems.
needWritableDir() {
if test -n "@readOnlyRoot@"; then
mount -t tmpfs -o "mode=$2" none $1 $3
else
mkdir -m $2 -p $1
fi
}
needWritableDir /etc 0755 -n # to shut up mount
test -e /etc/fstab || touch /etc/fstab # idem
mount -n -t proc none /proc
cat /proc/mounts > /etc/mtab
# Process the kernel command line.
for o in $(cat /proc/cmdline); do
case $o in
debugtrace)
# Show each command.
set -x
;;
debug2)
echo "Debug shell called from @out@"
exec @shell@
;;
S|s|single)
# !!! argh, can't pass a startup event to Upstart yet.
exec @shell@
;;
esac
done
# More special file systems, initialise required directories.
mount -t sysfs none /sys
mount -t tmpfs -o "mode=0755" none /dev
needWritableDir /tmp 01777
needWritableDir /var 0755
needWritableDir /nix/var 0755
mkdir -m 0755 -p /nix/var/nix/db
mkdir -m 0755 -p /nix/var/nix/gcroots
mkdir -m 0755 -p /nix/var/nix/temproots
mkdir -m 0755 -p /var/log
ln -sf /nix/var/nix/profiles /nix/var/nix/gcroots/
# Ensure that the module tools can find the kernel modules.
export MODULE_DIR=@kernel@/lib/modules/
# Miscellaneous cleanup.
rm -rf /var/run
mkdir -m 0755 -p /var/run
echo -n > /var/run/utmp # must exist
chmod 664 /var/run/utmp
# Start udev.
udevd --daemon
# Let udev create device nodes for all modules that have already been
# loaded into the kernel (or for which support is built into the
# kernel).
udevtrigger
udevsettle # wait for udev to finish
# Necessary configuration for syslogd.
echo "*.* /dev/tty10" > /etc/syslog.conf
echo "syslog 514/udp" > /etc/services # required, even if we don't use it
# login/su absolutely need this.
test -e /etc/login.defs || touch /etc/login.defs
# Enable a password-less root login.
if ! test -e /etc/passwd; then
echo "root::0:0:root:/:@shell@" > /etc/passwd
fi
if ! test -e /etc/group; then
echo "root:*:0" > /etc/group
fi
# We need "localhost" (!!! destructive hack for NIXOS-41).
echo "127.0.0.1 localhost" > /etc/hosts
echo "hosts: files dns" > /etc/nsswitch.conf
# Set up the Upstart jobs.
export UPSTART_CFG_DIR=/etc/event.d
rm -f /etc/event.d
ln -sf @upstartJobs@/etc/event.d /etc/event.d
# Show a nice greeting on each terminal.
cat > /etc/issue <<EOF
<<< Welcome to NixOS (\m) - Kernel \r (\l) >>>
EOF
# Additional path for the interactive shell.
for i in @extraPath@; do
PATH=$PATH:$i/bin
if test -e $i/sbin; then
PATH=$PATH:$i/sbin
fi
done
cat > /etc/profile <<EOF
export PATH=$PATH
export MODULE_DIR=$MODULE_DIR
source $(dirname $(type -tp nix-env))/../etc/profile.d/nix.sh
alias ll="ls -l"
if test -f /etc/profile.local; then
source /etc/profile.local
fi
EOF
# Set the host name.
hostname @hostName@
# Start an interactive shell.
#exec @shell@
# Start Upstart's init.
exec @upstart@/sbin/init -v

View File

@ -1,27 +0,0 @@
{ genericSubstituter, shell, coreutils, findutils
, utillinux, kernel, udev, upstart
, path ? []
, # Whether the root device is root only. If so, we'll mount a
# ramdisk on /etc, /var and so on.
readOnlyRoot
, # The Upstart job configuration.
upstartJobs
, hostName
}:
genericSubstituter {
src = ./boot-stage-2-init.sh;
isExecutable = true;
inherit shell kernel upstart readOnlyRoot upstartJobs hostName;
path = [
coreutils
findutils
utillinux
udev
upstart
];
extraPath = path;
}

View File

@ -1,52 +0,0 @@
#! @bash@/bin/sh -e
default=$1
if test -z "$1"; then
echo "Syntax: grub-menu-builder.sh <DEFAULT-CONFIG>"
exit 1
fi
target=/boot/grub/menu.lst
tmp=$target.tmp
cat > $tmp << GRUBEND
# Automatically generated. DO NOT EDIT THIS FILE!
default=0
timeout=5
GRUBEND
addEntry() {
name="$1"
path="$2"
cat >> $tmp << GRUBEND
title $name
GRUBEND
#cat $path/menu.lst >> $tmp
grep -v "title \|default=\|timeout=" < $path/menu.lst >> $tmp
}
if test -n "$tmp"; then
addEntry "NixOS - Default" $default
fi
# Add all generations of the system profile to the menu, in reverse
# (most recent to least recent) order.
for generation in $(
(cd /nix/var/nix/profiles && ls -d system-*-link) \
| sed 's/system-\([0-9]\+\)-link/\1/' \
| sort -n -r); do
echo $generation
link=/nix/var/nix/profiles/system-$generation-link
date=$(stat --printf="%y\n" $link | sed 's/\..*//')
addEntry "NixOS - Configuration $generation ($date)" $link
done
cp $tmp $target

View File

@ -1,7 +0,0 @@
{stdenv, theme}:
stdenv.mkDerivation {
name = "theme";
builder = ./unpack-theme.sh;
inherit theme;
}

View File

@ -1,18 +0,0 @@
source $stdenv/setup
ensureDir $out
tar xvfj $theme -C $out
themeName=$(cd $out && ls)
for i in $out/$themeName/config/*.cfg; do
echo "converting $i"
# Rewrite /etc paths. Also, the file names
# config/bootsplash-<RES>.cfg should be <RES>.cfg.
sed "s^/etc/bootsplash/themes^$out^g" < $i > $out/$themeName/$(basename $i | sed 's^.*-^^')
done
rm $out/$themeName/config/*.cfg
ln -s $themeName $out/default

View File

@ -1,17 +0,0 @@
{ stdenv, genericSubstituter, shell, nix
}:
genericSubstituter {
src = ./installer.sh;
dir = "bin";
isExecutable = true;
inherit shell nix;
pathsFromGraph = ./paths-from-graph.sh;
nixClosure = stdenv.mkDerivation {
name = "closure";
exportReferencesGraph = ["refs" nix];
builder = builtins.toFile "builder.sh" "source $stdenv/setup; cp refs $out";
};
}

View File

@ -1,132 +0,0 @@
#! @shell@
# Syntax: installer.sh <DEVICE> <NIX-EXPR>
# (e.g., installer.sh /dev/hda1 ./my-machine.nix)
# - mount target device
# - make Nix store etc.
# - copy closure of rescue env to target device
# - register validity
# - start the "target" installer in a chroot to the target device
# * do a nix-pull
# * nix-env -p system-profile -i <nix-expr for the configuration>
# * run hook scripts provided by packages in the configuration?
# - install/update grub
set -e
targetDevice="$1"
nixExpr="$2"
if test -z "$targetDevice" -o -z "$nixExpr"; then
echo "Syntax: installer.sh <targetDevice> <nixExpr>"
exit 1
fi
nixExpr=$(readlink -f "$nixExpr")
# Make sure that the target device isn't mounted.
umount "$targetDevice" 2> /dev/null || true
# Check it.
fsck -n "$targetDevice"
# Mount the target device.
mountPoint=/tmp/inst-mnt
mkdir -p $mountPoint
mount "$targetDevice" $mountPoint
mkdir -m 0755 -p $mountPoint/dev $mountPoint/proc $mountPoint/sys $mountPoint/mnt
mount --rbind / $mountPoint/mnt
mount --bind /dev $mountPoint/dev
mount --bind /proc $mountPoint/proc
mount --bind /sys $mountPoint/sys
cleanup() {
for i in $(grep -F "$mountPoint" /proc/mounts \
| perl -e 'while (<>) { /^\S+\s+(\S+)\s+/; print "$1\n"; }' \
| sort -r);
do
umount $i
done
}
trap "cleanup" EXIT
mkdir -m 01777 -p $mountPoint/tmp
mkdir -m 0755 -p $mountPoint/var
# Create the necessary Nix directories on the target device, if they
# don't already exist.
mkdir -m 0755 -p \
$mountPoint/nix/store \
$mountPoint/nix/var/nix/gcroots \
$mountPoint/nix/var/nix/temproots \
$mountPoint/nix/var/nix/manifests \
$mountPoint/nix/var/nix/userpool \
$mountPoint/nix/var/nix/profiles \
$mountPoint/nix/var/nix/db \
$mountPoint/nix/var/log/nix/drvs
# Get the store paths to copy from the references graph.
storePaths=$(@shell@ @pathsFromGraph@ @nixClosure@)
# Copy Nix to the Nix store on the target device.
echo "copying Nix to $targetDevice...."
for i in $storePaths; do
echo " $i"
rsync -a $i $mountPoint/nix/store/
done
# Register the paths in the Nix closure as valid. This is necessary
# to prevent them from being deleted the first time we install
# something. (I.e., Nix will see that, e.g., the glibc path is not
# valid, delete it to get it out of the way, but as a result nothing
# will work anymore.)
chroot $mountPoint @nix@/bin/nix-store --register-validity < @nixClosure@
# Create the required /bin/sh symlink; otherwise lots of things
# (notably the system() function) won't work.
mkdir -m 0755 -p $mountPoint/bin
ln -sf $(type -tp sh) $mountPoint/bin/sh
# Enable networking in the chroot.
mkdir -m 0755 -p $mountPoint/etc
cp /etc/resolv.conf $mountPoint/etc/
# Do a nix-pull to speed up building.
nixpkgsURL=http://nix.cs.uu.nl/dist/nix/nixpkgs-0.11pre6984
chroot $mountPoint @nix@/bin/nix-pull $nixpkgsURL/MANIFEST
# Build the specified Nix expression in the target store and install
# it into the system configuration profile.
#rm -rf $mountPoint/scratch
#mkdir $mountPoint/scratch
#curl $nixpkgsURL/nixexprs.tar.bz2 | tar xj -C $mountPoint/scratch
#nixpkgsName=$(cd $mountPoint/scratch && ls)
chroot $mountPoint @nix@/bin/nix-env \
-p /nix/var/nix/profiles/system \
-f "/mnt/$nixExpr" -i -A systemConfiguration
# Grub needs a mtab.
echo "$targetDevice / somefs rw 0 0" > $mountPoint/etc/mtab
# Switch to the new system configuration. This will install Grub with
# a menu default pointing at the kernel/initrd/etc of the new
# configuration.
echo "finalising the installation..."
NIXOS_INSTALL_GRUB=1 chroot $mountPoint /nix/var/nix/profiles/system/bin/switch-to-configuration

View File

@ -1,6 +0,0 @@
default linux
prompt 1
timeout 60
label linux
kernel vmlinuz
append initrd=initrd selinux=0 apm=on acpi=on

View File

@ -1,53 +0,0 @@
mknod -m 0600 /dev/ttyS0 c 4 64
mknod -m 0600 /dev/ttyS1 c 4 65
mknod -m 0600 /dev/ttyS2 c 4 66
mknod -m 0600 /dev/ttyS3 c 4 67
# base UNIX devices
mknod -m 0600 /dev/mem c 1 1
mknod -m 0666 /dev/null c 1 3
mknod -m 0666 /dev/zero c 1 5
# tty
mknod -m 0600 /dev/tty c 5 0
if ! test -e /dev/console; then
mknod -m 0600 /dev/console c 5 1
fi
for i in $(seq 0 10); do
mknod -m 0600 /dev/tty$i c 4 $i
done
mkdir -m 0755 /dev/pts
mknod -m 0666 /dev/ptmx c 5 2
# random
mknod -m 0644 /dev/random c 1 8
mknod -m 0644 /dev/urandom c 1 9
mknod -m 0660 /dev/hda b 3 0
mknod -m 0660 /dev/hda1 b 3 1
mknod -m 0660 /dev/hda2 b 3 2
mknod -m 0660 /dev/hda3 b 3 3
mknod -m 0660 /dev/hdb b 3 64
mknod -m 0660 /dev/hdb1 b 3 65
mknod -m 0660 /dev/hdb2 b 3 66
mknod -m 0660 /dev/hdb3 b 3 67
mknod -m 0660 /dev/hdc b 22 0
mknod -m 0660 /dev/hdc1 b 22 1
mknod -m 0660 /dev/hdc2 b 22 2
mknod -m 0660 /dev/hdc3 b 22 3
mknod -m 0660 /dev/hdd b 22 64
mknod -m 0660 /dev/hdd1 b 22 65
mknod -m 0660 /dev/hdd2 b 22 66
mknod -m 0660 /dev/hdd3 b 22 67
#mknod -m 0660 /dev/sda b 8 0
#mknod -m 0660 /dev/sda1 b 8 1
#mknod -m 0660 /dev/sda2 b 8 2
#mknod -m 0660 /dev/sda3 b 8 3
mknod -m 0600 /dev/initctl p

View File

@ -1,31 +0,0 @@
# Create an initial ramdisk containing the closure of the specified
# file system objects. An initial ramdisk is used during the initial
# stages of booting a Linux system. It is loaded by the boot loader
# along with the kernel image. It's supposed to contain everything
# (such as kernel modules) necessary to allow us to mount the root
# file system. Once the root file system is mounted, the `real' boot
# script can be called.
#
# An initrd is really just a gzipped cpio archive.
#
# Symlinks are created for each top-level file system object. E.g.,
# `contents = {object = ...; symlink = /init;}' is a typical
# argument.
{stdenv, cpio, contents}:
stdenv.mkDerivation {
name = "initrd";
builder = ./make-initrd.sh;
buildInputs = [cpio];
# !!! should use XML.
objects = map (x: x.object) contents;
symlinks = map (x: x.symlink) contents;
suffices = map (x: if x ? suffix then x.suffix else "none") contents;
# For obtaining the closure of `contents'.
exportReferencesGraph =
map (x: [("closure-" + baseNameOf x.symlink) x.object]) contents;
pathsFromGraph = ./paths-from-graph.sh;
}

View File

@ -1,42 +0,0 @@
source $stdenv/setup
set -o pipefail
objects=($objects)
symlinks=($symlinks)
suffices=($suffices)
mkdir root
# Needed for splash_helper, which gets run before init.
mkdir root/dev
mkdir root/sys
mkdir root/proc
for ((n = 0; n < ${#objects[*]}; n++)); do
object=${objects[$n]}
symlink=${symlinks[$n]}
suffix=${suffices[$n]}
if test "$suffix" = none; then suffix=; fi
# Get the paths in the closure of `object'.
closure=closure-$(basename $symlink)
if ! test -e $closure; then
echo 'Your Nix installation is too old! Upgrade to nix-0.11pre7038 or newer.'
exit 1
fi
storePaths=$($SHELL $pathsFromGraph $closure)
# Paths in cpio archives *must* be relative, otherwise the kernel
# won't unpack 'em.
(cd root && cp -prd --parents $storePaths .)
mkdir -p $(dirname root/$symlink)
ln -s $object$suffix root/$symlink
done
# Put the closure in a gzipped cpio archive.
ensureDir $out
(cd root && find * -print0 | cpio -ov -H newc --null | gzip -9 > $out/initrd)

View File

@ -1,44 +0,0 @@
{ stdenv, cdrtools
# The file name of the resulting ISO image.
, isoName ? "cd.iso"
, # The files and directories to be placed in the ISO file system.
# This is a list of attribute sets {source, target} where `source'
# is the file system object (regular file or directory) to be
# grafted in the file system at path `target'.
contents
/*
, # In addition to `contents', the closure of the store paths listed
# in `packages' are also placed in the file system.
packages ? []
*/
, # `init' should be a store path, the closure of which is added to
# the image, just like `packages'. However, in addition, a symlink
# `/init' to `init' will be created.
init ? null
# Whether this should be an El-Torito bootable CD.
, bootable ? false
# The path (in the ISO file system) of the boot image.
, bootImage ? ""
}:
assert bootable -> bootImage != "";
stdenv.mkDerivation {
name = "iso9660-image";
builder = ./make-iso9660-image.sh;
buildInputs = [cdrtools];
inherit isoName init bootable bootImage;
sources = map ({source, target}: source) contents;
targets = map ({source, target}: target) contents;
# For obtaining the closure of `init'.
exportReferencesGraph = ["init-closure" init];
pathsFromGraph = ./paths-from-graph.sh;
}

View File

@ -1,31 +0,0 @@
source $stdenv/setup
if test -n "$bootable"; then
bootFlags="-b $bootImage -c boot.cat -no-emul-boot -boot-load-size 4"
fi
graftList=
sources_=($sources)
targets_=($targets)
for ((i = 0; i < ${#targets_[@]}; i++)); do
graftList="$graftList ${targets_[$i]}=$(readlink -f ${sources_[$i]})"
done
storePaths=$($SHELL $pathsFromGraph ./init-closure)
for i in $storePaths; do
graftList="$graftList ${i:1}=$i"
done
if test -n "$init"; then
ln -s $init init
graftList="$graftList init=init"
fi
# !!! -f is a quick hack.
ensureDir $out/iso
mkisofs -r -J -o $out/iso/$isoName $bootFlags \
-graft-points $graftList
ensureDir $out/nix-support
echo $system > $out/nix-support/system

View File

@ -1,13 +0,0 @@
# Given a kernel build (with modules in $kernel/lib/modules/VERSION),
# produce a module tree in $out/lib/modules/VERSION that contains only
# the modules identified by `rootModules', plus their dependencies.
# Also generate an appropriate modules.dep.
{stdenv, kernel, rootModules, module_init_tools}:
stdenv.mkDerivation {
name = kernel.name + "-shrunk";
builder = ./modules-closure.sh;
inherit kernel rootModules module_init_tools;
allowedReferences = ["out"];
}

View File

@ -1,37 +0,0 @@
source $stdenv/setup
set -o pipefail
PATH=$module_init_tools/sbin:$PATH
version=$(cd $kernel/lib/modules && ls -d *)
echo "kernel version is $version"
export MODULE_DIR=$kernel/lib/modules/
# Determine the dependencies of each root module.
closure=
for module in $rootModules; do
echo "root module: $module"
deps=$(modprobe --set-version "$version" --show-depends "$module" \
| sed 's/^insmod //')
for i in $deps; do echo $i; done
closure="$closure $deps"
done
# Remove duplicates.
closure=$(for i in $closure; do echo $i; done | sort | uniq)
echo "closure:"
ensureDir $out
for module in $closure; do
echo $module
target=$(echo $module | sed "s^$kernel^$out^")
mkdir -p $(dirname $target)
cp $module $target
grep "^$module" $kernel/lib/modules/$version/modules.dep \
| sed "s^$kernel^$out^g" \
>> $out/lib/modules/$version/modules.dep
done

View File

@ -1,97 +0,0 @@
[
{
name = ["networking" "hostname"];
default = "nixos";
description = "The name of the machine.";
}
{
name = ["networking" "useDHCP"];
default = true;
description = "
Whether to use DHCP to obtain an IP adress and other
configuration for all network interfaces that are not manually
configured.
";
}
{
name = ["networking" "interfaces"];
default = [];
example = [
{ interface = "eth0";
ipAddress = "131.211.84.78";
netmask = "255.255.255.128";
gateway = "131.211.84.1";
}
];
description = "
The configuration for each network interface. If
<option>networking.useDHCP</option> is true, then each interface
not listed here will be configured using DHCP.
";
}
{
name = ["filesystems" "mountPoints"];
example = [
{ device = "/dev/hda2";
mountPoint = "/";
}
];
description = "
The file systems to be mounted by NixOS. It must include an
entry for the root directory (<literal>mountPoint =
\"/\"</literal>). This is the file system on which NixOS is (to
be) installed..
";
}
{
name = ["services" "syslogd" "tty"];
default = 10;
description = "
The tty device on which syslogd will print important log
messages.
";
}
{
name = ["services" "mingetty" "ttys"];
default = [1 2 3 4 5 6];
description = "
The list of tty (virtual console) devices on which to start a
login prompt.
";
}
{
name = ["services" "mingetty" "waitOnMounts"];
default = false;
description = "
Whether the login prompts on the virtual consoles will be
started before or after all file systems have been mounted. By
default we don't wait, but if for example your /home is on a
separate partition, you may want to turn this on.
";
}
{
name = ["services" "sshd" "enable"];
default = false;
description = "
Whether to enable the Secure Shell daemon, which allows secure
remote logins.
";
}
{
name = ["services" "sshd" "forwardX11"];
default = false;
description = "
Whether to enable sshd to forward X11 connections.
";
}
]

View File

@ -1,10 +0,0 @@
graph="$1"
while read storePath; do
echo $storePath
read deriver
read count
for ((i = 0; i < $count; i++)); do
read ref
done
done < $graph

View File

@ -1,101 +0,0 @@
let
# The label used to identify the installation CD.
cdromLabel = "NIXOS";
in
# Build boot scripts for the CD that find the CD-ROM automatically.
with import ./boot-environment.nix {
autoDetectRootDevice = true;
rootLabel = cdromLabel;
stage2Init = "/init";
readOnlyRoot = true;
};
rec {
inherit nixosInstaller bootStage1 upstartJobs; # !!! debug
# Since the CD is read-only, the mount points must be on disk.
cdMountPoints = pkgs.stdenv.mkDerivation {
name = "mount-points";
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
ensureDir $out
cd $out
mkdir proc sys tmp etc dev var mnt nix nix/var
touch $out/${cdromLabel}
";
};
# We need a copy of the Nix expressions for Nixpkgs and NixOS on the
# CD. We put them in a tarball because accessing that many small
# files from a slow device like a CD-ROM takes too long.
makeTarball = tarName: input: pkgs.stdenv.mkDerivation {
name = "tarball";
inherit tarName input;
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
ensureDir $out
(cd $input && tar cvfj $out/$tarName . \\
--exclude '*~' --exclude '.svn' \\
--exclude 'pkgs' --exclude 'result')
";
};
# Put the current directory in the tarball. !!! This gives us a lot
# of crap (like .svn if this is a working copy). An "svn export"
# would be better, but that's impure.
nixosTarball = makeTarball "nixos.tar.bz2" ./.;
nixpkgsTarball = pkgs.fetchurl {
url = http://nix.cs.uu.nl/dist/nix/nixpkgs-0.11pre7087/nixpkgs-0.11pre7087.tar.bz2;
md5 = "c5840fcd049d75e00ad856ecbbef6857";
};
# Create an ISO image containing the isolinux boot loader, the
# kernel, the initrd produced above, and the closure of the stage 2
# init.
rescueCD = import ./make-iso9660-image.nix {
inherit (pkgs) stdenv cdrtools;
isoName = "nixos.iso";
contents = [
{ source = pkgs.syslinux + "/lib/syslinux/isolinux.bin";
target = "isolinux/isolinux.bin";
}
{ source = ./isolinux.cfg;
target = "isolinux/isolinux.cfg";
}
{ source = pkgs.kernel + "/vmlinuz";
target = "isolinux/vmlinuz";
}
{ source = initialRamdisk + "/initrd";
target = "isolinux/initrd";
}
{ source = cdMountPoints;
target = "/";
}
{ source = nixosTarball + "/" + nixosTarball.tarName;
target = "/" + nixosTarball.tarName;
}
{ source = nixpkgsTarball;
target = "/nixpkgs.tar.bz2";
}
];
init = bootStage2;
bootable = true;
bootImage = "isolinux/isolinux.bin";
};
}

View File

@ -1,58 +0,0 @@
{fetchurl}:
rec {
# Some themes.
themeBabyTux = fetchurl {
url = http://www.bootsplash.de/files/themes/Theme-BabyTux.tar.bz2;
md5 = "a6d89d1c1cff3b6a08e2f526f2eab4e0";
};
themeFrozenBubble = fetchurl {
url = http://www.bootsplash.de/files/themes/Theme-FrozenBubble.tar.bz2;
md5 = "da49f04988ab04b7e0de117b0d25061a";
};
themePativo = fetchurl { # Yeah!
url = http://www.bootsplash.de/files/themes/Theme-Pativo.tar.bz2;
md5 = "9e13beaaadf88d43a5293e7ab757d569";
};
themeGNU = fetchurl {
url = http://www.bootsplash.de/files/themes/Theme-GNU.tar.bz2;
md5 = "61969309d23c631e57b0a311102ef034";
};
# The splash screen.
splashScreen = themeBabyTux;
# The themes to use for each tty. For each tty except the first
# entry in the list, you can omit `theme' to get the same theme as
# the first one. If a tty does not appear, it doesn't get a
# theme (i.e., it will keep a black background).
ttyBackgrounds = [
{ tty = 1;
theme = themeBabyTux;
}
{ tty = 2;
}
{ tty = 3;
theme = themeGNU;
}
{ tty = 4;
theme = themeGNU;
}
{ tty = 5;
theme = themePativo;
}
{ tty = 10; # logging console
theme = themeGNU;
}
];
}

View File

@ -1,55 +0,0 @@
let
# The root device.
rootDevice = "/dev/hda1";
# The device on which GRUB should be installed (leave empty if you
# don't want GRUB to be installed).
grubDevice = "/dev/hda";
# Build boot scripts.
bootEnv = import ./boot-environment.nix {
autoDetectRootDevice = false;
inherit rootDevice;
stage2Init = ""; # Passed on the command line via Grub.
readOnlyRoot = false;
};
# Extra kernel command line arguments.
extraKernelParams = [
"selinux=0"
"apm=on"
"acpi=on"
"vga=0x317"
"console=tty1"
"splash=verbose"
];
in
with bootEnv;
rec {
systemConfiguration = pkgs.stdenv.mkDerivation {
name = "system-configuration";
builder = ./system-configuration.sh;
inherit (pkgs) grub coreutils gnused gnugrep diffutils;
inherit grubDevice;
inherit bootStage2;
inherit grubMenuBuilder;
kernel = pkgs.kernel + "/vmlinuz";
initrd = initialRamdisk + "/initrd";
inherit extraKernelParams;
};
grubMenuBuilder = pkgs.genericSubstituter {
src = ./grub-menu-builder.sh;
isExecutable = true;
inherit (pkgs) bash;
};
}

View File

@ -1,31 +0,0 @@
source $stdenv/setup
ensureDir $out
ln -s $kernel $out/kernel
ln -s $grub $out/grub
ln -s $bootStage2 $out/init
ln -s $initrd $out/initrd
echo "$extraKernelParams" > $out/kernel-params
cat > $out/menu.lst << GRUBEND
kernel $kernel init=$bootStage2 $extraKernelParams
initrd $initrd
GRUBEND
ensureDir $out/bin
cat > $out/bin/switch-to-configuration <<EOF
#! $SHELL
set -e
export PATH=$coreutils/bin:$gnused/bin:$gnugrep/bin:$diffutils/bin
if test -n "$grubDevice"; then
mkdir -m 0700 -p /boot/grub
$grubMenuBuilder $out
if test "\$NIXOS_INSTALL_GRUB" = 1; then
$grub/sbin/grub-install "$grubDevice" --no-floppy --recheck
fi
fi
EOF
chmod +x $out/bin/switch-to-configuration

View File

@ -1,4 +0,0 @@
#! /bin/sh
set -e
nix-env -p /nix/var/nix/profiles/system -f system-configuration.nix -i -A systemConfiguration
/nix/var/nix/profiles/system/bin/switch-to-configuration

View File

@ -1,12 +0,0 @@
{
name = "ctrl-alt-delete";
job = "
on ctrlaltdel
script
shutdown -r now 'Ctrl-Alt-Delete pressed'
end script
";
}

View File

@ -1,43 +0,0 @@
{dhcp}:
{
name = "dhclient";
job = "
description \"DHCP client\"
start on network-interfaces/started
stop on network-interfaces/stop
script
# Determine the interface on which to start dhclient.
interfaces=
# !!! apparent race; operstate seems to have a slight delay, so
# if dhclient is started right after network-interfaces, we don't
# always see all the interfaces.
#for i in $(cd /sys/class/net && ls -d *); do
# if test \"$i\" != \"lo\" -a \"$(cat /sys/class/net/$i/operstate)\" != 'down'; then
# interfaces=\"$interfaces $i\"
# fi
#done
for i in $(ifconfig | grep '^[^ ]' | sed 's/ .*//'); do
if test \"$i\" != \"lo\"; then
interfaces=\"$interfaces $i\"
fi
done
if test -z \"$interfaces\"; then
echo 'No interfaces on which to start dhclient!'
exit 1
fi
mkdir -m 755 -p /var/state/dhcp
exec ${dhcp}/sbin/dhclient -d $interfaces
end script
";
}

View File

@ -1,19 +0,0 @@
# Create an etc/event.d directory containing symlinks to the
# specified list of Upstart job files.
{stdenv, jobs}:
stdenv.mkDerivation {
name = "upstart-jobs";
inherit jobs;
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
ensureDir $out/etc/event.d
for i in $jobs; do
if test -d $i; then
ln -s $i/etc/event.d/* $out/etc/event.d/
fi
done
";
}

View File

@ -1,41 +0,0 @@
{bash, event}:
assert event == "reboot"
|| event == "halt"
|| event == "system-halt"
|| event == "power-off";
{
name = "sys-" + event;
job = "
start on ${event}
script
exec < /dev/tty1 > /dev/tty1 2>&1
echo \"\"
echo \"<<< SYSTEM SHUTDOWN >>>\"
echo \"\"
# Do an initial sync just in case.
sync || true
# Unmount file systems.
umount -n -a || true
# Remount / read-only
mount -n -o remount,ro /dontcare / || true
# Final sync.
sync || true
# Right now all events above power off the system.
if test ${event} = reboot; then
exec reboot -f
else
exec halt -f -p
fi
end script
";
}

View File

@ -1,23 +0,0 @@
# !!! Don't like it that I have to pass the kernel here.
{kernel, module_init_tools}:
{
name = "hardware-scan";
job = "
start on startup
script
export MODULE_DIR=${kernel}/lib/modules/
# Try to load modules for all PCI devices.
for i in /sys/bus/pci/devices/*/modalias; do
echo \"Trying to load a module for $(basename $(dirname $i))...\"
${module_init_tools}/sbin/modprobe $(cat $i) || true
echo \"\"
done
end script
";
}

View File

@ -1,19 +0,0 @@
{bash}:
{
name = "maintenance-shell";
job = "
start on maintenance
start on stalled
script
exec < /dev/tty1 > /dev/tty1 2>&1
echo \"\"
echo \"<<< MAINTENANCE SHELL >>>\"
echo \"\"
exec ${bash}/bin/sh
end script
";
}

View File

@ -1,7 +0,0 @@
{stdenv}: job:
stdenv.mkDerivation {
inherit (job) name job;
builder = builtins.toFile "builder.sh"
"source $stdenv/setup; ensureDir $out/etc/event.d; echo \"$job\" > $out/etc/event.d/$name";
}

View File

@ -1,10 +0,0 @@
{mingetty, ttyNumber}:
{
name = "tty" + toString ttyNumber;
job = "
start on startup
stop on shutdown
respawn ${mingetty}/sbin/mingetty --noclear tty${toString ttyNumber}
";
}

View File

@ -1,36 +0,0 @@
# !!! Don't like it that I have to pass the kernel here.
{nettools, kernel, module_init_tools}:
{
name = "network-interfaces";
job = "
start on hardware-scan
stop on shutdown
start script
export MODULE_DIR=${kernel}/lib/modules/
${module_init_tools}/sbin/modprobe af_packet
for i in $(cd /sys/class/net && ls -d *); do
echo \"Bringing up network device $i...\"
${nettools}/sbin/ifconfig $i up || true
done
end script
# Hack: Upstart doesn't yet support what we want: a service that
# doesn't have a running process associated with it.
respawn sleep 10000
stop script
for i in $(cd /sys/class/net && ls -d *); do
echo \"Taking down network device $i...\"
${nettools}/sbin/ifconfig $i down || true
done
end script
";
}

View File

@ -1,32 +0,0 @@
{openssh}:
{
name = "sshd";
job = "
description \"SSH server\"
start on network-interfaces/started
stop on network-interfaces/stop
start script
mkdir -m 0555 -p /var/empty
mkdir -m 0755 -p /etc/ssh
echo 'X11Forwarding yes' > /etc/ssh/sshd_config
if ! test -f /etc/ssh/ssh_host_dsa_key; then
${openssh}/bin/ssh-keygen -t dsa -b 1024 -f /etc/ssh/ssh_host_dsa_key -N ''
fi
if ! grep -q '^sshd:' /etc/passwd; then
echo 'sshd:x:74:74:SSH privilege separation user:/var/empty:/noshell' >> /etc/passwd
fi
end script
respawn ${openssh}/sbin/sshd -D -h /etc/ssh/ssh_host_dsa_key -f /etc/ssh/sshd_config
";
}

View File

@ -1,10 +0,0 @@
{sysklogd}:
{
name = "syslogd";
job = "
start on startup
stop on shutdown
respawn ${sysklogd}/sbin/syslogd -n
";
}

View File

@ -1,37 +0,0 @@
source $stdenv/setup
ttys=($ttys)
themes=($themes)
ensureDir $out
default=
for ((n = 0; n < ${#ttys[*]}; n++)); do
tty=${ttys[$n]}
theme=${themes[$n]}
if test "$theme" = "default"; then
if test -z "$default"; then
echo "No default theme!"
exit 1
fi
theme=$default
fi
if test -z "$default"; then default=$theme; fi
echo "TTY $tty -> $theme"
themeName=$(cd $theme && ls | grep -v default)
ln -sf $theme/$themeName $out/$themeName
if test -e $out/$tty; then
echo "Multiple themes defined for the same TTY!"
exit 1
fi
ln -sf $themeName $out/$tty
done

View File

@ -1,52 +0,0 @@
{stdenv, splashutils, backgrounds}:
rec {
name = "tty-backgrounds";
unpackTheme = theme: import ../helpers/unpack-theme.nix {
inherit stdenv theme;
};
themesUnpacked = stdenv.mkDerivation {
name = "splash-themes";
builder = ./tty-backgrounds-combine.sh;
# !!! Should use XML here.
ttys = map (x: x.tty) backgrounds;
themes = map (x: if x ? theme then (unpackTheme x.theme) else "default") backgrounds;
};
job = "
start on hardware-scan
start script
rm -f /etc/splash
ln -s ${themesUnpacked} /etc/splash
# Critical: tell the kernel where to find splash_helper. It calls
# this program every time we switch between consoles.
echo ${splashutils}/bin/splash_helper > /proc/sys/kernel/fbsplash
# Set the theme for each console, as determined by
# tty-backgrounds-combine.sh above.
for tty in ${toString (map (x: x.tty) backgrounds)}; do
theme=$(readlink ${themesUnpacked}/$tty)
${splashutils}/bin/splash_util --tty $tty -c setcfg -t $theme || true
${splashutils}/bin/splash_util --tty $tty -c setpic -t $theme || true
${splashutils}/bin/splash_util --tty $tty -c on || true
done
end script
respawn sleep 10000 # !!! Hack
stop script
# Disable the theme on each console.
for tty in ${toString (map (x: x.tty) backgrounds)}; do
${splashutils}/bin/splash_util --tty $tty -c off || true
done
end script
";
}