amazon-init.nix: Don't run nixos-rebuild if we don't have to

This commit is contained in:
Eelco Dolstra 2016-02-04 15:15:19 +01:00
parent 98b365386a
commit 95584666e9

View File

@ -6,7 +6,7 @@ let
bootScript = pkgs.writeScript "bootscript.sh" '' bootScript = pkgs.writeScript "bootscript.sh" ''
#!${pkgs.stdenv.shell} -eux #!${pkgs.stdenv.shell} -eux
echo "attempting to fetch configuration from user-data..." echo "attempting to fetch configuration from EC2 user data..."
export PATH=${config.nix.package}/bin:${pkgs.wget}/bin:${pkgs.systemd}/bin:${pkgs.gnugrep}/bin:${pkgs.gnused}/bin:${config.system.build.nixos-rebuild}/bin:$PATH export PATH=${config.nix.package}/bin:${pkgs.wget}/bin:${pkgs.systemd}/bin:${pkgs.gnugrep}/bin:${pkgs.gnused}/bin:${config.system.build.nixos-rebuild}/bin:$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 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
@ -15,7 +15,7 @@ let
wget -q --wait=1 --tries=0 --retry-connrefused -O - http://169.254.169.254/2011-01-01/user-data > "$userData" wget -q --wait=1 --tries=0 --retry-connrefused -O - http://169.254.169.254/2011-01-01/user-data > "$userData"
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo "user-data fetched"
# If the user-data looks like it could be a nix expression, # 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 # copy it over. Also, look for a magic three-hash comment and set
# that as the channel. # that as the channel.
@ -30,17 +30,17 @@ let
nix-channel --update nix-channel --update
fi fi
echo "setting configuration" echo "setting configuration from EC2 user data"
cp "$userData" /etc/nixos/configuration.nix cp "$userData" /etc/nixos/configuration.nix
else else
echo "user-data does not appear to be a nix expression; ignoring" echo "user data does not appear to be a Nix expression; ignoring"
exit
fi fi
else else
echo "failed to fetch user-data" echo "failed to fetch user data"
exit
fi fi
type -f nixos-rebuild
nixos-rebuild switch nixos-rebuild switch
''; '';
in { in {