aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2024-10-02 09:32:54 +0200
committerKarel Kočí <cynerd@email.cz>2024-10-02 09:32:54 +0200
commit65a9e7cd89ab452bb3c75cfa496d0dcd90b3707d (patch)
tree29814d6164d0915ea8527fe0ea95e497669f1b3f /lib
parent0fb44b2a894221e5806ee9eaa287df77a72b9204 (diff)
downloadnixos-personal-65a9e7cd89ab452bb3c75cfa496d0dcd90b3707d.tar.gz
nixos-personal-65a9e7cd89ab452bb3c75cfa496d0dcd90b3707d.tar.bz2
nixos-personal-65a9e7cd89ab452bb3c75cfa496d0dcd90b3707d.zip
lib: implement as overlay
This uses fully the ability to overlay the nixpkgs library instead of doing that hackilly.
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;
+}