Best way to incorperate a bunch of wg-quick files into nix configuration


My VPN provides a bunch of wg-quick files who’s configuration I’d like to incorporate into my nix system. I suppose it wouldn’t be too hard to do this manually, but ideally I would like to the configuration to be nearly as easy as it is on conventional distros (i.e. simply drop them all into a folder and rebuild). This would make porting my configuration to other systems less painful since it is unlikely they would share the same wg-quick configuration.

My question is how should I approach this? How would you approach this? Is it a good idea to parse the configuration file and map it to networking.wg-quick? If so, would you generate and enclose the nix version of the wg-quick configuration in a derivation (vs. a simple function called by configuration.nix)? Is there a better/simpler approach?


I have a similar use case, just with openvpn. I imagine it’s similar in practice.

Personally, I wrote a small module-derivation combo for this:

The derivation makes it easier to stay up to date with the upstream, while the module makes the configuration less tedious (all it does is set up options for all VPN servers offered by my host, so I can switch between them with a rebuild).

Non-nixos machines just use the raw files from the host, so what I do in the nixos world doesn’t affect them much. If I wanted to, building the derivation and just copying over the results directory is trivial, but at this point I don’t run much without nix anymore.

Is this roughly what you’re looking for? I’m looking to switch to a wireguard host once my current period lapses, so I’m curious to see what you end up with :slight_smile: