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

nixos/nix-{gc,optimise}: make dates parameter more consistent #371483

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SFrijters
Copy link
Member

Kind of a followup to #362366

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@SFrijters SFrijters requested review from SuperSandro2000 and dasJ and removed request for SuperSandro2000 and dasJ January 6, 2025 16:06
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Jan 6, 2025
@SFrijters SFrijters changed the title nixos/nix-{gc,optimize}: more dates parameter more consistent nixos/nix-{gc,optimise}: more dates parameter more consistent Jan 6, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Jan 6, 2025
@SFrijters SFrijters changed the title nixos/nix-{gc,optimise}: more dates parameter more consistent nixos/nix-{gc,optimise}: make dates parameter more consistent Jan 6, 2025
@@ -86,7 +86,7 @@ in
description = "Nix Garbage Collector";
script = "exec ${config.nix.package.out}/bin/nix-collect-garbage ${cfg.options}";
serviceConfig.Type = "oneshot";
startAt = lib.optional cfg.automatic cfg.dates;
startAt = lib.optionals cfg.automatic cfg.dates;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want a potentially nested list here

Copy link
Member

Choose a reason for hiding this comment

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

Maybe check if it is a string and then put it into a list so we always have a list?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was wondering if that was necessary - I took this from the original nix-optimise but it looked weird to me.

type = with lib.types; listOf str;
default = "03:45";
type = with lib.types; either singleLineStr (listOf singleLineStr);
example = "weekly";
description = ''
Specification (in the format described by
Copy link
Member

Choose a reason for hiding this comment

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

We probably should adapt the description to mention that it can be a list

Copy link
Member Author

@SFrijters SFrijters Jan 7, 2025

Choose a reason for hiding this comment

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

I've slightly changed the description attribute for both; the type is also displayed directly on the options pages so that should be clear enough in combination?

@SFrijters SFrijters force-pushed the nixos-allow-list-or-string branch from 67f1782 to 5b01dab Compare January 7, 2025 16:24
@SFrijters SFrijters force-pushed the nixos-allow-list-or-string branch from 5b01dab to 45856c7 Compare January 7, 2025 16:30
@llakala
Copy link
Contributor

llakala commented Jan 7, 2025

I'll link #345573 here. It'd be nice to eventually standardize on one representation for dates.

@SFrijters
Copy link
Member Author

Ah, I didn't even know about that issue. If we can decide on the "correct" way I don't mind extending this PR to include autoUpgrade.

In my implementation I chose to make gc/optimise more relaxed about their inputs rather than deprecate something. Personally I am content if I can at least use a consistent format in my config, I don't mind which one it is.

@llakala
Copy link
Contributor

llakala commented Jan 7, 2025

There are many other modules than the specific three mentioned there that could do with being standardized. I just set up this search, using regex to avoid instances of systemd.timers or systemd.timedated. I'm sure it's not perfect, but it paints a strong enough picture. The types I saw used most often after scrolling through:

  • str (the most common by far)
  • singleLineStr
  • listOf str
  • either str (listOf str (allowing both)
  • unitOption (seen here. Intruiging, but a bit overly-verbose in my opinion.

Of these, I'd say the main three options are str, listOf str, and either (allowing both).

I personally think lists are the most clear when it comes to signaling to the user that multiple dates are accepted, but it would be a breaking change for many modules. Most people will also only put in one date, so they would end up constantly having to go through the inconvenience of a wrapping list.

If we decided not to go with listOf str, I think str would be my second choice. While I'm annoyed by the expected comma separator, I find either too ambiguous. People don't expect a list to take multiple types, and won't realize it unless they actually check the source code.

Final note - if we were to make a treewide change, I'd like to actually make a dates type in lib.types, and then just have all the modules use that as their type. This would set things up for the future well. Some documentation would also be nice. I realize I'm putting a lot on your plate for a PR that started out small - so I'm happy to collaborate with you on setting these things up if you're interested.

@SFrijters
Copy link
Member Author

To be honest, I was looking to scale back my nixpkgs time a bit this year and I just wanted to fix some personal annoyances. I don't think I'm the right person to spearhead this PR if the scope blows up so much.

@llakala
Copy link
Contributor

llakala commented Jan 8, 2025

Totally fine! I can make a future PR, then. I'll put my vote in for standardizing on a string. It breaks the least people's workflows, and matches the systemd standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants