2021-07-05 22:59:19 +02:00
|
|
|
{ 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 = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = lib.mkEnableOption ''
|
2021-07-05 22:59:19 +02:00
|
|
|
the Home Manager upgrade service that periodically updates your Nix
|
2023-07-02 01:45:18 +02:00
|
|
|
channels before running `home-manager switch`'';
|
2021-07-05 22:59:19 +02:00
|
|
|
|
|
|
|
frequency = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
example = "weekly";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-07-05 22:59:19 +02:00
|
|
|
The interval at which the Home Manager auto upgrade is run.
|
|
|
|
This value is passed to the systemd timer configuration
|
2023-07-01 01:30:13 +02:00
|
|
|
as the `OnCalendar` option.
|
2021-07-05 22:59:19 +02:00
|
|
|
The format is described in
|
2023-07-01 01:30:13 +02:00
|
|
|
{manpage}`systemd.time(7)`.
|
2021-07-05 22:59:19 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
'');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|