mirror of
https://gitlab.com/rensa-nix/core.git
synced 2026-02-02 15:25:08 +01:00
chore: initial commit
This commit is contained in:
commit
3aeff518bb
20 changed files with 1122 additions and 0 deletions
5
lib/compat/default.nix
Normal file
5
lib/compat/default.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{l}: rec {
|
||||
filter = import ./filter.nix {inherit l;};
|
||||
select = import ./select.nix {inherit filter;};
|
||||
get = import ./get.nix {inherit select;};
|
||||
}
|
||||
30
lib/compat/filter.nix
Normal file
30
lib/compat/filter.nix
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{l}: let
|
||||
filter = pred: t: p: let
|
||||
multiplePaths = l.isList (l.elemAt p 0);
|
||||
hoist = path: let
|
||||
result =
|
||||
l.filterAttrs (
|
||||
n: v:
|
||||
(l.elem n l.systems.doubles.all)
|
||||
&& (l.hasAttrByPath path v)
|
||||
)
|
||||
t;
|
||||
in
|
||||
if result == {}
|
||||
then builtins.abort "[ren] filter: Path ${toString path} not found in any targets."
|
||||
else
|
||||
l.mapAttrs (
|
||||
_: v: let
|
||||
attr = l.getAttrFromPath path v;
|
||||
in
|
||||
if pred == true
|
||||
then attr
|
||||
else l.filterAttrs pred attr
|
||||
)
|
||||
result;
|
||||
in
|
||||
if multiplePaths
|
||||
then l.foldl' l.recursiveUpdate {} (map (path: hoist path) p)
|
||||
else hoist p;
|
||||
in
|
||||
filter
|
||||
8
lib/compat/get.nix
Normal file
8
lib/compat/get.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{select}: let
|
||||
get = t: p: let
|
||||
r = select t p;
|
||||
s = builtins.head (builtins.attrNames r);
|
||||
in
|
||||
r.${s};
|
||||
in
|
||||
get
|
||||
2
lib/compat/select.nix
Normal file
2
lib/compat/select.nix
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
{filter}:
|
||||
filter true
|
||||
Loading…
Add table
Add a link
Reference in a new issue