mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-31 04:58:01 +00:00
43 lines
1.3 KiB
Nix
43 lines
1.3 KiB
Nix
# The entrypoint for our custom library set.
|
|
{ lib }:
|
|
|
|
lib.makeExtensible
|
|
(self:
|
|
rec {
|
|
/* Count the attributes with the given predicate.
|
|
|
|
Examples:
|
|
countAttrs (name: value: value) { d = true; f = true; a = false; }
|
|
=> 2
|
|
|
|
countAttrs (name: value: value.enable) { d = { enable = true; }; f = { enable = false; package = [ ]; }; }
|
|
=> 1
|
|
*/
|
|
countAttrs = pred: attrs:
|
|
lib.count (attr: pred attr.name attr.value)
|
|
(lib.mapAttrsToList lib.nameValuePair attrs);
|
|
|
|
/* Returns the file path of the given config of the given environment.
|
|
|
|
Type: getConfig :: String -> String -> Path
|
|
|
|
Example:
|
|
getConfig "home-manager" "foo-dogsquared"
|
|
=> ../configs/home-manager/foo-dogsquared
|
|
*/
|
|
getConfig = type: config: ../configs/${type}/${config};
|
|
|
|
|
|
/* Returns the file path of the given user subpart of the given
|
|
environment. Only certain environments such as NixOS have this type of
|
|
setup.
|
|
|
|
Type: getConfig :: String -> String -> Path
|
|
|
|
Example:
|
|
getUser "nixos" "foo-dogsquared"
|
|
=> ../configs/nixos/_users/foo-dogsquared
|
|
*/
|
|
getUser = type: user: ../configs/${type}/_users/${user};
|
|
})
|