Detect Port Conflicts in NixOS Services

14 Likes

Havenā€™t looked into the implementation, but this sounds like a good candidate for nixpkgs.

Wow this is great and it would be even better if it could be upstreamed to nixpkgs (also nix-darwin and home-manager)! :wink:

Unix has a nearly forgotten feature for registering port assignments - /etc/services. It canā€™t detect conflicts but it does provide a system-wide registry that can be accessed via getservbyname and getservbyport. This is useful for monitoring tools because they can use your port assignments to label traffic flows.

I had a PR to update the services file but it went stale and I wasnā€™t sure it was worth the eval overhead by itself. If it could be bolted onto conflict detection then I think it would be worth it.

3 Likes

Interesting. Iā€™m not sure how much eval overhead this would generate, since every NixOS service would have to set an additional option. I implemented it for my own homelab, but would also be interested in upstreaming.

Whoa, Iā€™d never heard of that. TIL. Thanks sir.

i hadnā€™t seen that PR

recently this file came up in another threadā€¦ maybe there is more interest than i had anticipated

i had a different take than you had on what we could do with that fileā€¦ see How to add extra ports to /etc/services? - #10 by aanderse for the rough idea

maybe worth investigating? :thinking:

1 Like

/etc/services is about protocols, not about particular daemons/services. Thatā€™s how I view it.

May be time to revive that port allocator RFC?

And/or the more generic allocator RFC?

This Nix PR also has good inputs :thinking:

2 Likes