Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nh: add module #5304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

JohnRTitor
Copy link
Contributor

@JohnRTitor JohnRTitor commented Apr 19, 2024

Description

nh is a Nix CLI helper designed to provide beautiful outputs when rebuilding system or garbage collecting. Module already exists for NixOS, and so should for home manager too.

This PR

  • adds programs.nh option
  • Add nh to news
  • Add johnrtitor as maintainer

Checklist

  • Change is backwards compatible.

  • Code formatted with ./format.

  • Code tested through nix-shell --pure tests -A run.all or nix develop --ignore-environment .#all using Flakes.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.

Maintainer CC

initial PR, I'll be maintaining this HM module

@JohnRTitor JohnRTitor force-pushed the nh-module branch 2 times, most recently from fe38e36 to 11b0c04 Compare April 19, 2024 19:06
@JohnRTitor
Copy link
Contributor Author

JohnRTitor commented Apr 19, 2024

Note: this home manager module can also run garbage collection systemd service. However it is only limited to user scope, unlike its NixOS sibling module.

Comment on lines +75 to +77
services.nh-clean = {
description = "Nh clean (user)";
script =
"exec ${lib.getExe cfg.package} clean user ${cfg.clean.extraArgs}";
startAt = cfg.clean.dates;
path = [ config.nix.package ];
serviceConfig.Type = "oneshot";
};

timers.nh-clean = { timerConfig = { Persistent = true; }; };
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is coming from some NixOS module. It will not work on HM since it does not use the same option naming for systemd units.

I would suggest creating some test case that enables the nh-clean service and then tests the content of the generated unit files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions. Indeed this is coming from a NixOS module.
I am trying to recreate the following in Home Manager syntax. How do I set these? LOCALE_ARCHIVE, variable, for example. I am new to NixOS and Nix syntax.

The following is the content of nh-clean.service.

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/zbn9jsvqg4gp6dsa01gmfwald132fk49-glibc-locales-2.39-31/lib/locale/locale-archive"
Environment="PATH=/nix/store/5dyaxm5ksj6956xbnssyr2pwm4bq9jkf-nix-2.18.2/bin:/nix/store/hq8765g3p1i7qbargnqli5mn0jpsdbfl-coreutils-9.5/bin:/nix/store/d1v47ybpl5cv9ycffgbfagfhvbvj8xdx-findutils-4.9.0/bin:/nix/store/wy37jk2hirzqzx0666w1849kjdgzdam6-gnugrep-3.11/bin:/nix/store/4cps736z7in3d37qc801lwv9z0ib67ps-gnused-4.9/bin:/nix/store/7kq9hvrhcy8g1v0jd07nr54279asg9vc-systemd-255.4/bin:/nix/store/5dyaxm5ksj6956xbnssyr2pwm4bq9jkf-nix-2.18.2/sbin:/nix/store/hq8765g3p1i7qbargnqli5mn0jpsdbfl-coreutils-9.5/sbin:/nix/store/d1v47ybpl5cv9ycffgbfagfhvbvj8xdx-findutils-4.9.0/sbin:/nix/store/wy37jk2hirzqzx0666w1849kjdgzdam6-gnugrep-3.11/sbin:/nix/store/4cps736z7in3d37qc801lwv9z0ib67ps-gnused-4.9/sbin:/nix/store/7kq9hvrhcy8g1v0jd07nr54279asg9vc-systemd-255.4/sbin"
Environment="TZDIR=/nix/store/7lzfzr3xsdgscccnfl9rykiwncwwvhbi-tzdata-2024a/share/zoneinfo"
ExecStart=/nix/store/8454db7gv30ls496k5cam45j1amykrnn-unit-script-nh-clean-start/bin/nh-clean-start
Type=oneshot

I was able to convert the timers config :)

      timers.nh-clean = {
        Timer = {
          OnCalendar = cfg.clean.dates;
          Persistent = true;
        };
      };

Or we can simply remove the service part and get it going.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rycee any suggestions?

modules/lib/maintainers.nix Outdated Show resolved Hide resolved
modules/programs/nh.nix Outdated Show resolved Hide resolved
@rycee
Copy link
Member

rycee commented Apr 21, 2024

Thanks for the contribution! I've added a few comments.

Add nh to news
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants