aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix51
1 files changed, 23 insertions, 28 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 3f14de0..76eb693 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -1,30 +1,25 @@
-nixpkgslib: let
- lib = nixpkgslib // nlib;
+final: _:
+with final; {
+ # Generic power of number
+ pow = base: e:
+ if e == 0
+ then 1
+ else foldl (x: _: x * base) 1 (genList id (e - 1));
+ # Power of 2
+ pow2 = pow 2;
- nlib = with builtins;
- with lib; {
- # Generic power of number
- pow = base: e:
- if e == 0
- then 1
- else foldl (x: _: x * 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));
- # 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
+ # IPv4 utilities
+ ipv4 = import ./ipv4.nix final;
+}