summary refs log tree commit diff
path: root/nixos/modules/tasks/auto-upgrade.nix
diff options
context:
space:
mode:
authorzimbatm <zimbatm@zimbatm.com>2017-12-17 20:32:56 +0000
committerzimbatm <zimbatm@zimbatm.com>2018-11-17 14:05:30 +0100
commit7b9a553e21d53069a86600d9274c0201ee06767e (patch)
tree3fe62386daa195e30668e9df07383d8e4d865c6c /nixos/modules/tasks/auto-upgrade.nix
parentb56191746ea57bd89ed17819f2ad0ac2b3b29533 (diff)
downloadnixpkgs-7b9a553e21d53069a86600d9274c0201ee06767e.tar
nixpkgs-7b9a553e21d53069a86600d9274c0201ee06767e.tar.gz
nixpkgs-7b9a553e21d53069a86600d9274c0201ee06767e.tar.bz2
nixpkgs-7b9a553e21d53069a86600d9274c0201ee06767e.tar.lz
nixpkgs-7b9a553e21d53069a86600d9274c0201ee06767e.tar.xz
nixpkgs-7b9a553e21d53069a86600d9274c0201ee06767e.tar.zst
nixpkgs-7b9a553e21d53069a86600d9274c0201ee06767e.zip
nixos: move system.autoUpgrade
This is not installer-specific
Diffstat (limited to 'nixos/modules/tasks/auto-upgrade.nix')
-rw-r--r--nixos/modules/tasks/auto-upgrade.nix92
1 files changed, 92 insertions, 0 deletions
diff --git a/nixos/modules/tasks/auto-upgrade.nix b/nixos/modules/tasks/auto-upgrade.nix
new file mode 100644
index 00000000000..7b756b70e2f
--- /dev/null
+++ b/nixos/modules/tasks/auto-upgrade.nix
@@ -0,0 +1,92 @@
+{ 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>.
+        '';
+      };
+
+      dates = mkOption {
+        default = "04:40";
+        type = types.str;
+        description = ''
+          Specification (in the format described by
+          <citerefentry><refentrytitle>systemd.time</refentrytitle>
+          <manvolnum>7</manvolnum></citerefentry>) of the time at
+          which the update will occur.
+        '';
+      };
+
+    };
+
+  };
+
+  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;
+          HOME = "/root";
+        } // config.networking.proxy.envVars;
+
+      path = [ pkgs.gnutar pkgs.xz.bin config.nix.package.out ];
+
+      script = ''
+        ${config.system.build.nixos-rebuild}/bin/nixos-rebuild switch ${toString cfg.flags}
+      '';
+
+      startAt = optional cfg.enable cfg.dates;
+    };
+
+  };
+
+}