-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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 is not overriding/specializing a systemd template unit file #80933
Comments
See https://unix.stackexchange.com/a/468067/135796 In order to debug your issue reliably, you can:
And this should give you the final ExecStart systemd will eventually use. |
I've encountered this issue as well. Note that the
then I don't see any easy way to enable pre-existing template unit, except for creating another unit without any logic but with a dependency to the template unit, which seems really hacky and totally unnecessary given that systemd supports the use case natively. |
I marked this as stale due to inactivity. → More info |
Still important |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
From #108054 (comment)
|
For NixOS newbies like me, this should be put in |
but then the service will not be I tried many things, but I'm still unable to have the template be instantiated correctly AND wanted by machines.target. |
Your own advice is wrong. Of course, if you remove |
I thought it was an error because when I keep this line, I don't get a symlink to
|
Oh no. Something must have changed in how systemd units are set up. So this trick doesn't work anymore. |
I also tried this:
where I put the symlink in |
I am working around this by templating the unit files myself:
Note that there is an override for the |
I found a fix to my trick, albeit not a very nice one. The problem is that if { config, lib, pkgs, ... }: {
systemd.packages = [
(pkgs.runCommandNoCC "machines" {
preferLocalBuild = true;
allowSubstitutes = false;
} ''
mkdir -p $out/etc/systemd/system/
cp ${config.systemd.package}/example/systemd/system/[email protected] $out/etc/systemd/system/[email protected]
'')
];
systemd.services."systemd-nspawn@archlinux".wantedBy = [ "machines.target" ];
} |
I marked this as stale due to inactivity. → More info |
PR #186314 is now merged into master, which fixes this issue. A working example in case of a nspawn instance: {
systemd.services."systemd-nspawn@archlinux" = {
wantedBy = [ "machines.target" ];
overrideStrategy = "asDropin";
};
} |
systemd seems to always give drop-ins priority, even if less specific. luckily the new-ish overrideStrategy option allows us to make a drop-in: NixOS/nixpkgs#80933 (comment)
Describe the bug
My custom package provides a custom systemd service file and a systemd template file. The template file is called
[email protected]
.I put this package into
systemd.packages = [ pkgs.image-classifier ];
.The normal systemd service file works as when I use
systemd.services.image-classifier-scheduler
, it overrides the provided service file. This is demonstrated by thesystemctl status image-classifier-scheduler
:Notice the:
However when I try to override/specialize the template file, this does not happen. This is my nix config:
And the provided template file:
When I check the status. The service runs, but it isn't overriding it from the provided template file.
Notice how it just says
Loaded
, instead ofDrop-In
. That loaded file is just the generated file from the Nix configuration, instead of overriding the provided template file.The provided systemd unit files are located in this style:
I'm wondering does NixOS support overriding systemd template files? If it does, is there a clear example of doing this, since doing it the same way I expected with the normal service file didn't work.
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.The nixpkgs revision I'm using is: d097edb
The text was updated successfully, but these errors were encountered: