-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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
Evaluation-time checking of systemd units #153369
Comments
On NixOS 20.03, I used this implementation: # Example:
# serviceUnitOf cfg.systemd.services.myservice == "myservice.service"
serviceUnitOf = service: "${service._module.args.name}.service"; so I could write:
and that would also fail at evaluation time if the service wasn't defined. But that stopped working with PR #82751: @roberth suggested an improvement in #82751 (comment) that I haven't fully gone through yet. I opened this issue so that we can discuss the concept here properly, instead of in a closed PR. |
I have more thoroughly tried the implementation by @roberth in #82751 (comment) now. Seems to work well so far! Any points against it? |
This will only work for units configured via This means, it can only be used for some units, which might be very confusing. A "linter" phase while assembling the system closure might work better, and also cover these use cases, without requiring any changes to the module system. What do you think? |
s/module system/the module/ You're making it sound complicated :) It'd be a good refactor regardless, to use the new option in the systemd module internally, but maybe not for the purpose of checking whether units exist, as you've explained clearly. It should be a build-time check, as eval does not have all the info. A build-time check may not be as convenient in some cases, but that doesn't seem as important. |
Might want to port |
The following is a module, when imported in a submodule, sets the name of the unit to the name which is used to name the attribute set: { name, lib, ... }: {
options.unitName = lib.mkOption {
type = lib.types.str;
example = "<name>";
description = ''
Name of the unit, without suffix like ".service"
'';
};
config.unitName = lib.mkDefault name;
} Note, |
@nbp the point was to include the suffix. My original suggestion: #82751 (comment) |
I _think_ `wants` (or `wantedBy`) is the common link in all the times where I've suffered huge `nixos-rebuild` times. But I'm not certain. It's hard to debug things which take hours and can only seem to be fixed by pulling the power. Which genuinely does seem to "fix" things sometimes - see https://www.reddit.com/r/NixOS/comments/ps4p42/comment/i3t3c4d/?utm_source=share&utm_medium=web2x&context=3. This issue may be related, but perhaps I'm misreading it: NixOS/nixpkgs#153369.
Potentially implemented by I asked there for a short comparison: #297726 (comment) |
This ticket describes a way how we can make writing systemd dependencies much safer, but I need help with making its implementation better.
In my deployments we have many NixOS modules with systemd units that depend on each other.
When expressing dependencies, It is easy to make mistakes that are only noticed at runtime, e.g. in
you may forget to enable the nginx module, or make a typo, or have a new NixOS release rename the service so things will break in production.
I have written an evaluation-time check like this:
that will complain if that unit does not exist on the machine.
It is implemented like this:
To do that, I had to modify nixpkgs like this:
It works, but the
config._module.args.name
magic has one drawback:It generates NixOS manual/options rebuilds, which take long.
Is there a better way we can do this?
The text was updated successfully, but these errors were encountered: