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
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
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.
Tangential: https://github.com/LnL7/nix-darwin/issues/746
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
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.
https://github.com/nix-community/home-manager/pull/4973
And it is merged! Also raised a PR to juspay/nix-dev-home to use it in the template.
Shivaraj B H has marked this topic as resolved.
Last updated: Nov 15 2024 at 12:33 UTC