Skip to content

feat(modules.systemd): systemd helper module#564

Open
BirdeeHub wants to merge 3 commits into
mainfrom
systemd
Open

feat(modules.systemd): systemd helper module#564
BirdeeHub wants to merge 3 commits into
mainfrom
systemd

Conversation

@BirdeeHub

@BirdeeHub BirdeeHub commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Things To Be Done / Questions To Answer:

  • Should this be added to wlib.modules.default or not?
  • You need to log out and log back in for the FIRST time the service is added in order for the service to be automatically enabled. After that, changes are reflected on rebuild. It would be nice to have it not need that.
  • More docs
  • If you generate the documentation, or look through the module.nix, you will notice there is a LOT of options. This is because, in the freeform modules, most of the options have been documented. Not all of them, but most of them. We might want to remove some, and leave the user to infer more from the systemd manual pages? It is a 1 to 1 translation to make this mapping easy. This is also 1 reason why we might not want to have it in wlib.modules.default, not everything needs a service, and there are other service runners besides systemd.

about the second one:

You can still start it yourself right away. It is installed, just not enabled.

The action to enable it has been done. Systemd does not know about that yet.

I am not entirely sure why you cannot systemctl daemon-reload or systemctl daemon-reexec, but it seems like you have to log out or restart. It seems to check for enable status at a very particular time and then cache the results.

I tried mirroring most of the options to nixos options, and that kinda solved this issue, but not entirely

When you mirror the options, nixos uses the overrides mechanism, so you can mirror just the wantedBy requiredBy and upheldBy options. It mostly solves the issue, but sometimes the service is enabled but doesn't seem to run until you restart anyway? But systemd is reporting everything should be running

home manager doesn't merge with the ones from the package, so we would need to mirror ALL of them for home manager and ignore the file from the package and this would not work with placeholders...

I think there is something that can be done with the generated install module that can work around this, maybe with an activation script that can solve this, but that is what has been taking so long. For now, the options work, they are a lot like the home manager ones, but you need to log out or restart the first time you add the service for it to be enabled. After that, changes are reflected on rebuild, as the old file no longer exists on the systemd path and has been replaced with a new one with the same name, so it inherits the enabled status and reflects the new values.

Also, sorry I have been absent the last week, will be getting back to it!

BirdeeHub added 3 commits June 5, 2026 20:20
Fixed the flux capacitor again

(auto-msg qwen2.5-coder:7b)
On branch systemd
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   modules/systemd/check.nix
	modified:   modules/systemd/config.nix
Implemented a feature to make the coffee machine sing karaoke during mornin�[6D�[K
mornings

(auto-msg qwen2.5-coder:7b)
On branch systemd
Your branch is up to date with 'private/systemd'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   modules/systemd/SCRATCH.nix

Fixed the flux capacitor again

(auto-msg qwen2.5-coder:7b)
On branch systemd
Your branch is up to date with 'private/systemd'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   modules/systemd/SCRATCH.nix
	modified:   modules/systemd/config.nix
	modified:   modules/systemd/module.nix
};
};
};
extensionsSubmodule = { name, ... }: {

@BirdeeHub BirdeeHub Jun 16, 2026

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The systemd.{user,service} submodule, containing options for each unit file extension type

The interesting thing to note is extraMod which adds some extra per-service options for enabling or disabling various actions we perform in translating the options to unit files.

The code above this comment is just the systemd docs written out as nix options basically. Below is more interesting to figure out how it works. These options are processed in ./config.nix

@BirdeeHub

Copy link
Copy Markdown
Owner Author

@zenoli @iynaix @rachitvrma @FluxZA is anyone available and interested in reviewing or giving advice? This is still a work in progress but it should be most of the way there already.

@zenoli

zenoli commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Hi @BirdeeHub
Cool stuff!
I have a lot going on right now. I'm glad to skim through it on the weekend if you can wait that long, I am by no means a systemd expert though, so only expect a superficial review from me :-)

@BirdeeHub

Copy link
Copy Markdown
Owner Author

Hi @BirdeeHub Cool stuff! I have a lot going on right now. I'm glad to skim through it on the weekend if you can wait that long, I am by no means a systemd expert though, so only expect a superficial review from me :-)

It will definitely be waiting that long.

Try to ignore the noise from the transposed systemd options when you do review it.

@FluxZA

FluxZA commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Hi All

I also will only have a chance to look over this on the weekend. I have some experience with systemd and how nixos handles it so hopefully I can help. Also happy to help out with documentation.

@rachitvrma

Copy link
Copy Markdown
Contributor

Hey everyone, I have been quite busy with some college work. I'll be happy to look into this, though.

@zenoli

zenoli commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

My apologies, I did not get around to look at it, unfortunately I don't think I will have time in the next days :-(

@FluxZA

FluxZA commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Hi, sorry this is a little late, my weekend was busier than I expected and I also ended up getting more absorbed in the manga I am reading than I planned 😂

I have gone through everything once, and I have some initial comments and questions. I haven't looked into the restart/logout issue yet, but I am still happy to if you want a second opinion.


Regarding inclusion in the default module, I agree that this is not necessary and would probably lead to the docs being cluttered. I was even thinking you could potentially split the current module to separate the systemd options and the extra mods options, so that if you are reading the docs you know if you are looking at something systems related or something related to the nix-wrap implementation. This would also create more separation for if you wanted to work with other service handlers in future.

This leads to the question of the docs for the systemd options. In my opinion we should have as many of them documented as possible, but keep the descriptions very basic with links to the systemd documentation. That way the docs aren't too bloated and if anything changes from systemd's side we don't have to maintain our docs to match the new behaviour.


Regarding your implementation, I am unsure of how the overwrite or append would work. Is this catering for a case where the host system already has a service and the wrapper needs it to behave differently?


Regarding docs, do you want help adding more docs or just reviewing the current docs?

@BirdeeHub

BirdeeHub commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

Regarding your implementation, I am unsure of how the overwrite or append would work. Is this catering for a case where the host system already has a service and the wrapper needs it to behave differently?

Close, it is catering for the case where the derivation already provides a service file with that name, for if you wish to modify it rather than overwriting it.

If overwrite is true, it will just replace it.


That is 1 vote for "not included in wlib.modules.default" so far. (There is not actually any voting system but that's 1 vote regardless.)


Regarding docs, do you want help adding more docs or just reviewing the current docs?

I was going to add a meta.description and review the freeform options that I have there already.

I am more interested in people reviewing the top level options that are not directly translated, and the implementation, as opposed to the list of systemd options for each section and their docs, as those are just transcribed from man systemd.* and I can review that just fine with a bit of time (already taken 2 passes at it but I probably still have 1 or 2 with the wrong type I will find when I look again)

@FluxZA

FluxZA commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Ahh okay, that makes sense. Cool I will go back and look at those descriptions in particular and leave comments if I have any.

let
extraMod = { _prefix, ... }: {
options =
let

@FluxZA FluxZA Jun 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The id generation here might benefit from some internal documentation. It took me a long time to figure out what it was doing (could just be a shortcoming in my nix knowledge though🤦🏼)

My understanding is that it is used to dynamically update the descriptions based of of where the extraMods function ends up being imported, using the last 3 levels of the option hierarchy if they exist. One thing I noticed when actually generating the docs, the final element (used in ${get 2}) seems to be a space for some of the options, I am not sure if that is intended.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let me know if this is not the type of doc suggestions you want. I had an hour to start looking this eve and this is the first thing I came across which I didn't understand. Will continue looking at more the rest of the week and I will try adjust feedback based on the level you are looking for.

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.

4 participants