diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..2e3573c --- /dev/null +++ b/Justfile @@ -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}} + diff --git a/checkmate/modules/formatter.nix b/checkmate/modules/formatter.nix index 976cdf9..41301a2 100644 --- a/checkmate/modules/formatter.nix +++ b/checkmate/modules/formatter.nix @@ -2,5 +2,6 @@ perSystem.treefmt.settings.global.excludes = [ "checkmate/tree/*" "docs/*" + "Justfile" ]; } diff --git a/checkmate/modules/tests.nix b/checkmate/modules/tests.nix index 7b15815..09aee13 100644 --- a/checkmate/modules/tests.nix +++ b/checkmate/modules/tests.nix @@ -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) + ]; + }).config.foo; + expected = 22; + }; }; } diff --git a/checkmate/tree/_scoped/foo.nix b/checkmate/tree/_scoped/foo.nix new file mode 100644 index 0000000..8badecc --- /dev/null +++ b/checkmate/tree/_scoped/foo.nix @@ -0,0 +1,4 @@ +{ lib, ... }: +{ + options.foo = lib.mkOption { default = foo; }; +} diff --git a/default.nix b/default.nix index d4f23a2..05adaf7 100644 --- a/default.nix +++ b/default.nix @@ -7,6 +7,7 @@ let filterf, mapf, paths, + scoped, ... }: path: @@ -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 @@ -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 @@ -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);