mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 12:45:27 +03:00
amazon-init NixOS module: fix (I think) race condition with network
The initialization code is now a systemd service that explicitly waits for network-online, so the occasional failure I was seeing because the `nixos-rebuild` couldn't get anything from the binary cache should stop. I hope!
This commit is contained in:
parent
7943dc8978
commit
b172684c17
1 changed files with 21 additions and 8 deletions
|
@ -1,20 +1,18 @@
|
||||||
{ config, pkgs, modulesPath, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
# This attempts to pull a nix expression from this EC2 instance's user-data.
|
|
||||||
|
|
||||||
let
|
let
|
||||||
bootScript = pkgs.writeScript "bootscript.sh" ''
|
script = ''
|
||||||
#!${pkgs.stdenv.shell} -eu
|
#!${pkgs.stdenv.shell} -eu
|
||||||
|
|
||||||
echo "attempting to fetch configuration from EC2 user data..."
|
echo "attempting to fetch configuration from EC2 user data..."
|
||||||
|
|
||||||
|
export HOME=/root
|
||||||
export PATH=${pkgs.lib.makeBinPath [ config.nix.package pkgs.systemd pkgs.gnugrep pkgs.gnused config.system.build.nixos-rebuild]}:$PATH
|
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
|
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
|
userData=/etc/ec2-metadata/user-data
|
||||||
|
|
||||||
if [ -s "$userData" ]; then
|
if [ -s "$userData" ]; then
|
||||||
|
|
||||||
# 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.
|
||||||
|
@ -43,7 +41,22 @@ let
|
||||||
nixos-rebuild switch
|
nixos-rebuild switch
|
||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
boot.postBootCommands = ''
|
systemd.services.amazon-init = {
|
||||||
${bootScript} &
|
inherit script;
|
||||||
'';
|
description = "Reconfigure the system from EC2 userdata on startup";
|
||||||
|
|
||||||
|
wantedBy = [ "sshd.service" ];
|
||||||
|
before = [ "sshd.service" ];
|
||||||
|
after = [ "network-online.target" ];
|
||||||
|
requires = [ "network-online.target" ];
|
||||||
|
|
||||||
|
restartIfChanged = false;
|
||||||
|
unitConfig.X-StopOnRemoval = false;
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue