blob: 036af97f8e851aa8d52cfdfb88253231f72523ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
nixpkgslib: let
lib = nixpkgslib // nlib;
nlib = with builtins;
with lib; {
# Generic power of number
pow = base: e:
if e == 0
then 1
else foldl (a: b: a * base) 1 (genList id (e - 1));
# Power of 2
pow2 = pow 2;
# Convert integer to list of bits
int2bits = len: e: reverseList (genList (x: bitAnd e (pow2 (x + 1)) > 0) len);
# Reverse operation for int2bits
bits2int = l: let
len = length l;
zf = a: b:
if a
then pow2 b
else 0;
in
foldl add 0 (zipListsWith zf l (genList (i: len - i) len));
# IPv4 utilities
ipv4 = import ./ipv4.nix lib;
};
in
nlib
|