examples,pkgs,pkgs.ch-proxy: init

This commit is contained in:
Else, Someone 2025-09-17 15:51:59 +03:00
parent 81effc1ef3
commit 12e95630b1
4 changed files with 262 additions and 0 deletions

57
default.nix Normal file
View file

@ -0,0 +1,57 @@
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
)
);
}