* Add a top-level default.nix for NixOS which has attributes useful

for building parts of the system.  E.g.

  $ nix-build /etc/nixos/nixos -A upstartJobs.xserver

  to build the Upstart job for the X server, or

  $ nix-build /etc/nixos/nixos -A kernel

  to build the NixOS kernel.

* /etc/profile.sh: if ~/.nix-defexpr doesn't exist yet, create it as a
  directory and add links to root's channels, /etc/nixos/nixos and
  /etc/nixos/install-source.nix (as "nixpkgs_sys").
  
* boot.useKernel -> boot.kernel.

svn path=/nixos/trunk/; revision=9334
This commit is contained in:
Eelco Dolstra 2007-09-18 15:06:24 +00:00
parent 0d1aa83fea
commit f2780fdc62
6 changed files with 67 additions and 31 deletions

40
default.nix Normal file
View File

@ -0,0 +1,40 @@
let
configFileName =
let env = builtins.getEnv "NIXOS_CONFIG"; in
if env == "" then /etc/nixos/configuration.nix else env;
system = import system/system.nix {configuration = import configFileName;};
in
{ inherit (system)
activateConfiguration
bootStage1
bootStage2
etc
extraUtils
grubMenuBuilder
initialRamdisk
kernel
nix
nixosCheckout
nixosInstall
nixosRebuild
system
systemPath
config
;
manifests = system.config.get ["installer" "manifests"]; # exported here because nixos-rebuild uses it
upstartJobsCombined = system.upstartJobs;
# Make it easier to build individual Upstart jobs (e.g., "nix-build
# /etc/nixos/nixos -A upstartJobs.xserver").
upstartJobs = { recurseForDerivations = true; } //
builtins.listToAttrs (map (job:
{ attr = if job ? jobName then job.jobName else job.name; value = job; }
) system.upstartJobs.jobs);
}

View File

@ -62,9 +62,15 @@ fi
# Set up a default Nix expression from which to install stuff. # Set up a default Nix expression from which to install stuff.
if ! test -L $HOME/.nix-defexpr; then if test ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr; then
echo "creating $HOME/.nix-defexpr" >&2 echo "creating $HOME/.nix-defexpr" >&2
ln -s /etc/nixos/install-source.nix $HOME/.nix-defexpr rm -f $HOME/.nix-defexpr
mkdir $HOME/.nix-defexpr
ln -s /etc/nixos/install-source.nix $HOME/.nix-defexpr/nixpkgs_sys
ln -s /etc/nixos/nixos $HOME/.nix-defexpr/nixos
if test "$USER" != root; then
ln -s /nix/var/nix/gcroots/per-user/root/channels $HOME/.nix-defexpr/channels_root
fi
fi fi

View File

@ -31,10 +31,7 @@ if test -z "$NIXOS_CONFIG"; then NIXOS_CONFIG=/etc/nixos/configuration.nix; fi
# Pull the manifests defined in the configuration (the "manifests" # Pull the manifests defined in the configuration (the "manifests"
# attribute). Wonderfully hacky. # attribute). Wonderfully hacky.
if test -z "$NIXOS_NO_PULL"; then if test -z "$NIXOS_NO_PULL"; then
manifests=$(nix-instantiate --eval-only --xml --strict \ manifests=$(nix-instantiate --eval-only --xml --strict $NIXOS -A manifests \
$NIXOS/system/system.nix \
--arg configuration "import $NIXOS_CONFIG" \
-A manifests \
| grep '<string' | sed 's^.*"\(.*\)".*^\1^g') | grep '<string' | sed 's^.*"\(.*\)".*^\1^g')
for i in $manifests; do for i in $manifests; do
@ -47,14 +44,10 @@ fi
# or "boot"), or just build it and create a symlink "result" in the # or "boot"), or just build it and create a symlink "result" in the
# current directory (for "build" and "test"). # current directory (for "build" and "test").
if test "$action" = "switch" -o "$action" = "boot"; then if test "$action" = "switch" -o "$action" = "boot"; then
nix-env -p /nix/var/nix/profiles/system -f $NIXOS/system/system.nix \ nix-env -p /nix/var/nix/profiles/system -f $NIXOS --set -A system
--arg configuration "import $NIXOS_CONFIG" \
--set -A system
pathToConfig=/nix/var/nix/profiles/system pathToConfig=/nix/var/nix/profiles/system
elif test "$action" = "test" -o "$action" = "build"; then elif test "$action" = "test" -o "$action" = "build"; then
nix-build $NIXOS/system/system.nix \ nix-build $NIXOS -A system -K -k
--arg configuration "import $NIXOS_CONFIG" \
-A system -K -k
pathToConfig=./result pathToConfig=./result
else else
showSyntax showSyntax

