initial commit
This commit is contained in:
commit
5679c003d8
26 changed files with 296 additions and 0 deletions
34
lib/flake.nix
Normal file
34
lib/flake.nix
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
let
|
||||
scan = import ./scan.nix;
|
||||
|
||||
flake' = self: { imports, exports , base }@schema: { ... }@inputs: { ... }@imports: let
|
||||
lib = {
|
||||
inherit scan schema inputs imports;
|
||||
extend = flake schema inputs imports;
|
||||
new = flake {} {} {};
|
||||
# TODO: override
|
||||
};
|
||||
convert = attr: value: value self inputs imports;
|
||||
|
||||
result = (builtins.mapAttrs convert schema.exports);
|
||||
in result // { lib = lib // (result.lib or {}); };
|
||||
|
||||
flake = { imports?{}, exports?{}, base?[] }@schema'old: { ... }@inputs'old: { ... }@imports'old: { ... }@inputs'new: base: let
|
||||
schema = {
|
||||
imports = (schema'old.imports or {}) // scan { base = base + "/import"; recursive = true; };
|
||||
exports = (schema'old.exports or {}) // scan { base = base + "/export"; };
|
||||
base = [ base ] ++ (schema'old.base or []);
|
||||
};
|
||||
|
||||
merge = attr: let
|
||||
old = imports'old.${attr} or {};
|
||||
new = imports'new.${attr} or {};
|
||||
in builtins.mapAttrs (attr: _: (old.${attr} or []) ++ (new.${attr} or [])) (old//new);
|
||||
|
||||
imports'new = builtins.mapAttrs (name: value: scan { base = base + "/${name}"; convert = name: content: [ (value name content) ]; }) schema.imports;
|
||||
result = flake' result schema
|
||||
(inputs'old // (builtins.removeAttrs inputs'new ["self"]))
|
||||
(builtins.mapAttrs (attr: _: merge attr) schema.imports);
|
||||
in result;
|
||||
|
||||
in flake {} {} {}
|
||||
1
lib/host.nix
Normal file
1
lib/host.nix
Normal file
|
|
@ -0,0 +1 @@
|
|||
self:
|
||||
23
lib/scan.nix
Normal file
23
lib/scan.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{ base, convert ? name: value: value, recursive ? false }:
|
||||
let
|
||||
scan = sub: let
|
||||
all = builtins.readDir (base + "/${builtins.concatStringsSep "/" sub}");
|
||||
names = filter: builtins.filter filter (builtins.attrNames all);
|
||||
nix = name: all.${name} == "regular" && builtins.stringLength name > 4 && builtins.substring (builtins.stringLength name - 4) 4 name == ".nix";
|
||||
dir = name: all.${name} == "directory";
|
||||
files = map (name: sub ++ [ (builtins.substring 0 (builtins.stringLength name - 4) name) ]) (names nix);
|
||||
dirs = builtins.concatLists (map (name: scan (sub ++ [name])) (names dir));
|
||||
in if recursive then files ++ dirs else files;
|
||||
|
||||
root = scan [];
|
||||
|
||||
item = relative: let
|
||||
name = builtins.concatStringsSep "/" relative;
|
||||
absolute = base + "/${name}.nix";
|
||||
content = import absolute;
|
||||
value = convert name content;
|
||||
in { inherit name value; };
|
||||
|
||||
items = map item root;
|
||||
|
||||
in if builtins.pathExists base then builtins.listToAttrs (map item root) else {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue