Hi, I’m beginner with nixos but I couldn’t find nice solution with examples online.
I’ve tried to accomplish copying my user config for one of nix package which would be executed as service from systemd. The plan was that once I login package could run as web service in the background on startup.
So inside configuration.nix I created my own service for systemd:
It does copy to /nix/store which feels wrong, and is from my knowledge impossible as it should be always read-only.
Running journalctl -u myService.service -b basically confirms it as I’m just getting bunch of Read-only file system errors.
My question is, how can I achieve what I initially want?
So my service will run under config from user. Can I do it in configuration.nix alone?
What is the workaround/correct way of doing it, or is it completely impossible?
Note: Running it by hand from my user with my user config does the trick, but I’d like to make it completely automated on start-up ideally inside configuration.nix so I could easily move all my stuff to different machine in future
I’d love and appreciate any suggestions/comments which could lead me to answer
Thank you!
Does your service have a way to specify a config file in its command line args?
I assume from the context of the request that making the config file a static part of your system, upgraded through nixos-rebuild, isn’t a workable solution.
Another option worth considering would be to define this service as a systemd user service through home-manager. Then the user can update it themselves.
There is one thing to keep in mind though when you are doing this without home manager. A user level service defined this way is going to be enabled for all users. Now, if you’re the only person using this machine, you can of course just say “I don’t care”, but if you’re not, you need to do a little more work.
First of all, when passing the path to the config file, you should do something like %h/.config/SomePackage/config as systemd will then automatically substitute the path to $HOME. There are a bunch more you can see with man systemd.unit. No matter what, this is a healthy pattern rather than hardcoding user names/paths.
Secondly, with home-manager you would be able to define it just for your user.
But a workaround is to use unitConfig.ConditionUser = "azelski"; which will make it run just for you.
My intention was to do it for all the users, so it wasn’t a blunder here. I was expecting hardcoding as awful solution but I didn’t knew any better as I wanted to make it first ‘work’ then think later how to improve it. Thanks for tip on environment paths, I will check it out.
@peterhoeg@tejing Thanks for all the response it’s super helpful, I’ll definitely look at home-manager, along with more glance of systemd in general.
I was aware that home manger exists before but the main reason I didn’t wanted to get into it was that I wanted to keep as much as possible in /etc/nixos/configuration.nix but I guess I’ll still have to hold .profile and other stuff somewhere so hope it will make it much better experience.
Anywas once again thanks for rapid and detailed replies!
I was aware that home manger exists before but the main reason I didn’t wanted to get into it was that I wanted to keep as much as possible in /etc/nixos/configuration.nix
You absolutely can keep the HM config in configuration.nix if you want.