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: Manage files using systemd services #44

Merged
merged 1 commit into from
Nov 18, 2021

Conversation

talyz
Copy link
Collaborator

@talyz talyz commented Aug 29, 2021

Manage files by creating a systemd oneshot service for each file. The service links or bind mounts the file as appropriate on start and removes the link or unmounts it when stopped. Whether a symlink or bind mount is used is determined by if the target exists - if it does, it's bind mounted, otherwise symlinked. To make sure files are available early enough, also run the start portion in the activation script.

This lifts the restriction on files being placed in /etc and should finally close #1.

@colemickens
Copy link
Member

I'm using this PR, and I'm seeing this behavior.

  1. At some point, I get things all working.
  2. I reboot.
  3. Things come back correctly! (etc machine-id, and ssh host keys)
  4. As soon as I try to activate a new generation I get errors:
...
updating GRUB 2 menu...
activating the configuration...
mount already exists at '/etc/machine-id', ignoring
reloading user units for cole...
setting up tmpfiles

Frustratingly there's a sort of silent rollback there and the new generation is not activated or marked as the running generation. I guess I can just reboot after I set the system profile every time, but that's not ideal...

nixos.nix Outdated Show resolved Hide resolved
@colemickens
Copy link
Member

Seems like it fixed it!

@talyz
Copy link
Collaborator Author

talyz commented Sep 16, 2021

Great! Thanks again for trying it out!

@ambroisie
Copy link

What's the state on this PR? Is it going to be merged soon?

@talyz
Copy link
Collaborator Author

talyz commented Nov 12, 2021

I think it's done, but I would prefer to get some more testing and reviews before merging it.

Ping @etu @lovesegfault @cole-h

nixos.nix Outdated Show resolved Hide resolved
Copy link
Member

@cole-h cole-h left a comment

Choose a reason for hiding this comment

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

Much better. I (still >.<) have no way to test this, but the diff looks sane to me.

@lovesegfault
Copy link
Collaborator

lovesegfault commented Nov 14, 2021

I'm going to test this today without fault.

@lovesegfault
Copy link
Collaborator

Seems to be working AOK :)

  • I wish we had separate services for binding and linking, so bind-foo, link-bar, instead of bindOrLink-foo, bindOrLink-bar
  • I wonder whether the unit names having impermanence on them would be good? This way a user knows what they are when looking at systemctl

@ambroisie
Copy link

@lovesegfault I think having impermanence- as a prefix is necessary to be able to distinguish between link-foo and bind-bar while still having a simple "namespace".

@talyz
Copy link
Collaborator Author

talyz commented Nov 14, 2021

@lovesegfault Well, the problem is that we don't know wether we'll link or bind mount until the service runs, so I think bindOrLink is as accurate as it gets. We could of course append impermanence or maybe persistence, since that's what the option is called. It would make the names very long, but maybe that's okay.

@lovesegfault
Copy link
Collaborator

@lovesegfault Well, the problem is that we don't know wether we'll link or bind mount until the service runs, so I think bindOrLink is as accurate as it gets. We could of course append impermanence or maybe persistence, since that's what the option is called. It would make the names very long, but maybe that's okay.

How about just persist-$path?

@talyz
Copy link
Collaborator Author

talyz commented Nov 15, 2021

Yeah, that sounds good!

@talyz
Copy link
Collaborator Author

talyz commented Nov 16, 2021

@lovesegfault Changed! :)

nixos.nix Outdated Show resolved Hide resolved
nixos.nix Outdated Show resolved Hide resolved
nixos.nix Outdated Show resolved Hide resolved
Manage files by creating a systemd oneshot service for each file. The
service links or bind mounts the file as appropriate on start and
removes the link or unmounts it when stopped. Whether a symlink or
bind mount is used is determined by if the target exists - if it does,
it's bind mounted, otherwise symlinked. To make sure files are
available early enough, also run the start portion in the activation
script.

This lifts the restriction on files being placed in `/etc` and should
finally close #1.
@talyz
Copy link
Collaborator Author

talyz commented Nov 17, 2021

@cole-h All done! I kept the names of the ExecStart and ExecStop scripts, since I found the names more descriptive than something like persist-start-*, but all the other instances were changed.

@lovesegfault lovesegfault merged commit b74f468 into master Nov 18, 2021
@lovesegfault lovesegfault deleted the systemd-service-files branch November 18, 2021 19:36
@lovesegfault
Copy link
Collaborator

Thank you for tackling this @talyz!

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.

New API
5 participants