From 3e7cc9c7dbb5255450d7e9df032e863cc283b154 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Fri, 14 Jun 2024 23:45:07 +0800 Subject: [PATCH] lib/trivial: move nixpkgs module functions to utils --- lib/default.nix | 12 +++++++----- lib/trivial.nix | 23 ++++------------------- lib/utils/nixos.nix | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index 04613909..4ef51ab5 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,7 +1,9 @@ -# The entrypoint for our custom library set. Take note, this is modularly -# 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 -# a function that generates a valid nixpkgs module. +# The entrypoint for our custom library set. +# +# Take note, this is modularly 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 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.lib.makeExtensible @@ -13,6 +15,6 @@ pkgs.lib.makeExtensible trivial = callLib ./trivial.nix; data = callLib ./data.nix; - inherit (self.trivial) countAttrs getConfig getUser; + inherit (self.trivial) countAttrs; inherit (self.data) importYAML renderTeraTemplate; }) diff --git a/lib/trivial.nix b/lib/trivial.nix index ca39f8bc..c7b4c38d 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -14,26 +14,11 @@ 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 + /* Filters and groups the attribute set into two separate attribute. Example: - getConfig "home-manager" "foo-dogsquared" - => ../configs/home-manager/foo-dogsquared + filterAttrs' (n: v: v == 4) { a = 4; b = 2; c = 6; } + => { ok = { a = 4; }; reject = { b = 2; c = 6; }; } */ - 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}; + filterAttrs' = f: attrs: { }; } diff --git a/lib/utils/nixos.nix b/lib/utils/nixos.nix index 644d6c08..7244fbb7 100644 --- a/lib/utils/nixos.nix +++ b/lib/utils/nixos.nix @@ -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}; }