From a07e90d6f38dfc18a3dc3f1614cd802176f56151 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 13 Sep 2009 22:13:19 +0000 Subject: [PATCH] Update the documentation: * Change the module syntax of the example to follow Eelco's suggestions. * Add a section "Building your own NixOS CD", which explain how to replace configuration.nix by the configuration file of a live CD/DVD. * Fix "Testing the installer" and "Testing the initrd" to fit the location of derivations. svn path=/nixos/trunk/; revision=17105 --- doc/manual/development.xml | 190 ++++++++++++++++-------------- modules/installer/tools/tools.nix | 2 + modules/system/boot/kernel.nix | 1 + 3 files changed, 107 insertions(+), 86 deletions(-) diff --git a/doc/manual/development.xml b/doc/manual/development.xml index b1a9a3a43253..2f99ee42bce5 100644 --- a/doc/manual/development.xml +++ b/doc/manual/development.xml @@ -21,60 +21,48 @@ NixOS. Usual configuration file -{pkgs, config, ...}: +{config, modulesPath, pkgs, ...}: -###### interface let - inherit (pkgs.lib) mkOption; + inherit (pkgs.lib) mkOption mkIf mkThenElse types; - options = { - services = { - locate = { - - enable = mkOption { - default = false; - example = true; - description = '' - If enabled, NixOS will periodically update the database of - files used by the locate command. - ''; - }; - - period = mkOption { - default = "15 02 * * *"; - description = '' - This option defines (in the format used by cron) when the - locate database is updated. - The default is to update at 02:15 (at night) every day. - ''; - }; - - }; - - }; - }; -in - -###### implementation -let cfg = config.services.locate; - inherit (pkgs.lib) mkIf mkThenElse; - locatedb = "/var/cache/locatedb"; logfile = "/var/log/updatedb"; cmd = "root updatedb --localuser=nobody --output=${locatedb} > ${logfile}"; in -mkIf cfg.enable { - require = [ - options - - # config.services.cron - (import ../../upstart-jobs/cron.nix) +{ + imports = [ + (modulesPath + /services/scheduling/cron.nix) ]; - services = { - cron = { + options = { + services.locate = { + enable = mkOption { + default = false; + example = true; + type = types.bool; + description = '' + If enabled, NixOS will periodically update the database of + files used by the locate command. + ''; + }; + + period = mkOption { + default = "15 02 * * *"; + type = types.uniq type.string; + description = '' + This option defines (in the format used by cron) when the + locate database is updated. + The default is to update at 02:15 (at night) every day. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + services.cron = { systemCronJobs = mkThenElse { thenPart = "${cfg.period} root ${cmd}"; elsePart = ""; @@ -125,7 +113,7 @@ mkIf cfg.enable { - This line is used to import a function that is useful for + This line is used to import a functions that are useful for writing this configuration file. @@ -185,25 +173,26 @@ mkIf cfg.enable { - The attribute require is the only special - option that exists. It is used to embed all option declarations that - are required by your configuration file and it is also used to provide - the options that you are declaring. + The attribute imports contains a list of other + module location. These modules should provide option declarations for + the current module in order to be evaluated safely. - This attribute is processed - with pkgs.lib.uniqFlatten to collect all - configuration files that are used by your system and it avoid the - insertion of duplicated elements by comparing the configuration set codes. - - Currently, the file configuration.nix - implicitly embeds system/options.nix. If you need - a special configuration file, then you will have to add similar lines - to your computer configuration. + When a dependence on a NixOS module has to be made, then you + should use the argument modulesPath to prefix the + location of your NixOS repository. + The attribute config, which should not be + confused with the argument of the same name, contains a set of option + definitions defined by this module. When there is + neither imports nor options, then + this attribute set can be return without any enclosing. This feature + allow you to write your configuration.nix as a + module which does not contains any option declarations. + As mkIf does not need any then part or else part, then you can specify one on each option definition with the @@ -238,7 +227,7 @@ mkIf cfg.enable { -$ nix-build /etc/nixos/nixos attr +$ nix-build /etc/nixos/nixos -A attr where attr is an attribute in /etc/nixos/nixos/default.nix. Attributes of interest include: @@ -246,55 +235,84 @@ where attr is an attribute in - kernel - The kernel. + config + The computer configuration generated from + the NIXOS_CONFIG environment variable (default + is /etc/nixos/configuration.nix) with the NixOS + default set of modules. - initialRamdisk - The initial ramdisk (initrd) for this configuration. + system + The derivation which build your computer system. It is + built by the command nixos-rebuild + build - bootStage1 - The stage 1 (initrd) init script. + vm + The derivation which build your computer system inside a + virtual machine. It is built by the command nixos-rebuild + build-vm - - - bootStage2 - The stage 2 init script. - - - - etc - The statically computed parts of /etc. - - - - upstartJobs - An attribute set containing the Upstart jobs. For - instance, the sshd Upstart job can be built by - doing nix-build /etc/nixos/nixos -A - tests.upstartJobs.sshd. - - + +Most parts of NixOS can be build through the config +attribute set. This attribute set allows you to have a view of the merged +option definitions and all its derivations. Important derivations are store +inside the option and can be listed with the +command nix-instantiate --xml --eval-only /etc/nixos/nixos -A +config.system.build +. + +
+ +Building your own NixOS CD + +Building a NixOS CD is as easy as configuring your own computer. The +idea is to use another module which will replace +your configuration.nix to configure the system that +would be install on the CD. + +Default CD/DVD configurations are available +inside nixos/modules/installer/cd-dvd. To build them +you have to set NIXOS_CONFIG before +running nix-build to build the ISO. + + +$ export NIXOS_CONFIG=/etc/nixos/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix +$ nix-build /etc/nixos/nixos -A config.system.build.isoImage + + + +Before burning your CD/DVD, you can check the content of the image by mounting anywhere like +suggested by the following command: + + +$ mount -o loop -t iso9660 ./result/iso/cd.iso /mnt/iso + + + +
+
Testing the installer + Building, burning, and booting from an installation CD is rather tedious, so here is a quick way to see if the installer works properly: -$ nix-build .../nixos/configuration/rescue-cd.nix -A system.nixosInstall +$ export NIXOS_CONFIG=/etc/nixos/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix +$ nix-build /etc/nixos/nixos -A config.system.build.nixosInstall $ dd if=/dev/zero of=diskimage seek=2G count=0 bs=1 $ yes | mke2fs -j diskimage $ mount -o loop diskimage /mnt @@ -314,8 +332,8 @@ boot correctly is to use QEMU’s and options: -$ nix-build /etc/nixos/nixos -A initialRamdisk -o initrd -$ nix-build /etc/nixos/nixos -A kernel -o kernel +$ nix-build /etc/nixos/nixos -A config.system.build.initialRamdisk -o initrd +$ nix-build /etc/nixos/nixos -A config.system.build.kernel -o kernel $ qemu-system-x86_64 -kernel ./kernel/vmlinuz -initrd ./initrd/initrd -hda /dev/null diff --git a/modules/installer/tools/tools.nix b/modules/installer/tools/tools.nix index 37b7589f4776..45df2a50e929 100644 --- a/modules/installer/tools/tools.nix +++ b/modules/installer/tools/tools.nix @@ -80,4 +80,6 @@ in nixosHardwareScan nixosGenSeccureKeys ]; + + system.build = { inherit nixosInstall; }; } diff --git a/modules/system/boot/kernel.nix b/modules/system/boot/kernel.nix index 58a8948f4fd5..ca8098057348 100644 --- a/modules/system/boot/kernel.nix +++ b/modules/system/boot/kernel.nix @@ -180,6 +180,7 @@ in { require = [options]; + system.build = { inherit kernel; }; system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages; # The Linux kernel >= 2.6.27 provides firmware.