Skip to content

Instantly share code, notes, and snippets.

@ocharles
Created January 7, 2020 16:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ocharles/fa4ad515d723108a0e0663b1af383e49 to your computer and use it in GitHub Desktop.
Save ocharles/fa4ad515d723108a0e0663b1af383e49 to your computer and use it in GitHub Desktop.
{ pkgs, ... }:
{
systemd.services.auto-upgrade = {
serviceConfig.Type = "oneshot";
startAt = "hourly";
# This is required as otherwise the call to "switch" will stop this very
# unit, preventing the upgrade from completing.
unitConfig.X-StopOnRemoval = false;
script = ''
# Fetch the name of the latest output
OUT=$( curl --location --silent 'http://hydra/job/<name>/'"$(< /etc/tracking)"'/latest/api/get-info' | jq -r .outPath )
# Realise the output and make it valid. This will fetch the output from
# Hydra.
nix-store --realise --ignore-unknown "$OUT"
# Run "switch" to activate the configuration. If the fetch failed, this
# file won't exist and the unit will fail.
"$OUT/bin/switch-to-configuration" boot
# Add a GC root.
nix-env --profile /nix/var/nix/profiles/system --set "$OUT"
'';
path = with pkgs; [ curl jq nix ];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment