lib: reformat
This commit is contained in:
parent
ba867f46b3
commit
c24c58a743
1 changed files with 58 additions and 59 deletions
117
lib/default.nix
117
lib/default.nix
|
@ -1,71 +1,70 @@
|
||||||
{ lib }:
|
{ lib }:
|
||||||
lib.makeExtensible
|
lib.makeExtensible (self:
|
||||||
(self:
|
with lib;
|
||||||
with lib;
|
rec {
|
||||||
rec {
|
flattenListSet = imports: (flatten (concatLists (attrValues imports)));
|
||||||
flattenListSet = imports: (flatten (concatLists (attrValues imports)));
|
flattenSetList = attrSet: (mapAttrs (name: value: flatten value) attrSet);
|
||||||
flattenSetList = attrSet: (mapAttrs (name: value: flatten value) attrSet);
|
|
||||||
|
|
||||||
# ["/home/user/" "/.screenrc"] -> ["home" "user" ".screenrc"]
|
# ["/home/user/" "/.screenrc"] -> ["home" "user" ".screenrc"]
|
||||||
splitPath = paths:
|
splitPath = paths:
|
||||||
(filter
|
(filter
|
||||||
(s: builtins.typeOf s == "string" && s != "")
|
(s: builtins.typeOf s == "string" && s != "")
|
||||||
(concatMap (builtins.split "/") paths)
|
(concatMap (builtins.split "/") paths)
|
||||||
);
|
);
|
||||||
|
|
||||||
# ["home" "user" ".screenrc"] -> "home/user/.screenrc"
|
# ["home" "user" ".screenrc"] -> "home/user/.screenrc"
|
||||||
dirListToPath = dirList: (concatStringsSep "/" dirList);
|
dirListToPath = dirList: (concatStringsSep "/" dirList);
|
||||||
|
|
||||||
# ["/home/user/" "/.screenrc"] -> "/home/user/.screenrc"
|
# ["/home/user/" "/.screenrc"] -> "/home/user/.screenrc"
|
||||||
concatPaths = paths:
|
concatPaths = paths:
|
||||||
let
|
let
|
||||||
prefix = optionalString (hasPrefix "/" (head paths)) "/";
|
prefix = optionalString (hasPrefix "/" (head paths)) "/";
|
||||||
path = dirListToPath (splitPath paths);
|
path = dirListToPath (splitPath paths);
|
||||||
in
|
in
|
||||||
prefix + path;
|
prefix + path;
|
||||||
|
|
||||||
sanitizeName = name:
|
sanitizeName = name:
|
||||||
replaceStrings
|
replaceStrings
|
||||||
[ "." ] [ "" ]
|
[ "." ] [ "" ]
|
||||||
(sanitizeDerivationName (removePrefix "/" name));
|
(sanitizeDerivationName (removePrefix "/" name));
|
||||||
|
|
||||||
mapGenAttrs = list: func: attrs:
|
mapGenAttrs = list: func: attrs:
|
||||||
lib.genAttrs list (name: func (if builtins.typeOf attrs == "lambda" then attrs name else attrs));
|
lib.genAttrs list (name: func (if builtins.typeOf attrs == "lambda" then attrs name else attrs));
|
||||||
|
|
||||||
dirsOf = dir: lib.attrNames (lib.filterAttrs (file: type: type == "directory") (builtins.readDir dir));
|
dirsOf = dir: lib.attrNames (lib.filterAttrs (file: type: type == "directory") (builtins.readDir dir));
|
||||||
|
|
||||||
# Only useful for functors
|
# Only useful for functors
|
||||||
recMap = f: list:
|
recMap = f: list:
|
||||||
if list == [ ] then f
|
if list == [ ] then f
|
||||||
else recMap (f (head list)) (tail list)
|
else recMap (f (head list)) (tail list)
|
||||||
;
|
;
|
||||||
|
|
||||||
chain = {
|
chain = {
|
||||||
func = id;
|
func = id;
|
||||||
__functor = self: input:
|
__functor = self: input:
|
||||||
if (typeOf input) == "lambda"
|
if (typeOf input) == "lambda"
|
||||||
then self // { func = e: input (self.func e); }
|
then self // { func = e: input (self.func e); }
|
||||||
else self.func input;
|
else self.func input;
|
||||||
};
|
};
|
||||||
|
|
||||||
spread = function: list: if list == [ ] then function else spread (function (head list)) (tail list);
|
spread = function: list: if list == [ ] then function else spread (function (head list)) (tail list);
|
||||||
|
|
||||||
|
# Takes a function and makes it lazy, by consuming arguments and applying it to the inner function first
|
||||||
|
# before calling the original function
|
||||||
|
lazy = func: inner: {
|
||||||
|
inherit func;
|
||||||
|
app = inner;
|
||||||
|
__functor = self: input:
|
||||||
|
let app = self.app input; in
|
||||||
|
if (typeOf app) == "lambda" then self // { inherit app; }
|
||||||
|
else self.func app;
|
||||||
|
};
|
||||||
|
|
||||||
# Takes a function and makes it lazy, by consuming arguments and applying it to the inner function first
|
|
||||||
# before calling the original function
|
|
||||||
lazy = func: inner: {
|
|
||||||
inherit func;
|
|
||||||
app = inner;
|
|
||||||
__functor = self: input:
|
|
||||||
let app = self.app input; in
|
|
||||||
if (typeOf app) == "lambda" then self // { inherit app; }
|
|
||||||
else self.func app;
|
|
||||||
};
|
|
||||||
} // (
|
|
||||||
import ./digga.nix { inherit lib; }
|
|
||||||
) // (
|
|
||||||
import ./hosts.nix { inherit lib; }
|
|
||||||
) // (
|
|
||||||
import ./options.nix { inherit lib; }
|
|
||||||
)) // {
|
|
||||||
disko = import ./disko.nix { inherit lib; };
|
disko = import ./disko.nix { inherit lib; };
|
||||||
}
|
} // (
|
||||||
|
import ./digga.nix { inherit lib; }
|
||||||
|
) // (
|
||||||
|
import ./hosts.nix { inherit lib; }
|
||||||
|
) // (
|
||||||
|
import ./options.nix { inherit lib; }
|
||||||
|
))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue