Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic rebuild on every push to master #5

Open
zupo opened this issue Oct 10, 2019 · 1 comment
Open

Automatic rebuild on every push to master #5

zupo opened this issue Oct 10, 2019 · 1 comment

Comments

@zupo
Copy link
Owner

zupo commented Oct 10, 2019

I want the tv device to automatically pull latest changes and run nixos-rebuild && reboot every time tv.nix is updated in GitHub's master.

Ideas:

  • use cron to run git pull && nixos-rebuild
  • run a small webservice that listens to GitHub webhooks and then runs git pull && nixos-rebuild
  • something smarter?

Bonus karma points if it automatically boots into previous configuration in case it cannot boot into the new configuration.

@infinisil
Copy link

Unless very low latency updates are needed, I'd think a cron job or systemd timer would work best for this indeed, because then it doesn't depend on having some external stateful setup (e.g. a webhook setup for the GitHub repo), so it's more self-contained. This in turn also means that it's possible to easily use alternate git repositories.

Personally I'd recommend a systemd timer/service as they're more flexible than cron jobs (though a bit more verbose to set up too). A timer/service combo can look like this:

{
  systemd.timers.git-updater = {
    wantedBy = [ "timers.target" ];
    # Wait 60 seconds after the service finished before starting it again
    # This should prevent the service being started again too early if an update is in progress
    timerConfig.OnUnitInactiveSec = 60;
  };
  systemd.services.git-updater = {
    # I'm not entirely sure why this would be needed
    serviceConfig.Type = "oneshot";
    script = ''
      # Update script here
    '';
  };
}

And I already have a working update script for git repos here that can be adapted: https://github.com/Infinisil/nixbot/blob/feefc301bbe44742570bce0974005a2714a950e6/module.nix#L84-L113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants