-
-
Save grahamc/0aee1ca28d7dcf6aa3a22d6e4935a5bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
path_exists channel { | |
format = "" | |
format_down = "Upgrade!" | |
path = "/var/lib/is-nix-channel-up-to-date/up-to-date" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, pkgs, ... }: | |
{ | |
users = { | |
users.is-nix-channel-up-to-date = { | |
description = "Is-Nix-Channel-Up-To-Date"; | |
home = "/var/lib/is-nix-channel-up-to-date"; | |
createHome = true; | |
group = "is-nix-channel-up-to-date"; | |
uid = 400; | |
}; | |
groups.is-nix-channel-up-to-date.gid = 400; | |
}; | |
systemd.services.is-nix-channel-up-to-date = { | |
enable = true; | |
after = [ "network.target" "network-online.target" ]; | |
wants = [ "network-online.target" ]; | |
wantedBy = [ "multi-user.target" ]; | |
environment.VERSION_LOCAL = config.system.nixosRevision; | |
path = with pkgs; [ curl coreutils ]; | |
serviceConfig = { | |
User = "is-nix-channel-up-to-date"; | |
Group = "is-nix-channel-up-to-date"; | |
PrivateTmp = true; | |
WorkingDirectory = "/var/lib/is-nix-channel-up-to-date"; | |
}; | |
preStart = '' | |
chmod 755 /var/lib/is-nix-channel-up-to-date | |
''; | |
script = "${./is-nix-up-to-date.sh}"; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
CHAN=17.09 | |
DELAY=675 | |
SENTINAL=/var/lib/is-nix-channel-up-to-date/up-to-date | |
fetch_channel_version() { | |
curl "https://channels.nix.gsc.io/nixos-$CHAN/latest" \ | |
| cut -d' ' -f1 | |
} | |
remove_sentinal() { | |
echo "Removing sentinal from $SENTINAL" | |
rm "$SENTINAL" | |
exit 0 | |
} | |
VERSION_CHAN=$(fetch_channel_version) | |
echo "Channel starts at $VERSION_CHAN" | |
echo "System is at $VERSION_LOCAL" | |
if [ "$VERSION_CHAN" == "$VERSION_LOCAL" ]; then | |
touch "$SENTINAL" | |
else | |
remove_sentinal | |
fi | |
while true; do | |
sleep "$DELAY" | |
VERSION_CHAN=$(fetch_channel_version) | |
if [ "$VERSION_CHAN" != "$VERSION_LOCAL" ]; then | |
printf "Channel changed to %s\n" "$VERSION_CHAN" | |
remove_sentinal | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment