Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
system := `nix-instantiate --eval --raw -E builtins.currentSystem`

help:
just -l

ci:
just fmt -- --ci --no-cache
just test

fmt *args:
nix run github:denful/checkmate#fmt --override-input target path:. {{args}}

test *args:
nix flake check github:denful/checkmate --override-input target . {{args}}

1 change: 1 addition & 0 deletions checkmate/modules/formatter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
perSystem.treefmt.settings.global.excludes = [
"checkmate/tree/*"
"docs/*"
"Justfile"
];
}
10 changes: 10 additions & 0 deletions checkmate/modules/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ in
expr = lit.leafs ../tree/a/b/_c;
expected = [ ../tree/a/b/_c/d/e.nix ];
};

scoped."test adds attrs via scopedImport" = {
expr =
(lib.evalModules {
modules = [
((lit.addScoped { foo = 22; }) ../tree/_scoped)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's such a sweet little API!

];
}).config.foo;
expected = 22;
};
};

}
Expand Down
4 changes: 4 additions & 0 deletions checkmate/tree/_scoped/foo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ lib, ... }:
{
options.foo = lib.mkOption { default = foo; };
}
15 changes: 14 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let
filterf,
mapf,
paths,
scoped,
...
}:
path:
Expand All @@ -23,9 +24,19 @@ let
module =
{ lib, ... }:
{
imports = leafs lib path;
imports = (if scoped == { } then leafs else scoped-leafs) lib path;
};

scoped-leafs =
lib: root:
map (builtins.scopedImport (
{
inherit builtins;
__nixPath = [ ];
}
// scoped
)) (leafs lib root);

leafs =
lib:
let
Expand Down Expand Up @@ -144,6 +155,7 @@ let
mapf = (i: i);
filterf = _: true;
paths = [ ];
scoped = { };

# config is our state (initial at first). this functor allows it
# to work as if it was a function, taking an update function
Expand Down Expand Up @@ -175,6 +187,7 @@ let
match = regex: accAttr "filterf" (and (matchesRegex regex));
matchNot = regex: accAttr "filterf" (andNot (matchesRegex regex));
map = mapf: accAttr "mapf" (compose mapf);
addScoped = attrs: accAttr "scoped" (s: s // attrs);
addPath = path: accAttr "paths" (p: p ++ [ path ]);
addAPI = api: accAttr "api" (a: a // api);

Expand Down