* Scripts to set up and run the absolute minimal pure Nix
environment; that is, an operating system environment in which there is (essentially) only a store. The script `make-disk.sh' creates an ext2 disk image, creates a Nix store in it, and copies the closure of the bash package (from nixpkgs) to it. The script `run.sh' then starts bash in a UML virtual machine. The contents of the image after creation look like this: $ ls -l drwxr-xr-x 2 root root 1024 2004-02-14 19:13 dev lrwxrwxrwx 1 root root 61 2004-02-14 23:34 init -> /nix/store/e40873ece7a010752ad72b4262b23d28-bash-2.05b/bin/sh drwx------ 2 root root 12288 2004-02-14 19:13 lost+found drwxr-xr-x 4 root root 1024 2004-02-14 19:13 nix drwxr-xr-x 2 root root 1024 2004-02-14 19:13 proc drwxrwxrwt 2 root root 1024 2004-02-14 19:13 tmp The next step is to add all the other stuff that goes into a working system (coreutils, etc.). BTW, if you don't have `ls' you can still list directories by doing `echo *' :-) Nix itself should also be Nixified so that it can be put into the store. svn path=/nixu/trunk/; revision=783
This commit is contained in:
commit
e019265ec9
4
bootstrap.nix
Normal file
4
bootstrap.nix
Normal file
@ -0,0 +1,4 @@
|
||||
let {
|
||||
pkgs = import pkgs/system/i686-linux.nix;
|
||||
body = pkgs.bash;
|
||||
}
|
64
fill-disk.sh
Executable file
64
fill-disk.sh
Executable file
@ -0,0 +1,64 @@
|
||||
#! /bin/sh -e
|
||||
|
||||
initExpr=$1
|
||||
|
||||
make_dir() {
|
||||
mode=$1
|
||||
name=$2
|
||||
echo creating $name...
|
||||
if ! test -d $root/$name; then mkdir $root/$name; fi
|
||||
chmod $mode $root/$name
|
||||
}
|
||||
|
||||
root=/tmp/mnt
|
||||
|
||||
echo mounting...
|
||||
mount -t ext2 /dev/discs/disc0/disc $root
|
||||
|
||||
make_dir 00755 /dev
|
||||
make_dir 00755 /proc
|
||||
make_dir 01777 /tmp
|
||||
make_dir 00755 /nix
|
||||
make_dir 00755 /nix/store
|
||||
make_dir 00755 /nix/var
|
||||
make_dir 00755 /nix/var/nix
|
||||
make_dir 00755 /nix/var/nix/db
|
||||
make_dir 00755 /nix/var/log
|
||||
make_dir 00755 /nix/var/log/nix
|
||||
|
||||
export NIX_ROOT=$root
|
||||
|
||||
echo initialising Nix DB...
|
||||
/nix/bin/nix-store --init
|
||||
|
||||
echo verifying Nix DB...
|
||||
/nix/bin/nix-store --verify
|
||||
|
||||
echo registering valid paths...
|
||||
(while read storepath; do
|
||||
echo PATH $storepath
|
||||
if ! /nix/bin/nix-store --isvalid $storepath 2> /dev/null; then
|
||||
(unset NIX_ROOT; /nix/bin/nix-store --dump $storepath) | /nix/bin/nix-store --restore $storepath
|
||||
/nix/bin/nix-store --validpath $storepath
|
||||
fi
|
||||
done) < /tmp/storepaths
|
||||
|
||||
echo registering successors...
|
||||
(while read line; do
|
||||
echo SUCC $line
|
||||
/nix/bin/nix-store --successor $line
|
||||
done) < /tmp/successors
|
||||
|
||||
echo setting init symlink...
|
||||
initPath=$(/nix/bin/nix-store -qn $initExpr)
|
||||
rm -f $root/init
|
||||
ln -s $initPath/bin/sh $root/init
|
||||
|
||||
echo unmounting...
|
||||
umount $root
|
||||
|
||||
echo syncing...
|
||||
sync
|
||||
|
||||
echo halting...
|
||||
/sbin/halt -d -f
|
34
make-disk.sh
Executable file
34
make-disk.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#! /bin/sh -e
|
||||
|
||||
image=/tmp/disk.img
|
||||
size=$(expr 256 \* 1024 \* 1024)
|
||||
storepaths=/tmp/storepaths
|
||||
successors=/tmp/successors
|
||||
|
||||
if ! test -f $image; then
|
||||
|
||||
echo creating empty disk of $size bytes in $image...
|
||||
# Note: this is a sparse file.
|
||||
dd if=/dev/zero of=$image bs=1 seek=$(expr $size - 1) count=1
|
||||
|
||||
echo creating disk image in $image...
|
||||
/sbin/mke2fs -F $image
|
||||
|
||||
fi
|
||||
|
||||
|
||||
# What to copy?
|
||||
storeexpr=$(nix-instantiate ./bootstrap.nix)
|
||||
nix-store -rB $storeexpr
|
||||
nix-store -qn --requisites $storeexpr > $storepaths
|
||||
|
||||
(while read storepath; do
|
||||
nix-store -q --predecessors $storepath | (while read predecessor; do
|
||||
echo $predecessor $storepath
|
||||
done)
|
||||
done) < $storepaths > $successors
|
||||
|
||||
# Fill the disk with the minimal Nix store.
|
||||
if ! test -d /tmp/mnt; then mkdir /tmp/mnt; fi
|
||||
linux ubd0=$image root=/dev/root rootflags=/ rootfstype=hostfs init="$(pwd)/fill-disk.sh $storeexpr"
|
||||
|
Loading…
Reference in New Issue
Block a user