1 { config, lib, pkgs, ... }:
3 let cfg = config.system.autoUpgradeWithPinch;
6 system.autoUpgradeWithPinch = {
12 Whether to periodically upgrade NixOS to the latest version.
13 Presumes that /etc/nixos is a git repo with a remote and
14 contains a pinch file called "channels".
22 Specification (in the format described by
23 <citerefentry><refentrytitle>systemd.time</refentrytitle>
24 <manvolnum>7</manvolnum></citerefentry>) of the time at
25 which the update will occur.
32 GPG key that signs updates. Updates are only merged if the commit
33 at the tip of the remote branch is signed with this key.
39 config = lib.mkIf cfg.enable {
41 (import ../overlays/keyedgit.nix)
42 (import ../overlays/pinch.nix)
44 auto-upgrade = super.writeShellScriptBin "auto-upgrade" ''
48 ${self.keyedgit cfg.key}/bin/git pull --ff-only --verify-signatures
49 ${self.pinch}/bin/pinch update channels
52 ${config.system.build.nixos-rebuild}/bin/nixos-rebuild switch --no-build-output
57 environment.systemPackages = [ pkgs.auto-upgrade ];
59 systemd.services.nixos-upgrade = {
60 description = "NixOS Upgrade";
61 restartIfChanged = false;
62 unitConfig.X-StopOnRemoval = false;
63 serviceConfig.Type = "oneshot";
64 environment = config.nix.envVars // {
65 inherit (config.environment.sessionVariables) NIX_PATH;
67 } // config.networking.proxy.envVars;
70 config.nix.package.out
82 # Chill for awhile before applying updates. If applying an update
83 # badly breaks things, we want a window in which an operator can
84 # intervene either to fix the problem or disable automatic updates.
87 ${pkgs.auto-upgrade}/bin/auto-upgrade