at 16.09-beta 2.6 kB view raw
1# This module creates a bootable ISO image containing the given NixOS 2# configuration. The derivation for the ISO image will be placed in 3# config.system.build.tarball. 4 5{ config, lib, pkgs, ... }: 6 7with lib; 8 9let 10 11 versionFile = pkgs.writeText "nixos-version" config.system.nixosVersion; 12 13in 14 15{ 16 options = { 17 tarball.contents = mkOption { 18 example = literalExample '' 19 [ { source = pkgs.memtest86 + "/memtest.bin"; 20 target = "boot/memtest.bin"; 21 } 22 ] 23 ''; 24 description = '' 25 This option lists files to be copied to fixed locations in the 26 generated ISO image. 27 ''; 28 }; 29 30 tarball.storeContents = mkOption { 31 example = literalExample "[ pkgs.stdenv ]"; 32 description = '' 33 This option lists additional derivations to be included in the 34 Nix store in the generated ISO image. 35 ''; 36 }; 37 38 }; 39 40 config = { 41 42 # In stage 1 of the boot, mount the CD/DVD as the root FS by label 43 # so that we don't need to know its device. 44 fileSystems = [ ]; 45 46 # boot.initrd.availableKernelModules = [ "mvsdio" "reiserfs" "ext3" "ext4" ]; 47 48 # boot.initrd.kernelModules = [ "rtc_mv" ]; 49 50 # Closures to be copied to the Nix store on the CD, namely the init 51 # script and the top-level system configuration directory. 52 tarball.storeContents = 53 [ { object = config.system.build.toplevel; 54 symlink = "/run/current-system"; 55 } 56 ]; 57 58 # Individual files to be included on the CD, outside of the Nix 59 # store on the CD. 60 tarball.contents = 61 [ { source = config.system.build.initialRamdisk + "/initrd"; 62 target = "/boot/initrd"; 63 } 64 { source = versionFile; 65 target = "/nixos-version.txt"; 66 } 67 ]; 68 69 # Create the tarball 70 system.build.tarball = import ../../../lib/make-system-tarball.nix { 71 inherit (pkgs) stdenv perl xz pathsFromGraph; 72 73 inherit (config.tarball) contents storeContents; 74 }; 75 76 boot.postBootCommands = 77 '' 78 # After booting, register the contents of the Nix store on the 79 # CD in the Nix database in the tmpfs. 80 if [ -f /nix-path-registration ]; then 81 ${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration && 82 rm /nix-path-registration 83 fi 84 85 # nixos-rebuild also requires a "system" profile and an 86 # /etc/NIXOS tag. 87 touch /etc/NIXOS 88 ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system 89 ''; 90 91 }; 92 93}