lib/trivial: move nixpkgs module functions to utils

This commit is contained in:
Gabriel Arazas 2024-06-14 23:45:07 +08:00
parent 20c0549706
commit 3e7cc9c7db
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
3 changed files with 32 additions and 24 deletions

View File

@ -1,7 +1,9 @@
# The entrypoint for our custom library set. Take note, this is modularly # The entrypoint for our custom library set.
# included as part of the environment so we cannot have any functions or #
# references that could make the evaluation go in an infinite recursion such as # Take note, this is modularly included as part of the environment so we cannot
# a function that generates a valid nixpkgs module. # have any functions or references that could make the evaluation go in an
# infinite recursion such as a function that generates a valid nixpkgs module.
# If you have to add those functions, you'll have to add them in configUtils.
{ pkgs }: { pkgs }:
pkgs.lib.makeExtensible pkgs.lib.makeExtensible
@ -13,6 +15,6 @@ pkgs.lib.makeExtensible
trivial = callLib ./trivial.nix; trivial = callLib ./trivial.nix;
data = callLib ./data.nix; data = callLib ./data.nix;
inherit (self.trivial) countAttrs getConfig getUser; inherit (self.trivial) countAttrs;
inherit (self.data) importYAML renderTeraTemplate; inherit (self.data) importYAML renderTeraTemplate;
}) })

View File

@ -14,26 +14,11 @@
lib.count (attr: pred attr.name attr.value) lib.count (attr: pred attr.name attr.value)
(lib.mapAttrsToList lib.nameValuePair attrs); (lib.mapAttrsToList lib.nameValuePair attrs);
/* Returns the file path of the given config of the given environment. /* Filters and groups the attribute set into two separate attribute.
Type: getConfig :: String -> String -> Path
Example: Example:
getConfig "home-manager" "foo-dogsquared" filterAttrs' (n: v: v == 4) { a = 4; b = 2; c = 6; }
=> ../configs/home-manager/foo-dogsquared => { ok = { a = 4; }; reject = { b = 2; c = 6; }; }
*/ */
getConfig = type: config: ../configs/${type}/${config}; filterAttrs' = f: attrs: { };
/* 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};
} }

View File

@ -30,4 +30,25 @@
]; ];
}); });
/* 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};
} }