78 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			78 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
| { lib, ... }:
 | |
| {
 | |
|   # create adev namespace for lib
 | |
|   adev = rec {
 | |
|     systems = import ./systems.nix { inherit lib; };
 | |
|     container-utils = import ./container-utils.nix { inherit lib; };
 | |
| 
 | |
|     # 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:
 | |
|     # mapGetAttr :: String -> AttrSet -> [Any]
 | |
|     mapGetAttr = attr: set: lib.mapAttrsToList (_: attrset: lib.getAttr attr attrset) set;
 | |
| 
 | |
|     # 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]
 | |
|     ls = dir: lib.attrNames (builtins.readDir dir);
 | |
| 
 | |
|     # 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 =
 | |
|       dir:
 | |
|       lib.optionals (builtins.pathExists dir) (
 | |
|         lib.attrNames (lib.filterAttrs (_: type: type == "directory") (builtins.readDir dir))
 | |
|       );
 | |
| 
 | |
|     # 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]
 | |
|     fileList = dir: map (file: dir + "/${file}") (ls dir);
 | |
| 
 | |
|     # reduce an attribute set to a string
 | |
|     #
 | |
|     # example:
 | |
|     # given attrset {host1 = "palatine-hill"; host2 = "jeeves";}
 | |
|     # and func (host: hostname: host + " is " + hostname + ", " )
 | |
|     # mapAttrsToString would return 'host1 is palatine-hill, host2 is jeeves, '
 | |
|     #
 | |
|     # args:
 | |
|     # func: an function to apply to attrSet to turn each entry into one string
 | |
|     # attrSet: an attribute set to reduce
 | |
|     #
 | |
|     # type:
 | |
|     # mapAttrsToString :: AttrSet -> (String -> Any -> String) -> String
 | |
|     mapAttrsToString =
 | |
|       func: attrSet: (lib.foldl' (cur: next: cur + next) "" (lib.mapAttrsToList func attrSet));
 | |
|   };
 | |
| }
 |