@ -8,7 +8,28 @@
with lib ;
let cfg = config . ec2 ; in
let
cfg = config . ec2 ;
udhcpcScript = pkgs . writeScript " u d h c p - s c r i p t "
''
#! /bin/sh
if [ " $ 1 " = bound ] ; then
ip address add " $ i p / $ m a s k " dev " $ i n t e r f a c e "
if [ - n " $ r o u t e r " ] ; then
ip route add default via " $ r o u t e r " dev " $ i n t e r f a c e "
fi
if [ - n " $ d n s " ] ; then
rm - f /etc/resolv.conf
for i in $ dns ; do
echo " n a m e s e r v e r $ d n s " > > /etc/resolv.conf
done
fi
fi
'' ;
in
{
imports = [ ../profiles/headless.nix ./ec2-data.nix ./amazon-grow-partition.nix ./amazon-init.nix ] ;
@ -20,8 +41,10 @@ let cfg = config.ec2; in
autoResize = true ;
} ;
boot . initrd . kernelModules = [ " x e n - b l k f r o n t " ] ;
boot . kernelModules = [ " x e n - n e t f r o n t " ] ;
boot . initrd . kernelModules =
[ " x e n - b l k f r o n t " " x e n - n e t f r o n t "
" a f _ p a c k e t " # <- required by udhcpc
] ;
boot . kernelParams = mkIf cfg . hvm [ " c o n s o l e = t t y S 0 " ] ;
# Prevent the nouveau kernel module from being loaded, as it
@ -55,6 +78,18 @@ let cfg = config.ec2; in
# Nix operations.
boot . initrd . postMountCommands =
''
metaDir = $ targetRoot/etc/ec2-metadata
mkdir - m 0755 $ targetRoot/etc
mkdir - m 0700 - p " $ m e t a D i r "
echo " g e t t i n g E C 2 i n s t a n c e m e t a d a t a . . . "
ip link set eth0 up
udhcpc - - interface eth0 - - quit - - now - - script $ { udhcpcScript }
if ! [ - e " $ m e t a D i r / a m i - m a n i f e s t - p a t h " ] ; then
wget - q - O " $ m e t a D i r / a m i - m a n i f e s t - p a t h " http://169.254.169.254/1.0/meta-data/ami-manifest-path
fi
diskNr = 0
diskForUnionfs =
for device in /dev/xvd [ abcde ] * ; do
@ -85,7 +120,7 @@ let cfg = config.ec2; in
mkdir - m 1777 - p $ targetRoot / $ diskForUnionfs/root/tmp $ targetRoot/tmp
mount - - bind $ targetRoot / $ diskForUnionfs/root/tmp $ targetRoot/tmp
if [ ! - e $ targetRoot/.ebs ] ; then
if [ " $ ( c a t " $ metaDir/ami-manifest-path " ) " != " ( u n k n o w n ) " ] ; then
mkdir - m 755 - p $ targetRoot / $ diskForUnionfs/root/var $ targetRoot/var
mount - - bind $ targetRoot / $ diskForUnionfs/root/var $ targetRoot/var