From da1ed34e5e6606fd0c9c8e21b82fd646e44213fd Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Thu, 5 Sep 2024 00:39:36 +0000 Subject: [PATCH] add slaacSuffix to unused lib --- nix/lib/default.nix | 2 ++ nix/lib/unused.nix | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 nix/lib/unused.nix diff --git a/nix/lib/default.nix b/nix/lib/default.nix index 3e222f2..5fee45f 100644 --- a/nix/lib/default.nix +++ b/nix/lib/default.nix @@ -10,6 +10,8 @@ libO types = libO.types // lib.importFlakeMod ./types.nix; + x-banananetwork-unused = lib.importFlakeMod ./unused.nix; + # functions supportedSystems = builtins.attrNames nixpkgs.legacyPackages; diff --git a/nix/lib/unused.nix b/nix/lib/unused.nix new file mode 100644 index 0000000..723e0a9 --- /dev/null +++ b/nix/lib/unused.nix @@ -0,0 +1,49 @@ +{ lib, ... }@flakeArg: +# functions I wrote but didn’t end up using +# feel free to use them & reference them directly +{ + + slaacSuffix = + mac: + let + replaceChars = [ + " " + "." + ":" + "-" + ]; + rawMac = builtins.replaceStrings replaceChars (map (x: "") replaceChars) (lib.strings.toLower mac); + invert7bit = { + "0" = "2"; + "1" = "3"; + "2" = "0"; + "3" = "1"; + "4" = "6"; + "5" = "7"; + "6" = "4"; + "7" = "5"; + "8" = "a"; + "9" = "b"; + "a" = "8"; + "b" = "9"; + "c" = "e"; + "d" = "f"; + "e" = "c"; + "f" = "d"; + }; + inherit (builtins) substring; + in + assert builtins.match (lib.strings.replicate 12 "[0-9a-f]") rawMac; + builtins.concatStringsSep "" [ + (substring 0 1 rawMac) + (invert7bit.${substring 1 1 rawMac}) + (substring 2 2 rawMac) + ":" + (substring 4 2 rawMac) + "ff:f0" + (substring 6 2 rawMac) + ":" + (substring 8 4 rawMac) + ]; + +}