Stream: nix

Topic: ✔ automatic gc in home-manager


view this post on Zulip Shivaraj B H (Jan 27 2024 at 02:51):

I am planning to add automatic gc to home-manager and in mac it would be via launchd, if you would like to try out launchd in your home-manager config, here’s a simple example:

{
  launchd = {
    enable = true;
    agents = {
     hello = {
       enable = true;
       config = {
         ProgramArguments = [ "say" "hello" ];
         StartCalendarInterval = [
           {
             Minute = 0;
           }
         ];
       };
     };
    };
  };
}

This agent will say hello at 0th minute of every hour

view this post on Zulip Shivaraj B H (Jan 28 2024 at 04:12):

I have an initial draft ready and has been tested on macOS:
https://github.com/shivaraj-bh/home-manager/tree/nix-gc

Will test on linux before raising a PR

view this post on Zulip Shivaraj B H (Jan 28 2024 at 04:16):

Try it out in your home-manager config:
Add my home-manager flake to your inputs:

{
  inputs.home-manager.url = github:shivaraj-bh/home-manager/nix-gc;
}

Add the service:

{
  services.nix-gc = {
    enable = true;
    frequency = monthly";
  };
}

To see the status of the agent, run:

launchctl print gui/501/org.nix-community.home.nix-gc

And to verify if it is working fine, you can kickstart the agent manually and check the logs in /tmp/nix-gc.log:

launchctl kickstart gui/501/org.nix-community.home.nix-gc
tail /tmp/nix-gc.log

I will be removing the log file while raising a PR, this is just to debug.

view this post on Zulip Srid (Jan 28 2024 at 09:57):

Tangential: https://github.com/LnL7/nix-darwin/issues/746

view this post on Zulip Shivaraj B H (Jan 29 2024 at 05:05):

I have now changed the API to be same as nixos, enabling gc will look like:

{
  nix.gc = {
     automatic = true;
     frequency = monthly;
  };
}

I have tested it on linux as well, this is how you can check the status of the systemd service on linux:

systemctl —user status nix-gc

—user is used because home-manager spawns up user units and not system units (as done by nixos module).

To manually trigger gc, run:

systemctl —user start nix-gc

view this post on Zulip Shivaraj B H (Jan 29 2024 at 05:07):

Overall, it looks good to raise a PR and I am only worried about the convention to choose frequency option be an enum, which I think will be bought up in the PR discussion and we can resolve it then.

view this post on Zulip Shivaraj B H (Jan 29 2024 at 13:12):

https://github.com/nix-community/home-manager/pull/4973

view this post on Zulip Shivaraj B H (Feb 06 2024 at 04:16):

And it is merged! Also raised a PR to juspay/nix-dev-home to use it in the template.

view this post on Zulip Notification Bot (Feb 06 2024 at 11:03):

Shivaraj B H has marked this topic as resolved.


Last updated: Nov 15 2024 at 12:33 UTC