mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-31 10:58:02 +00:00
lib: remove filesToAttr
There's no part of the setup is using it so we're dumping it.
This commit is contained in:
parent
3839be59e3
commit
26128d00da
@ -2,49 +2,6 @@
|
|||||||
{ lib }:
|
{ lib }:
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
/* Create an attribute set that represents the structure of the modules
|
|
||||||
inside of a directory. While it can recurse into directories, it will
|
|
||||||
stop once it detects `default.nix` inside.
|
|
||||||
|
|
||||||
Signature:
|
|
||||||
path -> attrset
|
|
||||||
Where:
|
|
||||||
- `path` is the starting point.
|
|
||||||
Returns:
|
|
||||||
An attribute set. The keys are the basename of the file or the directory
|
|
||||||
and the values are the filepath to the Nix file.
|
|
||||||
|
|
||||||
!!! Implementation detail is based from
|
|
||||||
https://github.com/divnix/digga/blob/main/src/importers.nix looking at it
|
|
||||||
multiple times for the purpose of familiarizing myself to coding in Nix
|
|
||||||
and functional programming shtick.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
filesToAttr ./hosts
|
|
||||||
=> { ni = ./hosts/ni/default.nix; zilch = ./hosts/zilch/default.nix }
|
|
||||||
*/
|
|
||||||
filesToAttr = dirPath:
|
|
||||||
let
|
|
||||||
isModule = file: type:
|
|
||||||
(type == "regular" && lib.hasSuffix ".nix" file)
|
|
||||||
|| (type == "directory");
|
|
||||||
|
|
||||||
collect = file: type: {
|
|
||||||
name = lib.removeSuffix ".nix" file;
|
|
||||||
value =
|
|
||||||
let path = dirPath + "/${file}";
|
|
||||||
in if (type == "regular")
|
|
||||||
|| (type == "directory" && lib.pathExists (path + "/default.nix")) then
|
|
||||||
path
|
|
||||||
else
|
|
||||||
filesToAttr path;
|
|
||||||
};
|
|
||||||
|
|
||||||
files = lib.filterAttrs isModule (builtins.readDir dirPath);
|
|
||||||
in
|
|
||||||
lib.filterAttrs (name: value: value != { })
|
|
||||||
(lib.mapAttrs' collect files);
|
|
||||||
|
|
||||||
/* Count the attributes with the given predicate.
|
/* Count the attributes with the given predicate.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
@ -3,8 +3,7 @@ self: super: let
|
|||||||
publicLib = import ../. { lib = super; };
|
publicLib = import ../. { lib = super; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit (publicLib) filesToAttr countAttrs getSecrets
|
inherit (publicLib) countAttrs getSecrets attachSopsPathPrefix;
|
||||||
attachSopsPathPrefix;
|
|
||||||
|
|
||||||
# Until I figure out how to properly add them only for their respective
|
# Until I figure out how to properly add them only for their respective
|
||||||
# environment, this is the working solution for now. Not really perfect
|
# environment, this is the working solution for now. Not really perfect
|
||||||
|
Loading…
Reference in New Issue
Block a user