57 lines
1.3 KiB
Nix
57 lines
1.3 KiB
Nix
let
|
|
pkgs = import <nixpkgs> { };
|
|
inherit (pkgs) lib;
|
|
dirToAttrs =
|
|
root: patterns: f:
|
|
lib.listToAttrs (
|
|
lib.concatMap (
|
|
dirent:
|
|
let
|
|
fname = dirent.name;
|
|
typ = dirent.value;
|
|
fpath = root + "/${fname}";
|
|
doMatch =
|
|
pat:
|
|
let
|
|
match = pat fpath fname typ;
|
|
value = f match fpath typ;
|
|
in
|
|
if match == null then [ ] else [ (lib.nameValuePair match value) ];
|
|
in
|
|
(lib.take 1 (lib.concatMap (doMatch) patterns))
|
|
) (lib.attrsToList (builtins.readDir root))
|
|
);
|
|
in
|
|
{
|
|
examples =
|
|
dirToAttrs ./examples
|
|
[
|
|
(
|
|
path: fname: _:
|
|
lib.strings.removeSuffix ".nix" fname
|
|
)
|
|
]
|
|
(
|
|
name: fpath: _:
|
|
import <nixpkgs/nixos/lib/eval-config.nix> { modules = [ fpath ]; }
|
|
);
|
|
pkgs = lib.makeScope pkgs.newScope (
|
|
self:
|
|
dirToAttrs ./pkgs
|
|
[
|
|
(
|
|
path: fname: _:
|
|
lib.strings.removeSuffix ".nix" fname
|
|
)
|
|
]
|
|
(
|
|
name: fpath: typ:
|
|
if typ == "regular" then
|
|
self.callPackage fpath { }
|
|
else if typ == "directory" && builtins.pathExists (fpath + "/package.nix") then
|
|
self.callPackage (fpath + "/package.nix") { }
|
|
else
|
|
null
|
|
)
|
|
);
|
|
}
|