From 901670f5f4337998c430ae27c3b31f6db4a5a8fe Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Fri, 10 Apr 2020 20:46:04 -0700 Subject: [PATCH 1/1] Auto-upgrade with pinch --- modules/auto-upgrade.nix | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 modules/auto-upgrade.nix diff --git a/modules/auto-upgrade.nix b/modules/auto-upgrade.nix new file mode 100644 index 0000000..973ac22 --- /dev/null +++ b/modules/auto-upgrade.nix @@ -0,0 +1,68 @@ +{ config, lib, pkgs, ... }: +with lib; +let cfg = config.system.autoUpgradeWithPinch; +in { + options = { + system.autoUpgradeWithPinch = { + + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to periodically upgrade NixOS to the latest version. + Presumes that /etc/nixos is a git repo with a remote and + contains a pinch file called "channels". + ''; + }; + + dates = mkOption { + default = "04:40"; + type = types.str; + description = '' + Specification (in the format described by + systemd.time + 7) of the time at + which the update will occur. + ''; + }; + }; + }; + + config = lib.mkIf cfg.enable { + nixpkgs.overlays = [ (import ../overlays/pinch.nix) ]; + systemd.services.nixos-upgrade = { + description = "NixOS Upgrade"; + restartIfChanged = false; + unitConfig.X-StopOnRemoval = false; + serviceConfig.Type = "oneshot"; + environment = config.nix.envVars // { + inherit (config.environment.sessionVariables) NIX_PATH; + HOME = "/root"; + } // config.networking.proxy.envVars; + + path = with pkgs; [ + config.nix.package.out + coreutils + git + gitMinimal + gnutar + gzip + pinch + xz.bin + ]; + + script = '' + set -e + ( + cd /etc/nixos + git pull --ff-only + pinch update channels + ) + + ${config.system.build.nixos-rebuild}/bin/nixos-rebuild switch --no-build-output + ''; + + startAt = cfg.dates; + }; + }; +} -- 2.44.1