1# This module contains the basic configuration for building a NixOS
2# tarball, that can directly boot, maybe using PXE or unpacking on a fs.
3
4{ config, lib, pkgs, ... }:
5
6with lib;
7
8let
9
10 pkgs2storeContents = l : map (x: { object = x; symlink = "none"; }) l;
11
12 # For PXE kernel loading
13 pxeconfig = pkgs.writeText "pxeconfig-default" ''
14 default menu.c32
15 prompt 0
16
17 label bootlocal
18 menu default
19 localboot 0
20 timeout 80
21 TOTALTIMEOUT 9000
22
23 label nixos
24 MENU LABEL ^NixOS using nfsroot
25 KERNEL bzImage
26 append ip=dhcp nfsroot=/home/pcroot systemConfig=${config.system.build.toplevel} init=${config.system.build.toplevel}/init rw
27
28 # I don't know how to make this boot with nfsroot (using the initrd)
29 label nixos_initrd
30 MENU LABEL NixOS booting the poor ^initrd.
31 KERNEL bzImage
32 append initrd=initrd ip=dhcp nfsroot=/home/pcroot systemConfig=${config.system.build.toplevel} init=${config.system.build.toplevel}/init rw
33
34 label memtest
35 MENU LABEL ^${pkgs.memtest86.name}
36 KERNEL memtest
37 '';
38
39 dhcpdExampleConfig = pkgs.writeText "dhcpd.conf-example" ''
40 # Example configuration for booting PXE.
41 allow booting;
42 allow bootp;
43
44 # Adapt this to your network configuration.
45 option domain-name "local";
46 option subnet-mask 255.255.255.0;
47 option broadcast-address 192.168.1.255;
48 option domain-name-servers 192.168.1.1;
49 option routers 192.168.1.1;
50
51 # PXE-specific configuration directives...
52 # Some BIOS don't accept slashes for paths inside the tftp servers,
53 # and will report Access Violation if they see slashes.
54 filename "pxelinux.0";
55 # For the TFTP and NFS root server. Set the IP of your server.
56 next-server 192.168.1.34;
57
58 subnet 192.168.1.0 netmask 255.255.255.0 {
59 range 192.168.1.50 192.168.1.55;
60 }
61 '';
62
63 readme = ./system-tarball-pc-readme.txt;
64
65in
66
67{
68 imports =
69 [ ./system-tarball.nix
70
71 # Profiles of this basic installation.
72 ../../profiles/all-hardware.nix
73 ../../profiles/base.nix
74 ../../profiles/installation-device.nix
75 ];
76
77 # To speed up further installation of packages, include the complete stdenv
78 # in the Nix store of the tarball.
79 tarball.storeContents = pkgs2storeContents [ pkgs.stdenv ];
80
81 tarball.contents =
82 [ { source = config.boot.kernelPackages.kernel + "/" + config.system.boot.loader.kernelFile;
83 target = "/boot/" + config.system.boot.loader.kernelFile;
84 }
85 { source = "${pkgs.syslinux}/share/syslinux/pxelinux.0";
86 target = "/boot/pxelinux.0";
87 }
88 { source = "${pkgs.syslinux}/share/syslinux/menu.c32";
89 target = "/boot/menu.c32";
90 }
91 { source = pxeconfig;
92 target = "/boot/pxelinux.cfg/default";
93 }
94 { source = readme;
95 target = "/readme.txt";
96 }
97 { source = dhcpdExampleConfig;
98 target = "/boot/dhcpd.conf-example";
99 }
100 { source = "${pkgs.memtest86}/memtest.bin";
101 # We can't leave '.bin', because pxelinux interprets this specially,
102 # and it would not load the image fine.
103 # http://forum.canardpc.com/threads/46464-0104-when-launched-via-pxe
104 target = "/boot/memtest";
105 }
106 ];
107
108 # Allow sshd to be started manually through "start sshd". It should
109 # not be started by default on the installation CD because the
110 # default root password is empty.
111 services.openssh.enable = true;
112 systemd.services.openssh.wantedBy = lib.mkOverride 50 [];
113
114 # To be able to use the systemTarball to catch troubles.
115 boot.crashDump = {
116 enable = true;
117 kernelPackages = pkgs.linuxPackages_3_4;
118 };
119
120 # No grub for the tarball.
121 boot.loader.grub.enable = false;
122
123 /* fake entry, just to have a happy stage-1. Users
124 may boot without having stage-1 though */
125 fileSystems = [
126 { mountPoint = "/";
127 device = "/dev/something";
128 }
129 ];
130
131 nixpkgs.config = {
132 packageOverrides = p: rec {
133 linux_3_4 = p.linux_3_4.override {
134 extraConfig = ''
135 # Enable drivers in kernel for most NICs.
136 E1000 y
137 # E1000E y
138 # ATH5K y
139 8139TOO y
140 NE2K_PCI y
141 ATL1 y
142 ATL1E y
143 ATL1C y
144 VORTEX y
145 VIA_RHINE y
146 R8169 y
147
148 # Enable nfs root boot
149 UNIX y # http://www.linux-mips.org/archives/linux-mips/2006-11/msg00113.html
150 IP_PNP y
151 IP_PNP_DHCP y
152 FSCACHE y
153 NFS_FS y
154 NFS_FSCACHE y
155 ROOT_NFS y
156
157 # Enable devtmpfs
158 DEVTMPFS y
159 DEVTMPFS_MOUNT y
160 '';
161 };
162 };
163 };
164}