Skip to content

Instantly share code, notes, and snippets.

@grahamc

grahamc/i3bar Secret

Last active October 11, 2017 21:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grahamc/0aee1ca28d7dcf6aa3a22d6e4935a5bc to your computer and use it in GitHub Desktop.
Save grahamc/0aee1ca28d7dcf6aa3a22d6e4935a5bc to your computer and use it in GitHub Desktop.
path_exists channel {
format = ""
format_down = "Upgrade!"
path = "/var/lib/is-nix-channel-up-to-date/up-to-date"
}
{ 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}";
};
}
#!/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