We have a cobbled-together FreeSWITCH server running in production on Debian on Azure, and finally made up my mind to re-write the whole configuration and deployment parts properly using Nix. I thought of creating a shell.nix to run it on Ubuntu at first by creating the mutable parts (logs, configs in dev, etc.) in a shellHook and just make a wrapper for the FreeSWITCH executable.
Is this a good general direction or am I overlooking some obvious alternatives?
Unfortunately, learning the ins & outs of NixOS and figuring out how to deploy it on Azure would be the best (and what Iām hoping to achieve at one point), but Nix/pkgs already have my head spinning and was hoping to use the shell.nix as a stepping stone to learn what I can before diving into NixOS. Nonetheless, if you say that NixOS is the proper way to go to deploy a service with Nix then Iāll just bite the bullet and go with that right away.
What do you want and what you donāt want much from Nix here?
Packages ā I assume you want them
Configs ā do you want NixOS config generators or are you fine writing your own simple templating for this?
Command line arguments ā do you want NixOS logic there, or are you fine writing a fixed set / trivial templating for this?
Because you can use parts of NixOS service definitions, but depending on what you want and how service is structured, different amounts of black magic might be involved based on your needs.
Nothing wrong with having a service where your neeeds are stable and simple enough that it is easier to write a service file statically and install it than using NixOS code!
While longer-term NixOS might definitely be interesting for you, if youāre already at the point youāre comfortable creating a shell.nix with the functionality you want, it sounds like you donāt really need to take that plunge yet.
Wow, thank you! This looks amazing! Unfortunately I donāt really get Nix/OS modules yet (the same with flakes), but this gives me extra motivation to go deeper.
Great question and great breakdown of this topic. Iām trying to keep the bar low for now, which means the same amateurish deployment quality, but use Nix wherever it is possible.
Didnāt even know that NixOS config generators can be re-used for this - but then again, I donāt know much about them. Nonetheless, thank you for bringing them up and giving me options!
When I used āamateurishā above, I meant it:) The service is currently started manually in a shell, only FreeSWITCH is running in a Debian package-provided systemd service file, but I do want to learn how to properly use services.
Oooh, Iāve been looking for something like this for a while now! I have been searching for āsystemd services on non-nixosā from time to time, but serokell/systemd-nix never popped up, unfortunately.
I use GitHub - numtide/system-manager: Manage system config using nix on any distro on Arch, does the job for /etc and systemd config.
It uses the same option structure as NixOS, no need to translate abstractions. (In fact you could probably use some NixOS modules wholesale, as long as they donāt do too much outside of its featureset.)
Thank you! This is another tool that Iāve never heard of, but was looking for. Just thinking about the fragmentation of the Nix eco-system gives me anxiety, but then I think about all the awesome projects that crop up all the time and I think it is worth it.
Thank you! You were right that these are way over my head for now, but I really appreciate the examples (and for pointing to specific code locations, especially), because even if I found your repos on my own, Iām quite confident that I wouldnāt have been able to tell whether they are germane to my use caseā¦ I definitely want to up my Nix game though, and now I can dive in with zero understanding, but armed with the knowledge that the code is indeed relevant, which is super helpful:)
Do you mean here to take parts of the Nix configuration for NixOS and apply them in non-NixOS contexts? Iām still having a hard time telling Nix expressions apart on the basis where they supposed to be evaluated (i.e,. NixOS or not).
This is a level Iām striving to achieve at one point, to be able to cherry-pick parts because I have deep understanding of Nix(OS/pkgs)?.
aside: Looked at your post right after waking up and lang-os immediately conjured up this food in my mind:)
Yes, my laptop is Nix-generated Nixpkgs-based non-NixOS-core system, with a bit of NixOS pieces reused for things like Xorg config. use-from-nixos.nix evaluates a part of the NixOS code and provides me with store paths to use in my not-exactly-NixOS system.
The almost-static-with-minimal-sed thing is on a Debian VPS with Nix installed. I find it fine to have handwritten configs as long as they are under a VCS.
Another option is to build a systemd portable service image using pkgs.portableService. You use the systemd facilities in the .service files to bind configuration, data, log, etc. directories from the host into the service image. This is my preferred way to define a service with nix but run it on non nixOS. There are also good reasons to do it even on NixOS, e.g., to decouple the service and the base OS update cadence.