summary refs log tree commit diff
path: root/nixos/modules/installer/tools/auto-upgrade.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-08-07 05:28:17 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-08-07 05:37:31 +0200
commit43c47560906f80e67ccf093884a50bf3f2972a51 (patch)
treeede809589485a93a79eb56dd961e10d1b5473034 /nixos/modules/installer/tools/auto-upgrade.nix
parent80d9b426638563a6d8b6dc1604180cc60b4b2862 (diff)
downloadnixpkgs-43c47560906f80e67ccf093884a50bf3f2972a51.tar
nixpkgs-43c47560906f80e67ccf093884a50bf3f2972a51.tar.gz
nixpkgs-43c47560906f80e67ccf093884a50bf3f2972a51.tar.bz2
nixpkgs-43c47560906f80e67ccf093884a50bf3f2972a51.tar.lz
nixpkgs-43c47560906f80e67ccf093884a50bf3f2972a51.tar.xz
nixpkgs-43c47560906f80e67ccf093884a50bf3f2972a51.tar.zst
nixpkgs-43c47560906f80e67ccf093884a50bf3f2972a51.zip
Add auto update feature
You can now keep your system up to date automatically by setting:

  system.autoUpgrade.enable = true;

Fixes #7369.
Diffstat (limited to 'nixos/modules/installer/tools/auto-upgrade.nix')
-rw-r--r--nixos/modules/installer/tools/auto-upgrade.nix81
1 files changed, 81 insertions, 0 deletions
diff --git a/nixos/modules/installer/tools/auto-upgrade.nix b/nixos/modules/installer/tools/auto-upgrade.nix
new file mode 100644
index 00000000000..b2676b05a02
--- /dev/null
+++ b/nixos/modules/installer/tools/auto-upgrade.nix
@@ -0,0 +1,81 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let cfg = config.system.autoUpgrade; in
+
+{
+
+  options = {
+
+    system.autoUpgrade = {
+
+      enable = mkOption {
+        type = types.bool;
+        default = false;
+        description = ''
+          Whether to periodically upgrade NixOS to the latest
+          version. If enabled, a systemd timer will run
+          <literal>nixos-rebuild switch --upgrade</literal> once a
+          day.
+        '';
+      };
+
+      channel = mkOption {
+        type = types.nullOr types.str;
+        default = null;
+        example = https://nixos.org/channels/nixos-14.12-small;
+        description = ''
+          The URI of the NixOS channel to use for automatic
+          upgrades. By default, this is the channel set using
+          <command>nix-channel</command> (run <literal>nix-channel
+          --list</literal> to see the current value).
+        '';
+      };
+
+      flags = mkOption {
+        type = types.listOf types.str;
+        default = [];
+        example = [ "-I" "stuff=/home/alice/nixos-stuff" "--option" "extra-binary-caches" "http://my-cache.example.org/" ];
+        description = ''
+          Any additional flags passed to <command>nixos-rebuild</command>.
+        '';
+      };
+
+    };
+
+  };
+
+  config = {
+
+    system.autoUpgrade.flags =
+      [ "--no-build-output" ]
+      ++ (if cfg.channel == null
+          then [ "--upgrade" ]
+          else [ "-I" "nixpkgs=${cfg.channel}/nixexprs.tar.xz" ]);
+
+    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 SSL_CERT_FILE;
+          HOME = "/root";
+        };
+
+      path = [ pkgs.gnutar pkgs.xz config.nix.package ];
+
+      script = ''
+        ${config.system.build.nixos-rebuild}/bin/nixos-rebuild test ${toString cfg.flags}
+      '';
+
+      startAt = mkIf cfg.enable "04:40";
+    };
+
+  };
+
+}