From dc9251000e78e6382b17616aed6193462c574536 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Sat, 3 Feb 2024 21:02:24 +0100 Subject: [PATCH] feat(users): cleanup old home-manager profiles --- users/deck/home.nix | 3 +++ users/malte/home.nix | 3 +++ users/marie/home.nix | 7 +++++- users/modules/profiles-cleanup.nix | 38 ++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 users/modules/profiles-cleanup.nix diff --git a/users/deck/home.nix b/users/deck/home.nix index ac0fc34..be24d69 100644 --- a/users/deck/home.nix +++ b/users/deck/home.nix @@ -29,6 +29,7 @@ in { imports = [ ../modules/boilr.nix ../modules/restic-backup.nix + ../modules/profiles-cleanup.nix ]; config = { @@ -48,6 +49,8 @@ in { }; }; + xdg.enable = true; + # Make sure firefox is my default browser programs.firefox.enable = true; diff --git a/users/malte/home.nix b/users/malte/home.nix index 01b562a..f453866 100644 --- a/users/malte/home.nix +++ b/users/malte/home.nix @@ -118,6 +118,7 @@ in { ./nb.nix ../modules/restic-backup.nix ../modules/colors.nix + ../modules/profiles-cleanup.nix ]; config = { @@ -208,6 +209,8 @@ in { }; }; + xdg.enable = true; + # Make sure firefox is my default browser programs.firefox.enable = true; diff --git a/users/marie/home.nix b/users/marie/home.nix index 0ecafc9..967e537 100644 --- a/users/marie/home.nix +++ b/users/marie/home.nix @@ -18,7 +18,10 @@ ]; })); in { - imports = [../modules/restic-backup.nix]; + imports = [ + ../modules/restic-backup.nix + ../modules/profiles-cleanup.nix + ]; config = { home.packages = with pkgs; [ @@ -46,6 +49,8 @@ in { programs.broot.enable = true; programs.fish.enable = true; + xdg.enable = true; + services.restic = { enable = true; paths = ["/home/marie/Uni" "/home/marie/Bilder" "/home/marie/Promotion"]; diff --git a/users/modules/profiles-cleanup.nix b/users/modules/profiles-cleanup.nix new file mode 100644 index 0000000..ea801e7 --- /dev/null +++ b/users/modules/profiles-cleanup.nix @@ -0,0 +1,38 @@ +{ + pkgs, + lib, + config, + ... +}: { + # This is a fix for https://github.com/nix-community/home-manager/issues/4672 + systemd.user = { + services = { + home-manager-profiles-cleanup = { + Unit.Description = "Clean up HM user profiles."; + + Service = { + Type = "oneshot"; + ExecStart = lib.getExe (pkgs.writeShellApplication { + name = "home-manager-profiles-cleanup-start-script"; + text = '' + ${lib.getExe config.nix.package} profile wipe-history \ + --profile "${config.xdg.stateHome}/nix/profiles/home-manager" \ + --older-than '30d' + ''; + }); + }; + }; + }; + + timers.home-manager-profiles-cleanup = { + Unit.Description = "Clean up HM user profiles."; + + Timer = { + OnCalendar = "weekly"; + Persistent = true; + }; + + Install.WantedBy = ["timers.target"]; + }; + }; +}