4 ms·
I wish just one of these would allow for multi-instantiation of services. I have projects where I need to spin up multiple independent postgres. Instead, many o
by k8svet 3y ago
I wish just one of these would allow for multi-instantiation of services. I have projects where I need to spin up multiple independent postgres. Instead, many of these tools repeat the patterns used in nixpkgs.
- Cyph0n 3y agoIf you’re on NixOS (the distro), the only way to run multiple services of the same type (eg, Nginx) is using containers. These can either be NixOS containers or standard Docker/Podman containers [1]. If you want to run a Compose project, I maintain a tool that help simplify this [2]. [1] https://nixos.wiki/wiki/NixOS_Containers https://nixos.wiki/wiki/NixOS_Containers [2] https://github.com/aksiksi/compose2nix https://github.com/aksiksi/compose2nix
- s900mhz 3y agoThis is great! Thanks for sharing
- Twey 3y agoAs GP implies, NixOS supports running multiple instances of any service you like, but the way some of the modules are written doesn't make it easy. Thankfully one of the advantages of NixOS is that it's pretty easy to add a configuration module to your personal configuration! In general, you can configure systemd yourself through `systemd.services`, where you can write systemd service files ‘directly’ in Nix syntax. Services for which multiple instances make sense often (unfortunately, not always) provide configuration that allows you to specify multiple instances (i.e. their top-level configuration object will be a list or attrset of instance configurations). I've written a little bit about patterns to do this here: https://twey.io/nix-patterns/inputs-and-outputs/ https://twey.io/nix-patterns/inputs-and-outputs/ If you needed, say, multiple instances of Postgres, it's not too challenging to copy-paste the nixpkgs implementation, change it a bit to parameterize the config on (e.g.) a service name for namespacing, then import that module into your NixOS configuration to allow you to define multiple instances. For example, I did this here for the Rainloop email client: https://github.com/Twey/dotfiles/blob/main/nixos/modules/services/rainloop.nix https://github.com/Twey/dotfiles/blob/main/nixos/modules/ser...
- Cyph0n 3y agoI probably should have said “the easiest way”. I did know that you could define systemd services yourself, but it’s good to see a specific pattern. I still think it’s easier to just spin up a NixOS container - should work for any service out of the box.
- k8svet 3y agoGrumble, I know, I don't like using containers when I don't need to, though. And I still think it's too bad that greenfield nix projects haven't thought about this more a-priori. Either by making the isolation a default, hidden foundation, or by creating the new module to be multi-instantiable.