3
0
Fork 0
forked from mirrors/nixpkgs

* Turn the top-level derivation of a NixOS configuration ("system")

into a NixOS module (modules/system/activation/top-level.nix -
  couldn't think of a better name).  The top-level derivation is
  returned in config.system.build.system.
* Inlined system.sh in top-level.nix so that we don't have to pass
  everything through environment variables.

svn path=/nixos/branches/modular-nixos/; revision=15740
This commit is contained in:
Eelco Dolstra 2009-05-27 09:00:45 +00:00
parent 7ac0b3aaea
commit 98cce35041
6 changed files with 112 additions and 123 deletions

View file

@ -8,27 +8,39 @@ let
nixpkgs = fromEnv "NIXPKGS" /etc/nixos/nixpkgs;
system = import system/system.nix { inherit configuration nixpkgs; };
pkgs = import nixpkgs {system = builtins.currentSystem;};
#system = import system/system.nix { inherit configuration nixpkgs; };
configComponents = [
configuration
(import ./system/options.nix)
];
# Make a configuration object from which we can retrieve option
# values.
config =
pkgs.lib.fixOptionSets
pkgs.lib.mergeOptionSets
pkgs configComponents;
optionDeclarations =
pkgs.lib.fixOptionSetsFun
pkgs.lib.filterOptionSets
pkgs configComponents
config;
in
{ inherit (system)
activateConfiguration
bootStage2
etc
grubMenuBuilder
kernel
modulesTree
system
systemPath
config
;
{
nix = system.config.environment.nix;
system = config.system.build.system;
nix = config.environment.nix;
nixFallback = (import nixpkgs {}).nixUnstable;
nixFallback = pkgs.nixUnstable;
manifests = system.config.installer.manifests; # exported here because nixos-rebuild uses it
manifests = config.installer.manifests; # exported here because nixos-rebuild uses it
tests = system.config.tests;
tests = config.tests;
}

View file

@ -0,0 +1,83 @@
{pkgs, config, ...}:
let
# This attribute is responsible for creating boot entries for
# child configuration. They are only (directly) accessible
# when the parent configuration is boot default. For example,
# you can provide an easy way to boot the same configuration
# as you use, but with another kernel
# !!! fix this
children = map (x: ((import ./system.nix)
{ platform = pkgs.system;
configuration = x//{boot=((x.boot)//{grubDevice = "";});};}).system)
config.nesting.children;
systemBuilder =
''
ensureDir $out
ln -s ${config.boot.kernelPackages.kernel}/vmlinuz $out/kernel
ln -s $grub $out/grub
ln -s ${config.system.build.bootStage2} $out/init
ln -s ${config.system.build.initialRamdisk}/initrd $out/initrd
ln -s ${config.system.activationScripts.script} $out/activate
ln -s ${config.system.build.etc}/etc $out/etc
ln -s ${config.system.path} $out/sw
ln -s ${pkgs.upstart} $out/upstart
echo "$kernelParams" > $out/kernel-params
echo "$configurationName" > $out/configuration-name
echo "${toString pkgs.upstart.interfaceVersion}" > $out/upstart-interface-version
mkdir $out/fine-tune
childCount=0;
for i in $children; do
childCount=$(( childCount + 1 ));
ln -s $i $out/fine-tune/child-$childCount;
done
cat > $out/menu.lst << GRUBEND
kernel $kernel init=$bootStage2 $kernelParams
initrd $initrd
GRUBEND
ensureDir $out/bin
substituteAll ${./switch-to-configuration.sh} $out/bin/switch-to-configuration
chmod +x $out/bin/switch-to-configuration
'';
# Putting it all together. This builds a store path 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.
system = pkgs.stdenv.mkDerivation {
name = "system";
buildCommand = systemBuilder;
inherit children;
inherit (pkgs) grub;
grubDevice = config.boot.grubDevice;
kernelParams =
config.boot.kernelParams ++ config.boot.extraKernelParams;
grubMenuBuilder = config.system.build.grubMenuBuilder;
configurationName = config.boot.configurationName;
# Most of these are needed by grub-install.
path = [
pkgs.coreutils
pkgs.gnused
pkgs.gnugrep
pkgs.findutils
pkgs.diffutils
pkgs.upstart # for initctl
];
};
in {
system.build.system = system;
}

View file

@ -445,6 +445,7 @@ in
../modules/services/x11/xfs.nix
../modules/services/x11/xserver/default.nix
../modules/system/activation/activation-script.nix
../modules/system/activation/top-level.nix
../modules/system/boot/kernel.nix
../modules/system/boot/stage-1.nix
../modules/system/boot/stage-2.nix

View file

@ -1,75 +0,0 @@
{ platform ? __currentSystem
, configuration
, nixpkgs ? ../../nixpkgs
}:
rec {
configComponents = [
configuration
(import ./options.nix)
];
# Make a configuration object from which we can retrieve option
# values.
config =
pkgs.lib.fixOptionSets
pkgs.lib.mergeOptionSets
pkgs configComponents;
optionDeclarations =
pkgs.lib.fixOptionSetsFun
pkgs.lib.filterOptionSets
pkgs configComponents
config;
pkgs = import nixpkgs {system = platform;};
# This attribute is responsible for creating boot entries for
# child configuration. They are only (directly) accessible
# when the parent configuration is boot default. For example,
# you can provide an easy way to boot the same configuration
# as you use, but with another kernel
children = map (x: ((import ./system.nix)
{ inherit platform;
configuration = x//{boot=((x.boot)//{grubDevice = "";});};}).system)
config.nesting.children;
# 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.
system = pkgs.checker (pkgs.stdenv.mkDerivation {
name = "system";
builder = ./system.sh;
switchToConfiguration = ./switch-to-configuration.sh;
inherit (pkgs) grub upstart;
grubDevice = config.boot.grubDevice;
kernelParams =
config.boot.kernelParams ++ config.boot.extraKernelParams;
bootStage2 = config.system.build.bootStage2;
activateConfiguration = config.system.activationScripts.script;
grubMenuBuilder = config.system.build.grubMenuBuilder;
etc = config.system.build.etc;
systemPath = config.system.path;
inherit children;
configurationName = config.boot.configurationName;
kernel = config.boot.kernelPackages.kernel + "/vmlinuz";
initrd = config.system.build.initialRamdisk + "/initrd";
# Most of these are needed by grub-install.
path = [
pkgs.coreutils
pkgs.gnused
pkgs.gnugrep
pkgs.findutils
pkgs.diffutils
pkgs.upstart # for initctl
];
upstartInterfaceVersion = pkgs.upstart.interfaceVersion;
}) config.environment.checkConfigurationOptions
optionDeclarations config;
}

View file

@ -1,32 +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
ln -s $activateConfiguration $out/activate
ln -s $etc/etc $out/etc
ln -s $systemPath $out/sw
ln -s $upstart $out/upstart
echo "$kernelParams" > $out/kernel-params
echo "$configurationName" > $out/configuration-name
echo "$upstartInterfaceVersion" > $out/upstart-interface-version
mkdir $out/fine-tune
ChildCount=0;
for i in $children; do
ChildCount=$(( ChildCount + 1 ));
ln -s $i $out/fine-tune/child-$ChildCount;
done
cat > $out/menu.lst << GRUBEND
kernel $kernel init=$bootStage2 $kernelParams
initrd $initrd
GRUBEND
ensureDir $out/bin
substituteAll $switchToConfiguration $out/bin/switch-to-configuration
chmod +x $out/bin/switch-to-configuration