View File

@ -56,14 +56,14 @@
} }
{ {
name = ["boot" "useKernel"]; name = ["boot" "kernel"];
default = pkgs :(pkgs.kernel); default = pkgs: pkgs.kernel;
description = " description = "
Function that takes package collection and returns kernel Function that takes package collection and returns kernel
package. Do not collect old generations after changing it package. Do not collect old generations after changing it
until you get to boot successfully. In principle, you can until you get to boot successfully. In principle, you can
specify a kernel that will build, but not boot. specify a kernel that will build, but not boot.
"; ";
} }
{ {

View File

@ -31,7 +31,7 @@ rec {
nix = pkgs.nixUnstable; # we need the exportReferencesGraph feature nix = pkgs.nixUnstable; # we need the exportReferencesGraph feature
useKernel = (config.get ["boot" "useKernel"]) pkgs; kernel = (config.get ["boot" "kernel"]) pkgs;
rootModules = rootModules =
(config.get ["boot" "initrd" "extraKernelModules"]) ++ (config.get ["boot" "initrd" "extraKernelModules"]) ++
@ -41,8 +41,7 @@ rec {
# Determine the set of modules that we need to mount the root FS. # Determine the set of modules that we need to mount the root FS.
modulesClosure = import ../helpers/modules-closure.nix { modulesClosure = import ../helpers/modules-closure.nix {
inherit (pkgs) stdenv module_init_tools; inherit (pkgs) stdenv module_init_tools;
kernel = useKernel; inherit kernel rootModules;
inherit rootModules;
}; };
@ -147,7 +146,7 @@ rec {
src = ./modprobe; src = ./modprobe;
isExecutable = true; isExecutable = true;
inherit (pkgs) module_init_tools; inherit (pkgs) module_init_tools;
kernel = useKernel; inherit kernel;
}; };
@ -253,8 +252,7 @@ rec {
src = ./activate-configuration.sh; src = ./activate-configuration.sh;
isExecutable = true; isExecutable = true;
inherit etc wrapperDir systemPath modprobe defaultShell; inherit etc wrapperDir systemPath modprobe defaultShell kernel;
kernel = useKernel;
readOnlyRoot = config.get ["boot" "readOnlyRoot"]; readOnlyRoot = config.get ["boot" "readOnlyRoot"];
hostName = config.get ["networking" "hostName"]; hostName = config.get ["networking" "hostName"];
setuidPrograms = setuidPrograms =
@ -281,8 +279,7 @@ rec {
bootStage2 = import ../boot/boot-stage-2.nix { bootStage2 = import ../boot/boot-stage-2.nix {
inherit (pkgs) substituteAll writeText coreutils inherit (pkgs) substituteAll writeText coreutils
utillinux udev upstart; utillinux udev upstart;
kernel = useKernel; inherit kernel activateConfiguration;
inherit activateConfiguration;
readOnlyRoot = config.get ["boot" "readOnlyRoot"]; readOnlyRoot = config.get ["boot" "readOnlyRoot"];
upstartPath = [ upstartPath = [
pkgs.coreutils pkgs.coreutils
@ -326,7 +323,7 @@ rec {
inherit grubMenuBuilder; inherit grubMenuBuilder;
inherit etc; inherit etc;
inherit systemPath; inherit systemPath;
kernel = useKernel + "/vmlinuz"; kernel = kernel + "/vmlinuz";
initrd = initialRamdisk + "/initrd"; initrd = initialRamdisk + "/initrd";
# Most of these are needed by grub-install. # Most of these are needed by grub-install.
path = [ path = [

View File

@ -5,8 +5,8 @@
job.jobDrv job.jobDrv
else else
( (
runCommand job.name {inherit (job) job;} runCommand ("upstart-" + job.name) {inherit (job) job; jobName = job.name;}
"ensureDir $out/etc/event.d; echo \"$job\" > $out/etc/event.d/$name" "ensureDir $out/etc/event.d; echo \"$job\" > $out/etc/event.d/$jobName"
) )
) )