@ -1,20 +1,18 @@
{ config , pkgs , modulesPath , . . . }:
# This attempts to pull a nix expression from this EC2 instance's user-data.
{ config , pkgs , . . . }:
let
bootScript = pkgs . writeScript " b o o t s c r i p t . s h " ''
script = ''
#!${pkgs.stdenv.shell} -eu
echo " a t t e m p t i n g t o f e t c h c o n f i g u r a t i o n f r o m E C 2 u s e r d a t a . . . "
export HOME = /root
export PATH = $ { pkgs . lib . makeBinPath [ config . nix . package pkgs . systemd pkgs . gnugrep pkgs . gnused config . system . build . nixos-rebuild ] }: $ PATH
export NIX_PATH = /nix/var/nix/profiles/per-user/root/channels/nixos : nixos-config = /etc/nixos/configuration.nix : /nix/var/nix/profiles/per-user/root/channels
userData = /etc/ec2-metadata/user-data
if [ - s " $ u s e r D a t a " ] ; then
# If the user-data looks like it could be a nix expression,
# copy it over. Also, look for a magic three-hash comment and set
# that as the channel.
@ -43,7 +41,22 @@ let
nixos-rebuild switch
'' ;
in {
boot . postBootCommands = ''
$ { bootScript } &
'' ;
systemd . services . amazon-init = {
inherit script ;
description = " R e c o n f i g u r e t h e s y s t e m f r o m E C 2 u s e r d a t a o n s t a r t u p " ;
wantedBy = [ " s s h d . s e r v i c e " ] ;
before = [ " s s h d . s e r v i c e " ] ;
after = [ " n e t w o r k - o n l i n e . t a r g e t " ] ;
requires = [ " n e t w o r k - o n l i n e . t a r g e t " ] ;
restartIfChanged = false ;
unitConfig . X-StopOnRemoval = false ;
serviceConfig = {
Type = " o n e s h o t " ;
RemainAfterExit = true ;
} ;
} ;
}