diff --git a/default.nix b/default.nix index 30eff6c2e6a5..ebb9110eb355 100644 --- a/default.nix +++ b/default.nix @@ -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; } diff --git a/system/switch-to-configuration.sh b/modules/system/activation/switch-to-configuration.sh similarity index 100% rename from system/switch-to-configuration.sh rename to modules/system/activation/switch-to-configuration.sh diff --git a/modules/system/activation/top-level.nix b/modules/system/activation/top-level.nix new file mode 100644 index 000000000000..306037d1f575 --- /dev/null +++ b/modules/system/activation/top-level.nix @@ -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; + +} diff --git a/system/options.nix b/system/options.nix index 90add193c863..a15a4b30a4a5 100644 --- a/system/options.nix +++ b/system/options.nix @@ -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 diff --git a/system/system.nix b/system/system.nix deleted file mode 100644 index ee9c6d259342..000000000000 --- a/system/system.nix +++ /dev/null @@ -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; - -} diff --git a/system/system.sh b/system/system.sh deleted file mode 100644 index 67042b5faf45..000000000000 --- a/system/system.sh +++ /dev/null @@ -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