at 16.09-beta 2.7 kB view raw
1# This module creates netboot media containing the given NixOS 2# configuration. 3 4{ config, lib, pkgs, ... }: 5 6with lib; 7 8{ 9 options = { 10 11 netboot.storeContents = mkOption { 12 example = literalExample "[ pkgs.stdenv ]"; 13 description = '' 14 This option lists additional derivations to be included in the 15 Nix store in the generated netboot image. 16 ''; 17 }; 18 19 }; 20 21 config = { 22 23 boot.loader.grub.version = 2; 24 25 # Don't build the GRUB menu builder script, since we don't need it 26 # here and it causes a cyclic dependency. 27 boot.loader.grub.enable = false; 28 29 boot.initrd.postMountCommands = '' 30 mkdir -p /mnt-root/nix/store 31 mount -t squashfs /nix-store.squashfs /mnt-root/nix/store 32 ''; 33 34 # !!! Hack - attributes expected by other modules. 35 system.boot.loader.kernelFile = "bzImage"; 36 environment.systemPackages = [ pkgs.grub2 pkgs.grub2_efi pkgs.syslinux ]; 37 38 boot.consoleLogLevel = mkDefault 7; 39 40 fileSystems."/" = 41 { fsType = "tmpfs"; 42 options = [ "mode=0755" ]; 43 }; 44 45 boot.initrd.availableKernelModules = [ "squashfs" ]; 46 47 boot.initrd.kernelModules = [ "loop" ]; 48 49 # Closures to be copied to the Nix store, namely the init 50 # script and the top-level system configuration directory. 51 netboot.storeContents = 52 [ config.system.build.toplevel ]; 53 54 # Create the squashfs image that contains the Nix store. 55 system.build.squashfsStore = import ../../../lib/make-squashfs.nix { 56 inherit (pkgs) stdenv squashfsTools perl pathsFromGraph; 57 storeContents = config.netboot.storeContents; 58 }; 59 60 61 # Create the initrd 62 system.build.netbootRamdisk = pkgs.makeInitrd { 63 inherit (config.boot.initrd) compressor; 64 prepend = [ "${config.system.build.initialRamdisk}/initrd" ]; 65 66 contents = 67 [ { object = config.system.build.squashfsStore; 68 symlink = "/nix-store.squashfs"; 69 } 70 ]; 71 }; 72 73 system.build.netbootIpxeScript = pkgs.writeTextDir "netboot.ipxe" "#!ipxe\nkernel bzImage init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}\ninitrd initrd\nboot"; 74 75 boot.loader.timeout = 10; 76 77 boot.postBootCommands = 78 '' 79 # After booting, register the contents of the Nix store 80 # in the Nix database in the tmpfs. 81 ${config.nix.package}/bin/nix-store --load-db < /nix/store/nix-path-registration 82 83 # nixos-rebuild also requires a "system" profile and an 84 # /etc/NIXOS tag. 85 touch /etc/NIXOS 86 ${config.nix.package}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system 87 ''; 88 89 }; 90 91}