I am using leftwm as my window manager, I have been using ~/.config/leftwm/config.toml to configure it. But as I have misconfig it, locked my self out of the terminal yesterday and had to use a booting USB to fix that file, I want to move the configuration into nix so that I can recover to previous generation if things go wrong next time.
And also leftwm seems to not support custom config path, so I cannot use pkgs.writeText to generate a text file as derivation and feed it to it.
So right now I think my best bet is to use home-manager's property, and use writeText to connect things together:
home.file.".config/leftwm/config.toml".source = pkgs.writeText "leftwm-config" ''
# some config here
'';
But is there a better way to do this? I do feel comfortable enough for this approach,as it forces me to put the configuration related with leftwm into two different files, and I can foresee that I will change one while forgetting the other one in the future. What is the most idiomatic way to handle this in Nix?
So right now I think my best bet is to use home-manager 's property, and use writeText to connect things together
I do think this is indeed the best option, maybe you could even make a real module for it and contribute it to home-manager?
It forces me to put the configuration related with leftwm into two different files
I don’t quite see how it does that. Is your problem that you are installing your home-manager configuration with the home-manager command? You can integrate home-manager into your nixos configuration with a module, see the Home Manager Manual.
Note also that if you’re using home manager to do this you probably want to do this instead:
xdg.configFile."leftwm/config.toml".text = ''
# Some config here
'';
Rather than redirecting the file writing through pkgs.writeText and hard-coding the xdg config directory. Alternatively use your .source and just keep your configuration in a separate file like so:
Thanks. I tried the home.file and xdg.configFile approach, and using them with flake is just awesome. Simple dotfile management. This is what I come up at the end: