2024-05-16 11:39:01 -04:00
|
|
|
{ lib, ... }:
|
|
|
|
{
|
|
|
|
# create rad-dev namespace for lib
|
|
|
|
rad-dev = rec {
|
2024-05-19 12:29:29 -04:00
|
|
|
systems = import ./systems.nix { inherit lib; };
|
2024-05-25 15:19:01 -04:00
|
|
|
microvm = import ./microvms.nix { inherit lib; };
|
2024-05-25 15:36:40 -04:00
|
|
|
|
2024-05-16 11:39:01 -04:00
|
|
|
# any(), but checks if any value in the list is true
|
|
|
|
#
|
|
|
|
# args:
|
|
|
|
# n: list of booleans
|
|
|
|
#
|
|
|
|
# type:
|
|
|
|
# anyBool:: [bool] -> bool
|
|
|
|
anyBool = lib.any (n: n);
|
|
|
|
|
|
|
|
# pulls a value out of an attrset and converts it to a list
|
|
|
|
#
|
|
|
|
# args:
|
|
|
|
# attr: attribute to search for in an attrset
|
|
|
|
# set: attrset to search
|
|
|
|
#
|
|
|
|
# type:
|
2024-05-19 16:04:57 -04:00
|
|
|
# mapGetAttr :: String -> AttrSet -> [Any]
|
2024-05-21 19:43:57 -04:00
|
|
|
mapGetAttr = attr: set: lib.mapAttrsToList (_: attrset: lib.getAttr attr attrset) set;
|
2024-05-16 11:39:01 -04:00
|
|
|
|
|
|
|
# gets list of files and directories inside of a directory
|
|
|
|
#
|
|
|
|
# args:
|
|
|
|
# base: base path to search
|
|
|
|
# dir: directory to get files from
|
|
|
|
#
|
|
|
|
# type:
|
|
|
|
# ls :: Path -> String -> [String]
|
2024-05-19 10:26:46 -04:00
|
|
|
ls = dir: lib.attrNames (builtins.readDir dir);
|
2024-05-16 11:39:01 -04:00
|
|
|
|
|
|
|
# gets list of directories inside of a given directory
|
|
|
|
#
|
|
|
|
# args:
|
|
|
|
# base: base path to search
|
|
|
|
# dir: directory to get files from
|
|
|
|
#
|
|
|
|
# type:
|
|
|
|
# lsdir :: Path -> String -> [String]
|
|
|
|
lsdir =
|
2024-05-19 10:26:46 -04:00
|
|
|
dir:
|
2024-05-20 01:19:21 -04:00
|
|
|
lib.optionals (builtins.pathExists dir) (
|
2024-05-21 19:47:21 -04:00
|
|
|
lib.attrNames (lib.filterAttrs (_: type: type == "directory") (builtins.readDir dir))
|
2024-05-20 01:19:21 -04:00
|
|
|
);
|
2024-05-16 11:39:01 -04:00
|
|
|
|
|
|
|
# return full paths of all files in a directory
|
|
|
|
#
|
|
|
|
# args:
|
|
|
|
# base: base path to search
|
|
|
|
# dir: path to get files from
|
|
|
|
#
|
|
|
|
# type:
|
|
|
|
# fileList :: Path -> String -> [Path]
|
2024-05-19 10:26:46 -04:00
|
|
|
fileList = dir: map (file: dir + "/${file}") (ls dir);
|
2024-05-30 23:39:31 -04:00
|
|
|
|
|
|
|
# constructs a mac address from a string's hash
|
|
|
|
#
|
|
|
|
# args:
|
|
|
|
# hashable: the string to hash
|
|
|
|
#
|
|
|
|
# type:
|
|
|
|
# strToMac :: String -> String
|
|
|
|
strToMac =
|
|
|
|
hashable:
|
|
|
|
let
|
|
|
|
# computes sha512 hash of input
|
|
|
|
hashStr = builtins.hashString "sha512" hashable;
|
|
|
|
# grabs first 12 letters of hash
|
|
|
|
hashSub = start: builtins.substring start 2 (builtins.substring 0 12 hashStr);
|
|
|
|
# joins list of strings with a delimiter between
|
|
|
|
joiner =
|
|
|
|
delim: arr:
|
|
|
|
builtins.foldl' (
|
|
|
|
a: b: lib.concatStrings ([ a ] ++ (lib.optionals (a != "") [ delim ]) ++ [ b ])
|
|
|
|
) "" arr;
|
|
|
|
# generates a list of indexes for the hash
|
|
|
|
starts = builtins.genList (x: x * 2) 6;
|
|
|
|
in
|
|
|
|
joiner ":" (map hashSub starts);
|
2024-05-16 11:39:01 -04:00
|
|
|
};
|
|
|
|
}
|