split tests, reorg types #1

open
opened by oeiuwq.com targeting main from provider
+1 -1
.github/workflows/test.yml
···
runs-on: ubuntu-latest
steps:
- uses: cachix/install-nix-action@v30
-
- run: nix flake check -L github:vic/checkmate --override-input target github:$GITHUB_REPOSITORY/$GITHUB_SHA
+
- run: nix flake check -L github:$GITHUB_REPOSITORY/$GITHUB_SHA?dir=checkmate --override-input target github:$GITHUB_REPOSITORY/$GITHUB_SHA
+184
checkmate/flake.lock
···
+
{
+
"nodes": {
+
"flake-parts": {
+
"inputs": {
+
"nixpkgs-lib": [
+
"nixpkgs-lib"
+
]
+
},
+
"locked": {
+
"lastModified": 1763759067,
+
"narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=",
+
"owner": "hercules-ci",
+
"repo": "flake-parts",
+
"rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0",
+
"type": "github"
+
},
+
"original": {
+
"owner": "hercules-ci",
+
"repo": "flake-parts",
+
"type": "github"
+
}
+
},
+
"import-tree": {
+
"locked": {
+
"lastModified": 1763762820,
+
"narHash": "sha256-ZvYKbFib3AEwiNMLsejb/CWs/OL/srFQ8AogkebEPF0=",
+
"owner": "vic",
+
"repo": "import-tree",
+
"rev": "3c23749d8013ec6daa1d7255057590e9ca726646",
+
"type": "github"
+
},
+
"original": {
+
"owner": "vic",
+
"repo": "import-tree",
+
"type": "github"
+
}
+
},
+
"nix-github-actions": {
+
"inputs": {
+
"nixpkgs": [
+
"nix-unit",
+
"nixpkgs"
+
]
+
},
+
"locked": {
+
"lastModified": 1737420293,
+
"narHash": "sha256-F1G5ifvqTpJq7fdkT34e/Jy9VCyzd5XfJ9TO8fHhJWE=",
+
"owner": "nix-community",
+
"repo": "nix-github-actions",
+
"rev": "f4158fa080ef4503c8f4c820967d946c2af31ec9",
+
"type": "github"
+
},
+
"original": {
+
"owner": "nix-community",
+
"repo": "nix-github-actions",
+
"type": "github"
+
}
+
},
+
"nix-unit": {
+
"inputs": {
+
"flake-parts": [
+
"flake-parts"
+
],
+
"nix-github-actions": "nix-github-actions",
+
"nixpkgs": [
+
"nixpkgs"
+
],
+
"treefmt-nix": "treefmt-nix"
+
},
+
"locked": {
+
"lastModified": 1762774186,
+
"narHash": "sha256-hRADkHjNt41+JUHw2EiSkMaL4owL83g5ZppjYUdF/Dc=",
+
"owner": "nix-community",
+
"repo": "nix-unit",
+
"rev": "1c9ab50554eed0b768f9e5b6f646d63c9673f0f7",
+
"type": "github"
+
},
+
"original": {
+
"owner": "nix-community",
+
"repo": "nix-unit",
+
"type": "github"
+
}
+
},
+
"nixpkgs": {
+
"locked": {
+
"lastModified": 1764587062,
+
"narHash": "sha256-hdFa0TAVQAQLDF31cEW3enWmBP+b592OvHs6WVe3D8k=",
+
"owner": "nixos",
+
"repo": "nixpkgs",
+
"rev": "c1cb7d097cb250f6e1904aacd5f2ba5ffd8a49ce",
+
"type": "github"
+
},
+
"original": {
+
"owner": "nixos",
+
"ref": "nixpkgs-unstable",
+
"repo": "nixpkgs",
+
"type": "github"
+
}
+
},
+
"root": {
+
"inputs": {
+
"flake-parts": "flake-parts",
+
"import-tree": "import-tree",
+
"nix-unit": "nix-unit",
+
"nixpkgs": "nixpkgs",
+
"nixpkgs-lib": [
+
"nixpkgs"
+
],
+
"systems": "systems",
+
"target": "target",
+
"treefmt-nix": "treefmt-nix_2"
+
}
+
},
+
"systems": {
+
"locked": {
+
"lastModified": 1681028828,
+
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+
"owner": "nix-systems",
+
"repo": "default",
+
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+
"type": "github"
+
},
+
"original": {
+
"owner": "nix-systems",
+
"repo": "default",
+
"type": "github"
+
}
+
},
+
"target": {
+
"locked": {
+
"path": "..",
+
"type": "path"
+
},
+
"original": {
+
"path": "..",
+
"type": "path"
+
},
+
"parent": []
+
},
+
"treefmt-nix": {
+
"inputs": {
+
"nixpkgs": [
+
"nix-unit",
+
"nixpkgs"
+
]
+
},
+
"locked": {
+
"lastModified": 1762410071,
+
"narHash": "sha256-aF5fvoZeoXNPxT0bejFUBXeUjXfHLSL7g+mjR/p5TEg=",
+
"owner": "numtide",
+
"repo": "treefmt-nix",
+
"rev": "97a30861b13c3731a84e09405414398fbf3e109f",
+
"type": "github"
+
},
+
"original": {
+
"owner": "numtide",
+
"repo": "treefmt-nix",
+
"type": "github"
+
}
+
},
+
"treefmt-nix_2": {
+
"inputs": {
+
"nixpkgs": [
+
"nixpkgs"
+
]
+
},
+
"locked": {
+
"lastModified": 1762938485,
+
"narHash": "sha256-AlEObg0syDl+Spi4LsZIBrjw+snSVU4T8MOeuZJUJjM=",
+
"owner": "numtide",
+
"repo": "treefmt-nix",
+
"rev": "5b4ee75aeefd1e2d5a1cc43cf6ba65eba75e83e4",
+
"type": "github"
+
},
+
"original": {
+
"owner": "numtide",
+
"repo": "treefmt-nix",
+
"type": "github"
+
}
+
}
+
},
+
"root": "root",
+
"version": 7
+
}
+28
checkmate/flake.nix
···
+
{
+
+
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules);
+
+
inputs = {
+
target.url = "path:..";
+
flake-parts = {
+
inputs.nixpkgs-lib.follows = "nixpkgs-lib";
+
url = "github:hercules-ci/flake-parts";
+
};
+
import-tree.url = "github:vic/import-tree";
+
nix-unit = {
+
inputs = {
+
flake-parts.follows = "flake-parts";
+
nixpkgs.follows = "nixpkgs";
+
};
+
url = "github:nix-community/nix-unit";
+
};
+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
+
nixpkgs-lib.follows = "nixpkgs";
+
systems.url = "github:nix-systems/default";
+
treefmt-nix = {
+
inputs.nixpkgs.follows = "nixpkgs";
+
url = "github:numtide/treefmt-nix";
+
};
+
};
+
+
}
+25
checkmate/modules/checkmate.nix
···
+
{ inputs, lib, ... }:
+
{
+
imports = [
+
inputs.nix-unit.modules.flake.default
+
inputs.treefmt-nix.flakeModule
+
];
+
systems = import inputs.systems;
+
+
perSystem =
+
{ self', ... }:
+
{
+
packages.fmt = self'.formatter;
+
treefmt.projectRoot = inputs.target;
+
nix-unit = {
+
allowNetwork = true;
+
inputs = inputs;
+
};
+
treefmt.programs = {
+
nixfmt.enable = true;
+
};
+
treefmt.settings.global.excludes = [
+
"LICENSE"
+
];
+
};
+
}
+61 -512
checkmate/modules/tests.nix
···
-
{ inputs, ... }:
-
{
-
perSystem =
-
{ lib, ... }:
-
let
-
transpose = import ../../nix { inherit lib; };
-
-
mkFlake =
-
mod:
-
inputs.flake-parts.lib.mkFlake
-
{
-
inputs.self = [ ];
-
}
-
{
-
systems = [ ];
-
imports = [
-
../../nix/flakeModule.nix
-
inputs.flake-parts.flakeModules.modules
-
mod
-
(fooMod "aspectOne")
-
(fooMod "aspectTwo")
-
(fooMod "aspectThree")
-
];
-
};
-
-
fooMod = aspect: {
+
{ inputs, lib, ... }:
+
let
+
targetNix = "${inputs.target}/nix";
+
targetLib = "${inputs.target}/nix/lib.nix";
+
targetMod = "${inputs.target}/nix/flakeModule.nix";
+
+
transpose = import targetNix { inherit lib; };
+
+
mkFlake =
+
mod:
+
inputs.flake-parts.lib.mkFlake
+
{
+
inputs.self = [ ];
+
}
+
{
+
systems = [ ];
imports = [
-
{ flake.modules.classOne.${aspect}.imports = [ fooOpt ]; }
-
{ flake.modules.classTwo.${aspect}.imports = [ fooOpt ]; }
-
{ flake.modules.classThree.${aspect}.imports = [ fooOpt ]; }
+
targetMod
+
inputs.flake-parts.flakeModules.modules
+
mod
+
(fooMod "aspectOne")
+
(fooMod "aspectTwo")
+
(fooMod "aspectThree")
];
};
-
fooOpt = {
-
options.foo = lib.mkOption {
-
type = lib.types.str;
-
default = "<unset>";
-
};
-
options.bar = lib.mkOption {
-
type = lib.types.listOf lib.types.str;
-
default = [ ];
-
};
-
options.baz = lib.mkOption {
-
type = lib.types.lazyAttrsOf lib.types.str;
-
default = { };
-
};
-
};
-
-
evalMod =
-
class: mod:
-
(lib.evalModules {
-
inherit class;
-
modules = [ mod ];
-
}).config;
-
in
-
{
-
nix-unit.tests = {
-
transpose."test swaps parent and child attrNames" = {
-
expr = transpose { a.b.c = 1; };
-
expected = {
-
b.a.c = 1;
-
};
-
};
-
-
transpose."test common childs become one parent" = {
-
expr = transpose {
-
a.b = 1;
-
c.b = 2;
-
};
-
expected.b = {
-
a = 1;
-
c = 2;
-
};
-
};
-
-
new-scope."test usage without flakes" =
-
let
-
flake-aspects-lib = import ../../nix/lib.nix lib;
-
# first eval is like evaling the flake.
-
first = lib.evalModules {
-
modules = [
-
(flake-aspects-lib.new-scope "hello")
-
{
-
hello.aspects =
-
{ aspects, ... }:
-
{
-
a.b.c = [ "world" ];
-
a.includes = [ aspects.x ];
-
x.b =
-
{ lib, ... }:
-
{
-
c = lib.splitString " " "mundo cruel";
-
};
-
};
-
}
-
];
-
};
-
# second eval is like evaling its nixosConfiguration
-
second = lib.evalModules {
-
modules = [
-
{ options.c = lib.mkOption { type = lib.types.listOf lib.types.str; }; }
-
first.config.hello.modules.b.a
-
];
-
};
-
expr = lib.sort (a: b: a < b) second.config.c;
-
expected = [
-
"cruel"
-
"mundo"
-
"world"
-
];
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test provides default" =
-
let
-
flake =
-
inputs.flake-parts.lib.mkFlake
-
{
-
inputs.self = [ ];
-
moduleLocation = builtins.toString ./.;
-
}
-
{
-
systems = [ ];
-
imports = [
-
../../nix/flakeModule.nix
-
inputs.flake-parts.flakeModules.modules
-
];
-
};
-
expr = flake.modules;
-
expected = { };
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test transposes to flake.modules" =
-
let
-
flake = mkFlake {
-
flake.aspects.aspectOne = {
-
classOne.foo = "niri";
-
classTwo.foo = "paper.spoon";
-
};
-
};
-
expr = {
-
classOne = (evalMod "classOne" flake.modules.classOne.aspectOne).foo;
-
classTwo = (evalMod "classTwo" flake.modules.classTwo.aspectOne).foo;
-
};
-
expected = {
-
classOne = "niri";
-
classTwo = "paper.spoon";
-
};
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test dependencies on aspects" =
-
let
-
flake = mkFlake {
-
flake.aspects =
-
{ aspects, ... }:
-
{
-
aspectOne = {
-
description = "os config";
-
includes = with aspects; [ aspectTwo ];
-
classOne.bar = [ "os" ];
-
};
-
-
aspectTwo = {
-
description = "user config at os level";
-
classOne.bar = [ "user" ];
-
};
-
};
-
};
-
expr = lib.sort (a: b: a < b) (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
-
expected = [
-
"os"
-
"user"
-
];
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test resolve aspect-chain" =
-
let
-
flake = mkFlake {
-
flake.aspects =
-
{ aspects, ... }:
-
{
-
aspectOne = {
-
name = "one";
-
includes = [ aspects.aspectOne.provides.dos ];
-
classOne.bar = [ "zzz" ];
-
provides.dos =
-
{ aspect-chain, ... }:
-
{
-
name = "dos";
-
includes = [ aspects.aspectOne.provides.tres ];
-
classOne.bar = map (x: x.name) aspect-chain;
-
};
-
-
provides.tres =
-
{ aspect-chain, ... }:
-
{
-
name = "tres";
-
classOne.bar = [ (lib.last aspect-chain).name ];
-
};
-
};
-
};
-
};
-
mod = {
-
imports = [
-
fooOpt
-
(flake.aspects.aspectOne.resolve { class = "classOne"; })
-
];
-
};
-
expr = lib.sort (a: b: a < b) (evalMod "classOne" mod).bar;
-
expected = [
-
"dos"
-
"one"
-
"zzz"
-
];
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test modules resolved" =
-
let
-
flake = mkFlake {
-
flake.aspects =
-
{ aspects, ... }:
-
{
-
aspectOne = {
-
name = "one";
-
includes = [ aspects.aspectOne.provides.dos ];
-
classOne.bar = [ "zzz" ];
-
provides.dos =
-
{ aspect-chain, ... }:
-
{
-
name = "dos";
-
includes = [ aspects.aspectOne.provides.tres ];
-
classOne.bar = map (x: x.name) aspect-chain;
-
};
-
-
provides.tres =
-
{ aspect-chain, ... }:
-
{
-
name = "tres";
-
classOne.bar = [ (lib.last aspect-chain).name ];
-
};
-
};
-
};
-
};
-
mod = {
-
imports = [
-
fooOpt
-
(flake.aspects.aspectOne.modules.classOne)
-
];
-
};
-
expr = lib.sort (a: b: a < b) (evalMod "classOne" mod).bar;
-
expected = [
-
"dos"
-
"one"
-
"zzz"
-
];
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test provides" =
-
let
-
flake = mkFlake {
-
flake.aspects =
-
{ aspects, ... }:
-
{
-
aspectOne.includes = with aspects.aspectTwo.provides; [
-
foo
-
bar
-
];
-
aspectOne.classOne = { }; # must be present for mixing dependencies.
-
aspectTwo = {
-
classOne.bar = [ "class one not included" ];
-
classTwo.bar = [ "class two not included" ];
-
provides.foo =
-
{ class, aspect-chain }:
-
{
-
name = "aspectTwo.foo";
-
description = "aspectTwo foo provided";
-
includes = [
-
aspects.aspectThree.provides.moo
-
aspects.aspectTwo.provides.baz
-
];
-
classOne.bar = [ "two:${class}:${lib.concatStringsSep "/" (lib.map (x: x.name) aspect-chain)}" ];
-
classTwo.bar = [ "foo class two not included" ];
-
};
-
# a provider can be immediately an aspect object.
-
provides.bar = {
-
# classOne is missing on bar
-
classTwo.bar = [ "bar class two not included" ];
-
};
-
# _ is an shortcut alias of provides.
-
_.baz = {
-
# classOne is missing on bar
-
classTwo.bar = [ "baz" ];
-
};
-
};
-
aspectThree.provides.moo =
-
{ aspect-chain, class }:
-
{
-
classOne.bar = [ "three:${class}:${lib.concatStringsSep "/" (lib.map (x: x.name) aspect-chain)}" ];
-
};
-
};
-
};
-
expr = lib.sort (a: b: a < b) (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
-
expected = [
-
"three:classOne:aspectOne/aspectTwo.foo"
-
"two:classOne:aspectOne"
-
];
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test provides using fixpoints" =
-
let
-
flake = mkFlake {
-
flake.aspects =
-
{ aspects, ... }:
-
{
-
aspectOne = {
-
classOne.bar = [ "1" ];
-
includes = [
-
aspects.aspectTwo
-
];
-
};
-
-
aspectTwo = {
-
classOne.bar = [ "2" ];
-
includes = [ aspects.aspectTwo.provides.three-and-four-and-five ];
-
provides =
-
{ provides, ... }:
-
{
-
three-and-four-and-five = {
-
classOne.bar = [ "3" ];
-
includes = [
-
provides.four
-
aspects.five
-
];
-
};
-
four = {
-
classOne.bar = [ "4" ];
-
};
-
};
-
};
-
-
five.classOne.bar = [ "5" ];
-
};
-
};
-
-
expr = lib.sort (a: b: a < b) (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
-
expected = [
-
"1"
-
"2"
-
"3"
-
"4"
-
"5"
-
];
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test provides parametrized modules" =
-
let
-
flake = mkFlake {
-
flake.aspects =
-
{ aspects, ... }:
-
{
-
aspectOne.includes = [ (aspects.aspectTwo.provides.hello "mundo") ];
-
aspectOne.classOne.bar = [ "1" ];
-
-
aspectTwo.provides.hello = world: {
-
classOne.bar = [ world ];
-
};
-
};
-
};
-
-
expr = lib.sort (a: b: a < b) (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
-
expected = [
-
"1"
-
"mundo"
-
];
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test override default provider" =
-
let
-
flake = mkFlake {
-
flake.aspects =
-
{ aspects, ... }:
-
{
-
aspectOne =
-
{ aspect, ... }:
-
{
-
includes = [ (aspects.aspectTwo { message = "hello ${aspect.name}"; }) ];
-
classOne = { }; # required for propagation
-
};
-
-
aspectTwo.__functor =
-
_:
-
{ message }: # args must be always named
-
{ class, aspect-chain }:
-
{ aspect, ... }:
-
{
-
classOne.bar = [
-
"foo"
-
aspect.name
-
message
-
class
-
]
-
++ (lib.map (x: x.name) aspect-chain);
-
};
-
aspectTwo.classOne.bar = [ "itself not included" ];
-
};
-
};
-
-
expr = (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
-
expected = [
-
"foo"
-
"<function body>"
-
"hello aspectOne"
-
"classOne"
-
"aspectOne"
-
];
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test override default provider includes" =
-
let
-
flake = mkFlake {
-
flake.aspects =
-
{ aspects, ... }:
-
{
-
aspectOne = {
-
classOne.bar = [ "should-not-be-present" ];
-
includes = [ aspects.aspectTwo ];
-
__functor = aspect: {
-
includes = [
-
{ classOne.bar = [ "from-functor" ]; }
-
]
-
++ map (f: f { message = "hello"; }) aspect.includes;
-
};
-
};
-
aspectTwo.__functor =
-
_aspect:
-
{ message }:
-
{
-
classOne.bar = [ message ];
-
};
-
};
-
};
-
-
expr = (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
-
expected = [
-
"hello"
-
"from-functor"
-
];
-
in
-
{
-
inherit expr expected;
-
};
-
-
aspects."test define top-level context-aware aspect" =
-
let
-
flake = mkFlake {
-
flake.aspects =
-
{ aspects, ... }:
-
{
-
aspectOne = {
-
classOne.bar = [ "should-not-be-present" ];
-
includes = [ aspects.aspectTwo ];
-
__functor = aspect: {
-
includes = [
-
{ classOne.bar = [ "from-functor" ]; }
-
]
-
++ map (f: f { message = "hello"; }) aspect.includes;
-
};
-
};
-
aspectTwo =
-
{ message }:
-
{
-
classOne.bar = [ message ];
-
};
-
};
-
};
-
-
expr = (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
-
expected = [
-
"hello"
-
"from-functor"
-
];
-
in
-
{
-
inherit expr expected;
-
};
-
};
-
+
fooMod = aspect: {
+
imports = [
+
{ flake.modules.classOne.${aspect}.imports = [ fooOpt ]; }
+
{ flake.modules.classTwo.${aspect}.imports = [ fooOpt ]; }
+
{ flake.modules.classThree.${aspect}.imports = [ fooOpt ]; }
+
];
+
};
+
+
fooOpt = {
+
options.foo = lib.mkOption {
+
type = lib.types.str;
+
default = "<unset>";
+
};
+
options.bar = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
+
default = [ ];
};
+
options.baz = lib.mkOption {
+
type = lib.types.lazyAttrsOf lib.types.str;
+
default = { };
+
};
+
};
+
+
evalMod =
+
class: mod:
+
(lib.evalModules {
+
inherit class;
+
modules = [ mod ];
+
}).config;
+
in
+
{
+
_module.args = {
+
inherit
+
transpose
+
targetLib
+
targetMod
+
targetNix
+
;
+
inherit mkFlake evalMod fooOpt;
+
};
}
+53
checkmate/modules/tests/aspect_chain.nix
···
+
{
+
lib,
+
mkFlake,
+
evalMod,
+
fooOpt,
+
...
+
}:
+
{
+
+
flake.tests."test resolve aspect-chain" =
+
let
+
flake = mkFlake {
+
flake.aspects =
+
{ aspects, ... }:
+
{
+
aspectOne = {
+
name = "one";
+
includes = [ aspects.aspectOne.provides.dos ];
+
classOne.bar = [ "zzz" ];
+
provides.dos =
+
{ aspect-chain, ... }:
+
{
+
name = "dos";
+
includes = [ aspects.aspectOne.provides.tres ];
+
classOne.bar = map (x: x.name) aspect-chain;
+
};
+
+
provides.tres =
+
{ aspect-chain, ... }:
+
{
+
name = "tres";
+
classOne.bar = [ (lib.last aspect-chain).name ];
+
};
+
};
+
};
+
};
+
mod = {
+
imports = [
+
fooOpt
+
(flake.aspects.aspectOne.resolve { class = "classOne"; })
+
];
+
};
+
expr = lib.sort (a: b: a < b) (evalMod "classOne" mod).bar;
+
expected = [
+
"dos"
+
"one"
+
"zzz"
+
];
+
in
+
{
+
inherit expr expected;
+
};
+
}
+53
checkmate/modules/tests/aspect_default_provider_functor.nix
···
+
{
+
mkFlake,
+
evalMod,
+
lib,
+
...
+
}:
+
{
+
+
flake.tests."test override default provider" =
+
let
+
flake = mkFlake {
+
flake.aspects =
+
{ aspects, ... }:
+
{
+
aspectOne =
+
{ aspect, ... }:
+
{
+
includes = [ (aspects.aspectTwo { message = "hello ${aspect.name}"; }) ];
+
classOne = { }; # required for propagation
+
};
+
+
aspectTwo.__functor =
+
_:
+
{ message }: # args must be always named
+
{ class, aspect-chain }:
+
{ aspect, ... }:
+
{
+
classOne.bar = [
+
"foo"
+
aspect.name
+
message
+
class
+
]
+
++ (lib.map (x: x.name) aspect-chain);
+
};
+
aspectTwo.classOne.bar = [ "itself not included" ];
+
};
+
};
+
+
expr = (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
+
expected = [
+
"foo"
+
"<function body>"
+
"hello aspectOne"
+
"classOne"
+
"aspectOne"
+
];
+
in
+
{
+
inherit expr expected;
+
};
+
+
}
+43
checkmate/modules/tests/aspect_default_provider_override.nix
···
+
{
+
mkFlake,
+
evalMod,
+
lib,
+
...
+
}:
+
{
+
+
flake.tests."test override default provider includes" =
+
let
+
flake = mkFlake {
+
flake.aspects =
+
{ aspects, ... }:
+
{
+
aspectOne = {
+
classOne.bar = [ "should-not-be-present" ];
+
includes = [ aspects.aspectTwo ];
+
__functor = aspect: {
+
includes = [
+
{ classOne.bar = [ "from-functor" ]; }
+
]
+
++ map (f: f { message = "hello"; }) aspect.includes;
+
};
+
};
+
aspectTwo.__functor =
+
_aspect:
+
{ message }:
+
{
+
classOne.bar = [ message ];
+
};
+
};
+
};
+
+
expr = (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
+
expected = [
+
"hello"
+
"from-functor"
+
];
+
in
+
{
+
inherit expr expected;
+
};
+
}
+37
checkmate/modules/tests/aspect_dependencies.nix
···
+
{
+
mkFlake,
+
evalMod,
+
lib,
+
...
+
}:
+
{
+
+
flake.tests."test dependencies on aspects" =
+
let
+
flake = mkFlake {
+
flake.aspects =
+
{ aspects, ... }:
+
{
+
aspectOne = {
+
description = "os config";
+
includes = with aspects; [ aspectTwo ];
+
classOne.bar = [ "os" ];
+
};
+
+
aspectTwo = {
+
description = "user config at os level";
+
classOne.bar = [ "user" ];
+
};
+
};
+
};
+
expr = lib.sort (a: b: a < b) (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
+
expected = [
+
"os"
+
"user"
+
];
+
in
+
{
+
inherit expr expected;
+
};
+
+
}
+59
checkmate/modules/tests/aspect_fixpoint.nix
···
+
{
+
lib,
+
mkFlake,
+
evalMod,
+
fooOpt,
+
...
+
}:
+
{
+
+
flake.tests."test provides using fixpoints" =
+
let
+
flake = mkFlake {
+
flake.aspects =
+
{ aspects, ... }@top:
+
{
+
aspectOne = {
+
classOne.bar = [ "1" ];
+
includes = [
+
aspects.aspectTwo
+
];
+
};
+
+
aspectTwo = {
+
classOne.bar = [ "2" ];
+
includes = [ aspects.aspectTwo.provides.three-and-four-and-five ];
+
provides =
+
{ aspects, ... }:
+
{
+
three-and-four-and-five = {
+
classOne.bar = [ "3" ];
+
includes = [
+
aspects.four
+
top.aspects.five
+
];
+
};
+
four = {
+
classOne.bar = [ "4" ];
+
};
+
};
+
};
+
+
five.classOne.bar = [ "5" ];
+
};
+
};
+
+
expr = lib.sort (a: b: a < b) (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
+
expected = [
+
"1"
+
"2"
+
"3"
+
"4"
+
"5"
+
];
+
in
+
{
+
inherit expr expected;
+
};
+
+
}
+54
checkmate/modules/tests/aspect_modules_resolved.nix
···
+
{
+
lib,
+
mkFlake,
+
evalMod,
+
fooOpt,
+
...
+
}:
+
{
+
+
flake.tests."test modules resolved" =
+
let
+
flake = mkFlake {
+
flake.aspects =
+
{ aspects, ... }:
+
{
+
aspectOne = {
+
name = "one";
+
includes = [ aspects.aspectOne.provides.dos ];
+
classOne.bar = [ "zzz" ];
+
provides.dos =
+
{ aspect-chain, ... }:
+
{
+
name = "dos";
+
includes = [ aspects.aspectOne.provides.tres ];
+
classOne.bar = map (x: x.name) aspect-chain;
+
};
+
+
provides.tres =
+
{ aspect-chain, ... }:
+
{
+
name = "tres";
+
classOne.bar = [ (lib.last aspect-chain).name ];
+
};
+
};
+
};
+
};
+
mod = {
+
imports = [
+
fooOpt
+
(flake.aspects.aspectOne.modules.classOne)
+
];
+
};
+
expr = lib.sort (a: b: a < b) (evalMod "classOne" mod).bar;
+
expected = [
+
"dos"
+
"one"
+
"zzz"
+
];
+
in
+
{
+
inherit expr expected;
+
};
+
+
}
+34
checkmate/modules/tests/aspect_parametric.nix
···
+
{
+
mkFlake,
+
evalMod,
+
lib,
+
...
+
}:
+
{
+
+
flake.tests."test provides parametrized modules" =
+
let
+
flake = mkFlake {
+
flake.aspects =
+
{ aspects, ... }:
+
{
+
aspectOne.includes = [ (aspects.aspectTwo.provides.hello "mundo") ];
+
aspectOne.classOne.bar = [ "1" ];
+
+
aspectTwo.provides.hello = world: {
+
classOne.bar = [ world ];
+
};
+
};
+
};
+
+
expr = lib.sort (a: b: a < b) (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
+
expected = [
+
"1"
+
"mundo"
+
];
+
in
+
{
+
inherit expr expected;
+
};
+
+
}
+64
checkmate/modules/tests/aspect_provides.nix
···
+
{
+
lib,
+
mkFlake,
+
evalMod,
+
fooOpt,
+
...
+
}:
+
{
+
+
flake.tests."test provides" =
+
let
+
flake = mkFlake {
+
flake.aspects =
+
{ aspects, ... }:
+
{
+
aspectOne.includes = with aspects.aspectTwo.provides; [
+
foo
+
bar
+
];
+
aspectOne.classOne = { }; # must be present for mixing dependencies.
+
aspectTwo = {
+
classOne.bar = [ "class one not included" ];
+
classTwo.bar = [ "class two not included" ];
+
provides.foo =
+
{ class, aspect-chain }:
+
{
+
name = "aspectTwo.foo";
+
description = "aspectTwo foo provided";
+
includes = [
+
aspects.aspectThree.provides.moo
+
aspects.aspectTwo.provides.baz
+
];
+
classOne.bar = [ "two:${class}:${lib.concatStringsSep "/" (lib.map (x: x.name) aspect-chain)}" ];
+
classTwo.bar = [ "foo class two not included" ];
+
};
+
# a provider can be immediately an aspect object.
+
provides.bar = {
+
# classOne is missing on bar
+
classTwo.bar = [ "bar class two not included" ];
+
};
+
# _ is an shortcut alias of provides.
+
_.baz = {
+
# classOne is missing on bar
+
classTwo.bar = [ "baz" ];
+
};
+
};
+
aspectThree.provides.moo =
+
{ aspect-chain, class }:
+
{
+
classOne.bar = [ "three:${class}:${lib.concatStringsSep "/" (lib.map (x: x.name) aspect-chain)}" ];
+
};
+
};
+
};
+
expr = lib.sort (a: b: a < b) (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
+
expected = [
+
"three:classOne:aspectOne/aspectTwo.foo"
+
"two:classOne:aspectOne"
+
];
+
in
+
{
+
inherit expr expected;
+
};
+
+
}
+42
checkmate/modules/tests/aspect_toplevel_parametric.nix
···
+
{
+
mkFlake,
+
evalMod,
+
lib,
+
...
+
}:
+
{
+
+
flake.tests."test define top-level context-aware aspect" =
+
let
+
flake = mkFlake {
+
flake.aspects =
+
{ aspects, ... }:
+
{
+
aspectOne = {
+
classOne.bar = [ "should-not-be-present" ];
+
includes = [ aspects.aspectTwo ];
+
__functor = aspect: {
+
includes = [
+
{ classOne.bar = [ "from-functor" ]; }
+
]
+
++ map (f: f { message = "hello"; }) aspect.includes;
+
};
+
};
+
aspectTwo =
+
{ message }:
+
{
+
classOne.bar = [ message ];
+
};
+
};
+
};
+
+
expr = (evalMod "classOne" flake.modules.classOne.aspectOne).bar;
+
expected = [
+
"hello"
+
"from-functor"
+
];
+
in
+
{
+
inherit expr expected;
+
};
+
}
+30
checkmate/modules/tests/default_empty.nix
···
+
{
+
lib,
+
inputs,
+
targetMod,
+
...
+
}:
+
{
+
+
flake.tests."test provides default" =
+
let
+
flake =
+
inputs.flake-parts.lib.mkFlake
+
{
+
inputs.self = [ ];
+
moduleLocation = builtins.toString ./.;
+
}
+
{
+
systems = [ ];
+
imports = [
+
targetMod
+
inputs.flake-parts.flakeModules.modules
+
];
+
};
+
expr = flake.modules;
+
expected = { };
+
in
+
{
+
inherit expr expected;
+
};
+
}
+29
checkmate/modules/tests/tranpose_flake_modules.nix
···
+
{
+
mkFlake,
+
lib,
+
evalMod,
+
...
+
}:
+
{
+
+
flake.tests."test transposes to flake.modules" =
+
let
+
flake = mkFlake {
+
flake.aspects.aspectOne = {
+
classOne.foo = "niri";
+
classTwo.foo = "paper.spoon";
+
};
+
};
+
expr = {
+
classOne = (evalMod "classOne" flake.modules.classOne.aspectOne).foo;
+
classTwo = (evalMod "classTwo" flake.modules.classTwo.aspectOne).foo;
+
};
+
expected = {
+
classOne = "niri";
+
classTwo = "paper.spoon";
+
};
+
in
+
{
+
inherit expr expected;
+
};
+
}
+15
checkmate/modules/tests/transpose_common.nix
···
+
{ transpose, ... }:
+
{
+
+
flake.tests."test transpose common childs become one parent" = {
+
expr = transpose {
+
a.b = 1;
+
c.b = 2;
+
};
+
expected.b = {
+
a = 1;
+
c = 2;
+
};
+
};
+
+
}
+10
checkmate/modules/tests/transpose_swap.nix
···
+
{ transpose, ... }:
+
{
+
+
flake.tests."test transpose swaps parent and child attrNames" = {
+
expr = transpose { a.b.c = 1; };
+
expected = {
+
b.a.c = 1;
+
};
+
};
+
}
+44
checkmate/modules/tests/without_flakes.nix
···
+
{ lib, targetLib, ... }:
+
{
+
+
flake.tests."test usage without flakes" =
+
let
+
flake-aspects-lib = import targetLib lib;
+
# first eval is like evaling the flake.
+
first = lib.evalModules {
+
modules = [
+
(flake-aspects-lib.new-scope "hello")
+
{
+
hello.aspects =
+
{ aspects, ... }:
+
{
+
a.b.c = [ "world" ];
+
a.includes = [ aspects.x ];
+
x.b =
+
{ lib, ... }:
+
{
+
c = lib.splitString " " "mundo cruel";
+
};
+
};
+
}
+
];
+
};
+
# second eval is like evaling its nixosConfiguration
+
second = lib.evalModules {
+
modules = [
+
{ options.c = lib.mkOption { type = lib.types.listOf lib.types.str; }; }
+
first.config.hello.modules.b.a
+
];
+
};
+
expr = lib.sort (a: b: a < b) second.config.c;
+
expected = [
+
"cruel"
+
"mundo"
+
"world"
+
];
+
in
+
{
+
inherit expr expected;
+
};
+
+
}