mirror of
https://gitlab.com/rensa-nix/core.git
synced 2025-12-12 06:10:08 +01:00
chore: initial commit
This commit is contained in:
commit
3aeff518bb
20 changed files with 1122 additions and 0 deletions
56
lib/utils/accumulate.nix
Normal file
56
lib/utils/accumulate.nix
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
{l}: let
|
||||
unique =
|
||||
l.foldl' (
|
||||
acc: e:
|
||||
if l.elem e.name acc.visited
|
||||
then acc
|
||||
else {
|
||||
visited = acc.visited ++ [e.name];
|
||||
result = acc.result ++ [e];
|
||||
}
|
||||
) {
|
||||
visited = [];
|
||||
result = [];
|
||||
};
|
||||
|
||||
accumulate =
|
||||
l.foldl' (
|
||||
acc: new: let
|
||||
first = l.head new;
|
||||
cdr = l.tail new;
|
||||
second = l.head cdr;
|
||||
cdr' = l.tail cdr;
|
||||
third = l.head cdr';
|
||||
in
|
||||
(
|
||||
if first == null
|
||||
then {inherit (acc) output;}
|
||||
else {output = acc.output // first;}
|
||||
)
|
||||
// (
|
||||
if second == null
|
||||
then {inherit (acc) actions;}
|
||||
else {actions = acc.actions // second;}
|
||||
)
|
||||
// (
|
||||
if third == null
|
||||
then {inherit (acc) init;}
|
||||
else {init = acc.init ++ [third];}
|
||||
)
|
||||
) {
|
||||
output = {};
|
||||
actions = {};
|
||||
init = [];
|
||||
};
|
||||
|
||||
optionalLoad = cond: elem:
|
||||
if cond
|
||||
then elem
|
||||
else [
|
||||
null # empty output
|
||||
null # empty action
|
||||
null # empty init
|
||||
];
|
||||
in {
|
||||
inherit unique accumulate optionalLoad;
|
||||
}
|
||||
4
lib/utils/default.nix
Normal file
4
lib/utils/default.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{l}: {
|
||||
inherit (import ./accumulate.nix {inherit l;}) accumulate unique optionalLoad;
|
||||
inherit (import ./import-signature.nix {inherit l;}) createImportSignature deSystemize;
|
||||
}
|
||||
35
lib/utils/import-signature.nix
Normal file
35
lib/utils/import-signature.nix
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{l}: let
|
||||
deSystemize = let
|
||||
iteration = cutoff: system: fragment:
|
||||
if !(l.isAttrs fragment) || cutoff == 0
|
||||
then fragment
|
||||
else let
|
||||
recursed = l.mapAttrs (_: iteration (cutoff - 1) system) fragment;
|
||||
in
|
||||
if l.hasAttr "${system}" fragment
|
||||
then
|
||||
if l.isFunction fragment.${system}
|
||||
then recursed // {__functor = _: fragment.${system};}
|
||||
else recursed // fragment.${system}
|
||||
else recursed;
|
||||
in
|
||||
iteration 3;
|
||||
|
||||
createImportSignature = cfg: system: cell: cells: additionalInputs: let
|
||||
self =
|
||||
cfg.inputs.self.sourceInfo
|
||||
// {
|
||||
rev = cfg.inputs.self.sourceInfo.rev or "not-a-commit";
|
||||
};
|
||||
in {
|
||||
inputs =
|
||||
(deSystemize system (cfg.inputs // additionalInputs))
|
||||
// {
|
||||
inherit self;
|
||||
cells = deSystemize system cells;
|
||||
};
|
||||
inherit cell;
|
||||
};
|
||||
in {
|
||||
inherit deSystemize createImportSignature;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue