lol

Add auto update feature

You can now keep your system up to date automatically by setting:

system.autoUpgrade.enable = true;

Fixes #7369.

+86
+81
nixos/modules/installer/tools/auto-upgrade.nix
··· 1 + { config, lib, pkgs, ... }: 2 + 3 + with lib; 4 + 5 + let cfg = config.system.autoUpgrade; in 6 + 7 + { 8 + 9 + options = { 10 + 11 + system.autoUpgrade = { 12 + 13 + enable = mkOption { 14 + type = types.bool; 15 + default = false; 16 + description = '' 17 + Whether to periodically upgrade NixOS to the latest 18 + version. If enabled, a systemd timer will run 19 + <literal>nixos-rebuild switch --upgrade</literal> once a 20 + day. 21 + ''; 22 + }; 23 + 24 + channel = mkOption { 25 + type = types.nullOr types.str; 26 + default = null; 27 + example = https://nixos.org/channels/nixos-14.12-small; 28 + description = '' 29 + The URI of the NixOS channel to use for automatic 30 + upgrades. By default, this is the channel set using 31 + <command>nix-channel</command> (run <literal>nix-channel 32 + --list</literal> to see the current value). 33 + ''; 34 + }; 35 + 36 + flags = mkOption { 37 + type = types.listOf types.str; 38 + default = []; 39 + example = [ "-I" "stuff=/home/alice/nixos-stuff" "--option" "extra-binary-caches" "http://my-cache.example.org/" ]; 40 + description = '' 41 + Any additional flags passed to <command>nixos-rebuild</command>. 42 + ''; 43 + }; 44 + 45 + }; 46 + 47 + }; 48 + 49 + config = { 50 + 51 + system.autoUpgrade.flags = 52 + [ "--no-build-output" ] 53 + ++ (if cfg.channel == null 54 + then [ "--upgrade" ] 55 + else [ "-I" "nixpkgs=${cfg.channel}/nixexprs.tar.xz" ]); 56 + 57 + systemd.services.nixos-upgrade = { 58 + description = "NixOS Upgrade"; 59 + 60 + restartIfChanged = false; 61 + unitConfig.X-StopOnRemoval = false; 62 + 63 + serviceConfig.Type = "oneshot"; 64 + 65 + environment = config.nix.envVars // 66 + { inherit (config.environment.sessionVariables) NIX_PATH SSL_CERT_FILE; 67 + HOME = "/root"; 68 + }; 69 + 70 + path = [ pkgs.gnutar pkgs.xz config.nix.package ]; 71 + 72 + script = '' 73 + ${config.system.build.nixos-rebuild}/bin/nixos-rebuild test ${toString cfg.flags} 74 + ''; 75 + 76 + startAt = mkIf cfg.enable "04:40"; 77 + }; 78 + 79 + }; 80 + 81 + }
+4
nixos/modules/installer/tools/tools.nix
··· 57 57 in 58 58 59 59 { 60 + 60 61 config = { 62 + 61 63 environment.systemPackages = 62 64 [ nixos-build-vms 63 65 nixos-install ··· 70 72 system.build = { 71 73 inherit nixos-install nixos-generate-config nixos-option nixos-rebuild; 72 74 }; 75 + 73 76 }; 77 + 74 78 }
+1
nixos/modules/module-list.nix
··· 41 41 ./hardware/video/bumblebee.nix 42 42 ./hardware/video/nvidia.nix 43 43 ./hardware/video/ati.nix 44 + ./installer/tools/auto-upgrade.nix 44 45 ./installer/tools/nixos-checkout.nix 45 46 ./installer/tools/tools.nix 46 47 ./misc/assertions.nix