From 29b7b302e16e38847e37811aca9e97f98c2b8c0f Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sun, 25 Feb 2024 20:02:41 +0800 Subject: [PATCH] lib: set as fixed point --- lib/default.nix | 51 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index f2cd421b..95600648 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,21 +1,42 @@ -# All of the custom functions suitable for all environments. +# The entrypoint for our custom library set. { lib }: -rec { - /* Count the attributes with the given predicate. +lib.makeExtensible + (self: + rec { + /* Count the attributes with the given predicate. - Examples: - countAttrs (name: value: value) { d = true; f = true; a = false; } - => 2 + 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); + 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); - getConfig = type: config: ../configs/${type}/${config}; + /* Returns the file path of the given config of the given environment. - getUser = type: user: ../configs/${type}/_users/${user}; -} + 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}; + })