···67 cfg = config.boot.initrd.network;
8000000000000000009in
1011{
···16 type = types.bool;
17 default = false;
18 description = ''
19- Add network connectivity support to initrd.
20-21- Network options are configured via <literal>ip</literal> kernel
22- option, according to the kernel documentation.
00023 '';
24 };
25···43 copy_bin_and_libs ${pkgs.mkinitcpio-nfs-utils}/bin/ipconfig
44 '';
4546- boot.initrd.preLVMCommands = ''
47- # Search for interface definitions in command line
48- for o in $(cat /proc/cmdline); do
49- case $o in
50- ip=*)
51- ipconfig $o && hasNetwork=1
52- ;;
53- esac
54- done
0000000000000000005556- ${cfg.postCommands}
57- '';
5859 };
60
···67 cfg = config.boot.initrd.network;
89+ udhcpcScript = pkgs.writeScript "udhcp-script"
10+ ''
11+ #! /bin/sh
12+ if [ "$1" = bound ]; then
13+ ip address add "$ip/$mask" dev "$interface"
14+ if [ -n "$router" ]; then
15+ ip route add default via "$router" dev "$interface"
16+ fi
17+ if [ -n "$dns" ]; then
18+ rm -f /etc/resolv.conf
19+ for i in $dns; do
20+ echo "nameserver $dns" >> /etc/resolv.conf
21+ done
22+ fi
23+ fi
24+ '';
25+26in
2728{
···33 type = types.bool;
34 default = false;
35 description = ''
36+ Add network connectivity support to initrd. The network may be
37+ configured using the <literal>ip</literal> kernel parameter,
38+ as described in <link
39+ xlink:href="https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt">the
40+ kernel documentation</link>. Otherwise, if
41+ <option>networking.useDHCP</option> is enabled, an IP address
42+ is acquired using DHCP.
43 '';
44 };
45···63 copy_bin_and_libs ${pkgs.mkinitcpio-nfs-utils}/bin/ipconfig
64 '';
6566+ boot.initrd.preLVMCommands =
67+ # Search for interface definitions in command line.
68+ ''
69+ for o in $(cat /proc/cmdline); do
70+ case $o in
71+ ip=*)
72+ ipconfig $o && hasNetwork=1
73+ ;;
74+ esac
75+ done
76+ ''
77+78+ # Otherwise, use DHCP.
79+ + optionalString config.networking.useDHCP ''
80+ if [ -z "$hasNetwork" ]; then
81+82+ # Bring up all interfaces.
83+ for iface in $(cd /sys/class/net && ls); do
84+ echo "bringing up network interface $iface..."
85+ ip link set "$iface" up
86+ done
87+88+ # Acquire a DHCP lease.
89+ echo "acquiring IP address via DHCP..."
90+ udhcpc --quit --now --script ${udhcpcScript}
91+ fi
92+ ''
9394+ + cfg.postCommands;
09596 };
97
+5-29
nixos/modules/virtualisation/amazon-image.nix
···89with lib;
1011-let
12-13- cfg = config.ec2;
14-15- udhcpcScript = pkgs.writeScript "udhcp-script"
16- ''
17- #! /bin/sh
18- if [ "$1" = bound ]; then
19- ip address add "$ip/$mask" dev "$interface"
20- if [ -n "$router" ]; then
21- ip route add default via "$router" dev "$interface"
22- fi
23- if [ -n "$dns" ]; then
24- rm -f /etc/resolv.conf
25- for i in $dns; do
26- echo "nameserver $dns" >> /etc/resolv.conf
27- done
28- fi
29- fi
30- '';
31-32-in
3334{
35 imports = [ ../profiles/headless.nix ./ec2-data.nix ./amazon-grow-partition.nix ./amazon-init.nix ];
···41 autoResize = true;
42 };
4344- boot.initrd.kernelModules =
45- [ "xen-blkfront" "xen-netfront"
46- "af_packet" # <- required by udhcpc
47- ];
48 boot.kernelParams = mkIf cfg.hvm [ "console=ttyS0" ];
4950 # Prevent the nouveau kernel module from being loaded, as it
···67 kill -9 -1
68 '';
690070 # Mount all formatted ephemeral disks and activate all swap devices.
71 # We cannot do this with the ‘fileSystems’ and ‘swapDevices’ options
72 # because the set of devices is dependent on the instance type
···79 boot.initrd.postMountCommands =
80 ''
81 metaDir=$targetRoot/etc/ec2-metadata
82- mkdir -m 0755 $targetRoot/etc
83 mkdir -m 0700 -p "$metaDir"
8485 echo "getting EC2 instance metadata..."
86- ip link set eth0 up
87- udhcpc --interface eth0 --quit --now --script ${udhcpcScript}
8889 if ! [ -e "$metaDir/ami-manifest-path" ]; then
90 wget -q -O "$metaDir/ami-manifest-path" http://169.254.169.254/1.0/meta-data/ami-manifest-path
···89with lib;
1011+let cfg = config.ec2; in
0000000000000000000001213{
14 imports = [ ../profiles/headless.nix ./ec2-data.nix ./amazon-grow-partition.nix ./amazon-init.nix ];
···20 autoResize = true;
21 };
2223+ boot.initrd.kernelModules = [ "xen-blkfront" "xen-netfront" ];
00024 boot.kernelParams = mkIf cfg.hvm [ "console=ttyS0" ];
2526 # Prevent the nouveau kernel module from being loaded, as it
···43 kill -9 -1
44 '';
4546+ boot.initrd.network.enable = true;
47+48 # Mount all formatted ephemeral disks and activate all swap devices.
49 # We cannot do this with the ‘fileSystems’ and ‘swapDevices’ options
50 # because the set of devices is dependent on the instance type
···57 boot.initrd.postMountCommands =
58 ''
59 metaDir=$targetRoot/etc/ec2-metadata
60+ mkdir -m 0755 -p $targetRoot/etc
61 mkdir -m 0700 -p "$metaDir"
6263 echo "getting EC2 instance metadata..."
006465 if ! [ -e "$metaDir/ami-manifest-path" ]; then
66 wget -q -O "$metaDir/ami-manifest-path" http://169.254.169.254/1.0/meta-data/ami-manifest-path