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
527 changes: 414 additions & 113 deletions README.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions checkmate.nix
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
{ lib, ... }:
{
imports =
let
files = builtins.readDir ./checkmate/tests;
names = builtins.attrNames files;
nixes = builtins.filter (lib.hasSuffix ".nix") names;
tests = map (file: "${./checkmate/tests}/${file}") nixes;
in
tests;
}
205 changes: 205 additions & 0 deletions checkmate/tests/aspect-functor.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{ lib, inputs, ... }:
let
__functor = import "${inputs.target}/nix/aspect-functor.nix" lib;

tail = out: { includes = lib.drop 1 out.includes; };

aspect-example = {
inherit __functor;
nixos.foo = 99;
includes = [
{ nixos.static = 100; }
(
{ host, ... }:
{
nixos.host = host;
}
)
(
{ host, user }:
{
nixos.host-user = [
host
user
];
}
)
(
{ user, ... }:
{
nixos.user = user;
}
)
(
{ user, ... }@ctx:
if builtins.length (builtins.attrNames ctx) == 1 then
{
nixos.user-only = user;
}
else
{ }
)
(
{ home, ... }:
{
nixos.home = home;
}
)
(_any: {
nixos.any = 10;
})
];
};

flake.tests."test provider function must be returned as is" =
let
provider =
{ class, aspect-chain }:
[
class
aspect-chain
];
x = tail (
{
inherit __functor;
includes = [ provider ];
}
{ }
);
in
{
expr = (builtins.elemAt x.includes 0) {
class = "foo";
aspect-chain = [ ];
};
expected = [
"foo"
[ ]
];
};

flake.tests."test functor first element is foo" = {
expr =
let
first = builtins.elemAt (aspect-example { }).includes 0;
in
(first {
class = "nixos";
aspect-chain = [ ];
});
expected = {
nixos.foo = 99;
};
};

flake.tests."test functor applied with empty attrs" = {
expr = tail (aspect-example { });
expected = {
includes = [
{ nixos.static = 100; }
{ } # host
{ } # host user
{ } # user
{ } # user-only
{ } # home
{ nixos.any = 10; }
];
};
};

flake.tests."test functor applied with host only" = {
expr = tail (aspect-example {
host = 2;
});
expected = {
includes = [
{ nixos.static = 100; }
{ nixos.host = 2; } # host
{ } # host user
{ } # user
{ } # user-only
{ } # home
{ nixos.any = 10; }
];
};
};

flake.tests."test functor applied with home only" = {
expr = tail (aspect-example {
home = 2;
});
expected = {
includes = [
{ nixos.static = 100; }
{ } # host
{ } # host user
{ } # user
{ } # user-only
{ nixos.home = 2; } # home
{ nixos.any = 10; }
];
};
};

flake.tests."test functor applied with home and unknown" = {
expr = tail (aspect-example {
home = 2;
unknown = 1;
});
expected = {
includes = [
{ nixos.static = 100; }
{ } # host
{ } # host user
{ } # user
{ } # user-only
{ } # home
{ nixos.any = 10; }
];
};
};

flake.tests."test functor applied with user only" = {
expr = tail (aspect-example {
user = 2;
});
expected = {
includes = [
{ nixos.static = 100; }
{ } # host
{ } # host user
{ nixos.user = 2; } # user
{ nixos.user-only = 2; } # user-only
{ } # home
{ nixos.any = 10; }
];
};
};

flake.tests."test functor applied with user and host" = {
expr = tail (aspect-example {
user = 2;
host = 1;
});
expected = {
includes = [
{ nixos.static = 100; }
{ } # host
{
nixos.host-user = [
1
2
];
} # host user
{ } # user
{ } # user-only
{ } # home
{ nixos.any = 10; }
];
};
};

in
{
inherit flake;
}
66 changes: 66 additions & 0 deletions checkmate/tests/function_can_take.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{ lib, inputs, ... }:
let
takes = import "${inputs.target}/nix/fn-can-take.nix" lib;

flake.tests."test function with no named arguments can take anything" = {
expr = takes { } (x: x);
expected = true;
};

flake.tests."test function called with non attrs" = {
expr = takes 22 ({ host }: [ host ]);
expected = false;
};

flake.tests."test function missing required attr" = {
expr = takes { } ({ host }: [ host ]);
expected = false;
};

flake.tests."test function satisfied required attr" = {
expr = takes {
host = 1;
} ({ host, ... }: [ host ]);
expected = true;
};

flake.tests."test function missing second required attr" = {
expr =
takes
{
host = 1;
}
(
{ host, user }:
[
host
user
]
);
expected = false;
};

flake.tests."test function optional second attr" = {
expr =
takes
{
host = 1;
foo = 9;
}
(
{
host,
user ? 0,
}:
[
host
user
]
);
expected = false;
};

in
{
inherit flake;
}
2 changes: 1 addition & 1 deletion modules/_types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
...
}:
let
den = config.den;
inherit (config) den;

hostsOption = lib.mkOption {
description = "den hosts definition";
Expand Down
64 changes: 6 additions & 58 deletions modules/aspects/defaults.nix
Original file line number Diff line number Diff line change
@@ -1,60 +1,8 @@
{ inputs, lib, ... }:
let

default.host =
{ aspect, ... }:
{
name = "<default.host>";
provides.host.includes = [ ];
provides.host.__functor =
callbacks:
{ host }:
{
name = "<${aspect.name}.host.*>";
includes = [ aspect ] ++ (map (f: f { inherit host; }) callbacks.includes);
};
};

default.user =
{ aspect, ... }:
{
name = "<default.user>";
provides.user.includes = [ ];
provides.user.__functor =
callbacks:
{ host, user }:
{
name = "<${aspect.name}.user.*>";
includes = [ aspect ] ++ (map (f: f { inherit host user; }) callbacks.includes);
};
};

default.home =
{ aspect, ... }:
{
name = "<default.home>";
provides.home.includes = [ ];
provides.home.__functor =
callbacks:
{ home }:
{
name = "<${aspect.name}.home.*>";
includes = [ aspect ] ++ (map (f: f { inherit home; }) callbacks.includes);
};
};

aspect-option =
description:
lib.mkOption {
inherit description;
default = { };
type = (inputs.flake-aspects.lib lib).types.aspectSubmodule;
};

in
# creates den.default aspect
{ lib, den, ... }:
{
config.den = { inherit default; };
options.den.default.host = aspect-option "host defaults";
options.den.default.user = aspect-option "host user defaults";
options.den.default.home = aspect-option "standalone home defaults";
config.den.default.__functor = den.lib.parametric true;
options.den.default = lib.mkOption {
type = den.lib.aspects.types.aspectSubmodule;
};
}
Loading