···6677 cfg = config.boot.initrd.network;
8899+ udhcpcScript = pkgs.writeScript "udhcp-script"
1010+ ''
1111+ #! /bin/sh
1212+ if [ "$1" = bound ]; then
1313+ ip address add "$ip/$mask" dev "$interface"
1414+ if [ -n "$router" ]; then
1515+ ip route add default via "$router" dev "$interface"
1616+ fi
1717+ if [ -n "$dns" ]; then
1818+ rm -f /etc/resolv.conf
1919+ for i in $dns; do
2020+ echo "nameserver $dns" >> /etc/resolv.conf
2121+ done
2222+ fi
2323+ fi
2424+ '';
2525+926in
10271128{
···1633 type = types.bool;
1734 default = false;
1835 description = ''
1919- Add network connectivity support to initrd.
2020-2121- Network options are configured via <literal>ip</literal> kernel
2222- option, according to the kernel documentation.
3636+ Add network connectivity support to initrd. The network may be
3737+ configured using the <literal>ip</literal> kernel parameter,
3838+ as described in <link
3939+ xlink:href="https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt">the
4040+ kernel documentation</link>. Otherwise, if
4141+ <option>networking.useDHCP</option> is enabled, an IP address
4242+ is acquired using DHCP.
2343 '';
2444 };
2545···4363 copy_bin_and_libs ${pkgs.mkinitcpio-nfs-utils}/bin/ipconfig
4464 '';
45654646- boot.initrd.preLVMCommands = ''
4747- # Search for interface definitions in command line
4848- for o in $(cat /proc/cmdline); do
4949- case $o in
5050- ip=*)
5151- ipconfig $o && hasNetwork=1
5252- ;;
5353- esac
5454- done
6666+ boot.initrd.preLVMCommands =
6767+ # Search for interface definitions in command line.
6868+ ''
6969+ for o in $(cat /proc/cmdline); do
7070+ case $o in
7171+ ip=*)
7272+ ipconfig $o && hasNetwork=1
7373+ ;;
7474+ esac
7575+ done
7676+ ''
7777+7878+ # Otherwise, use DHCP.
7979+ + optionalString config.networking.useDHCP ''
8080+ if [ -z "$hasNetwork" ]; then
8181+8282+ # Bring up all interfaces.
8383+ for iface in $(cd /sys/class/net && ls); do
8484+ echo "bringing up network interface $iface..."
8585+ ip link set "$iface" up
8686+ done
8787+8888+ # Acquire a DHCP lease.
8989+ echo "acquiring IP address via DHCP..."
9090+ udhcpc --quit --now --script ${udhcpcScript}
9191+ fi
9292+ ''
55935656- ${cfg.postCommands}
5757- '';
9494+ + cfg.postCommands;
58955996 };
6097
+5-29
nixos/modules/virtualisation/amazon-image.nix
···8899with lib;
10101111-let
1212-1313- cfg = config.ec2;
1414-1515- udhcpcScript = pkgs.writeScript "udhcp-script"
1616- ''
1717- #! /bin/sh
1818- if [ "$1" = bound ]; then
1919- ip address add "$ip/$mask" dev "$interface"
2020- if [ -n "$router" ]; then
2121- ip route add default via "$router" dev "$interface"
2222- fi
2323- if [ -n "$dns" ]; then
2424- rm -f /etc/resolv.conf
2525- for i in $dns; do
2626- echo "nameserver $dns" >> /etc/resolv.conf
2727- done
2828- fi
2929- fi
3030- '';
3131-3232-in
1111+let cfg = config.ec2; in
33123413{
3514 imports = [ ../profiles/headless.nix ./ec2-data.nix ./amazon-grow-partition.nix ./amazon-init.nix ];
···4120 autoResize = true;
4221 };
43224444- boot.initrd.kernelModules =
4545- [ "xen-blkfront" "xen-netfront"
4646- "af_packet" # <- required by udhcpc
4747- ];
2323+ boot.initrd.kernelModules = [ "xen-blkfront" "xen-netfront" ];
4824 boot.kernelParams = mkIf cfg.hvm [ "console=ttyS0" ];
49255026 # Prevent the nouveau kernel module from being loaded, as it
···6743 kill -9 -1
6844 '';
69454646+ boot.initrd.network.enable = true;
4747+7048 # Mount all formatted ephemeral disks and activate all swap devices.
7149 # We cannot do this with the ‘fileSystems’ and ‘swapDevices’ options
7250 # because the set of devices is dependent on the instance type
···7957 boot.initrd.postMountCommands =
8058 ''
8159 metaDir=$targetRoot/etc/ec2-metadata
8282- mkdir -m 0755 $targetRoot/etc
6060+ mkdir -m 0755 -p $targetRoot/etc
8361 mkdir -m 0700 -p "$metaDir"
84628563 echo "getting EC2 instance metadata..."
8686- ip link set eth0 up
8787- udhcpc --interface eth0 --quit --now --script ${udhcpcScript}
88648965 if ! [ -e "$metaDir/ami-manifest-path" ]; then
9066 wget -q -O "$metaDir/ami-manifest-path" http://169.254.169.254/1.0/meta-data/ami-manifest-path