diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 3e9c649ac..a7ca64796 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -292,6 +292,9 @@
/modules/services/gromit-mpx.nix @pjones
/tests/modules/services/gromit-mpx @pjones
+/modules/services/home-manager-auto-upgrade.nix @pinage404
+/tests/modules/services/home-manager-auto-upgrade @pinage404
+
/modules/services/hound.nix @adisbladis
/modules/services/imapnotify.nix @nickhu
diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix
index 0a54d1e02..f912bbd5f 100644
--- a/modules/lib/maintainers.nix
+++ b/modules/lib/maintainers.nix
@@ -193,4 +193,10 @@
githubId = 9267430;
name = "Philipp Mildenberger";
};
+ pinage404 = {
+ name = "pinage404";
+ email = "pinage404@gmail.com";
+ github = "pinage404";
+ githubId = 6325757;
+ };
}
diff --git a/modules/modules.nix b/modules/modules.nix
index a8c3e36bb..ce657ecd0 100644
--- a/modules/modules.nix
+++ b/modules/modules.nix
@@ -185,6 +185,7 @@ let
./services/gpg-agent.nix
./services/grobi.nix
./services/gromit-mpx.nix
+ ./services/home-manager-auto-upgrade.nix
./services/hound.nix
./services/imapnotify.nix
./services/kanshi.nix
diff --git a/modules/services/home-manager-auto-upgrade.nix b/modules/services/home-manager-auto-upgrade.nix
new file mode 100644
index 000000000..2f975ef1b
--- /dev/null
+++ b/modules/services/home-manager-auto-upgrade.nix
@@ -0,0 +1,69 @@
+{ config, lib, pkgs, ... }:
+
+let
+
+ cfg = config.services.home-manager.autoUpgrade;
+
+ homeManagerPackage = pkgs.callPackage ../../home-manager {
+ path = config.programs.home-manager.path;
+ };
+
+in {
+ meta.maintainers = [ lib.hm.maintainers.pinage404 ];
+
+ options = {
+ services.home-manager.autoUpgrade = {
+ enable = lib.mkEnableOption ''
+ the Home Manager upgrade service that periodically updates your Nix
+ channels before running home-manager switch
'';
+
+ frequency = lib.mkOption {
+ type = lib.types.str;
+ example = "weekly";
+ description = ''
+ The interval at which the Home Manager auto upgrade is run.
+ This value is passed to the systemd timer configuration
+ as the OnCalendar
option.
+ The format is described in
+
+ systemd.time
+ 7
+ .
+ '';
+ };
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ assertions = [
+ (lib.hm.assertions.assertPlatform "services.home-manager.autoUpgrade" pkgs
+ lib.platforms.linux)
+ ];
+
+ systemd.user = {
+ timers.home-manager-auto-upgrade = {
+ Unit.Description = "Home Manager upgrade timer";
+
+ Install.WantedBy = [ "timers.target" ];
+
+ Timer = {
+ OnCalendar = cfg.frequency;
+ Unit = "home-manager-auto-upgrade.service";
+ Persistent = true;
+ };
+ };
+
+ services.home-manager-auto-upgrade = {
+ Unit.Description = "Home Manager upgrade";
+
+ Service.ExecStart = toString
+ (pkgs.writeShellScript "home-manager-auto-upgrade" ''
+ echo "Update Nix's channels"
+ ${pkgs.nix}/bin/nix-channel --update
+ echo "Upgrade Home Manager"
+ ${homeManagerPackage}/bin/home-manager switch
+ '');
+ };
+ };
+ };
+}
diff --git a/tests/default.nix b/tests/default.nix
index 3a2eb4ffc..da6644f59 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -143,6 +143,7 @@ import nmt {
./modules/services/git-sync
./modules/services/gpg-agent
./modules/services/gromit-mpx
+ ./modules/services/home-manager-auto-upgrade
./modules/services/kanshi
./modules/services/lieer
./modules/services/pantalaimon
diff --git a/tests/modules/services/home-manager-auto-upgrade/basic-configuration.nix b/tests/modules/services/home-manager-auto-upgrade/basic-configuration.nix
new file mode 100644
index 000000000..444c88624
--- /dev/null
+++ b/tests/modules/services/home-manager-auto-upgrade/basic-configuration.nix
@@ -0,0 +1,18 @@
+{ config, ... }:
+
+{
+ config = {
+ services.home-manager.autoUpgrade = {
+ enable = true;
+ frequency = "00:00";
+ };
+
+ nmt.script = ''
+ serviceFile=home-files/.config/systemd/user/home-manager-auto-upgrade.service
+ assertFileExists $serviceFile
+
+ timerFile=home-files/.config/systemd/user/home-manager-auto-upgrade.timer
+ assertFileExists $timerFile
+ '';
+ };
+}
diff --git a/tests/modules/services/home-manager-auto-upgrade/default.nix b/tests/modules/services/home-manager-auto-upgrade/default.nix
new file mode 100644
index 000000000..fb09ebc38
--- /dev/null
+++ b/tests/modules/services/home-manager-auto-upgrade/default.nix
@@ -0,0 +1 @@
+{ home-manager-auto-upgrade-basic-configuration = ./basic-configuration.nix; }