Add network library with IPv4 conversion functions.#258250
Add network library with IPv4 conversion functions.#258250djacu wants to merge 1 commit intoNixOS:masterfrom
Conversation
|
what about ipv6? |
In short; next PR. Or someone else can add it if they feel inclined. :) |
infinisil
left a comment
There was a problem hiding this comment.
Nice, this would be very handy!
I think it's a bit too big all together though, could you split this into smaller PRs? That would make incremental reviews and merges much easier.
Ideally we'd also have a design document like we have for the path library and the fileset library. This would include arguments for why the library is design the way it is, such as why these specific functios were chosen, that alternatives would be worse, etc.
In particular I feel like the amount of conversion functions is a bit too much, could this be improved?
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/manipulate-ip-addresses-in-nix-lang/33363/5 |
Sure I'm happy to break it into multiple PRs and add a design document. How many chunks should I split it into or how small should I make the PRs? I worked with @kylerisse on designing the library. All the functions that go into |
The smallest chunks possible such that each still has a good use case (and explain that use case in the PR). |
| cidrToBitMask "192.168.70.9/15" | ||
| => 15 | ||
| */ | ||
| cidrToBitMask = cidr: let |
There was a problem hiding this comment.
How certain are you about the term bitmask? I would expect "11111111111111110000000000000000".
In IPv6 lingo that number after the slash is named prefix length.
There was a problem hiding this comment.
Not very. Prefix length is better. I think it's same in both ipv4 and ipv6, no?
|
A very hacky ipv4 and ipv6 library can be found here: |
|
@djacu any chance you are still working on this? ❤️ |
Hey sorry I got swamped helping plan scale and nixcon na. I started working on a design document. I was hoping to get back to it next week. |
|
At the request of @infinisil, I have created a new (smaller) PR with a design document. |
Description of changes
Adds a network library to
libwith functions for IPv4 conversions. Many core and supplementary modules can benefit from simple Nix functions that do IPv4 cidr/address/mask conversions. Examples include:dhcpdnetworking.interfacesflannelfail2banpostgreytincExample of how configuration can be improved using the new network library. This helps minimize the chance for typographical errors.
Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)