Skip to content

Commit

Permalink
Merge pull request #14 from sinanmohd/feat/nixosTests
Browse files Browse the repository at this point in the history
nixosTests: WIP integration tests
  • Loading branch information
sinanmohd authored Aug 17, 2024
2 parents 316b86f + 59b1063 commit 37d813b
Show file tree
Hide file tree
Showing 6 changed files with 544 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v7
- name: Build some-pkgs
run: nix run github:Mic92/nix-fast-build -- --skip-cached --no-nom --flake ".#packages"
nix-flake-check:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v13
- uses: DeterminateSystems/magic-nix-cache-action@v7
- name: Build the checks
run: nix run github:Mic92/nix-fast-build -- --skip-cached --no-nom --flake ".#checks.$(nix eval --raw --impure --expr builtins.currentSystem)"
28 changes: 28 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@

inputsFrom = [ self.packages.${system}.evanix ];
packages = with pkgs; [
nixfmt-rfc-style
gdb
ccls
valgrind
clang-tools # clang-format
flamegraph
nix-eval-jobs
linuxKernel.packages.linux_6_6.perf
hyperfine
nix-eval-jobs
];

shellHook = ''
Expand Down Expand Up @@ -69,5 +72,30 @@
});
}
);
legacyPackages = forAllSystems (
{ pkgs, ... }:
{
nixosTests = pkgs.callPackage ./nixos/tests/all-tests.nix { };
}
);
checks = forAllSystems (
{ system, pkgs, ... }:
let
inherit (pkgs.lib)
filterAttrs
isDerivation
mapAttrs'
nameValuePair
pipe
;
in
pipe self.legacyPackages.${system}.nixosTests [
(filterAttrs (_: p: isDerivation p))
(mapAttrs' (name: nameValuePair "nixosTests-${name}"))
]
// {
inherit (self.packages.${system}) evanix evanix-py;
}
);
};
}
14 changes: 14 additions & 0 deletions nixos/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Synthetic integration tests for "real" nix stores and substituters

Usage
---

```console
$ nix build .#nixosTests.diamond-unbuilt-2
```

Development
---

The `.#nixosTests` attrset is defined in [`all-tests.nix`](./all-tests.nix).
In [dsl.nix](./dsl.nix) we define the helper for generating NixOS tests from DAGs.
129 changes: 129 additions & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{ lib, testers }:

let
dsl = ./dsl.nix;
diamond.dag = {
nodes.a = { };
nodes.b.inputs.a = { }; # b->a
nodes.c.inputs.a = { }; # c->a
nodes.d.inputs.b = { }; # d->b
nodes.d.inputs.c = { }; # d->c
};

# A B C D E
# \ | / | |
# U V W X
sunset.dag = {
nodes =
let
goalDependsOn = inputs: {
goal = true;
inputs = lib.genAttrs inputs (_: { });
};
in
{
a = goalDependsOn [ "u" "v" ];
b = goalDependsOn [ "u" "v" ];
c = goalDependsOn [ "u" "v" ];
d = goalDependsOn [ "w" ];
e = goalDependsOn [ "x" ];

u = { };
v = { };
w = { };
x = { };
};
};
in
builtins.mapAttrs
(
name: value:
testers.runNixOSTest (
{
inherit name;
imports = value.imports ++ [ dsl ];
testScript =
value.testScriptPre or ""
+ ''
start_all()
substituter.wait_for_unit("nix-serve.service")
builder.succeed("dag-test")
''
+ value.testScriptPost or "";
}
// builtins.removeAttrs value [
"imports"
"testScriptPre"
"testScriptPost"
]
)
)
{
diamond-unbuilt-0 = {
imports = [
{
dag.test.unconstrained.builds = 0;
dag.test.unconstrained.downloads = 0;
}
diamond
];
};
diamond-unbuilt-2 = {
imports = [
{
dag.nodes.a.cache = "remote";
dag.nodes.b.cache = "remote";
dag.nodes.d.goal = true;
dag.test.unconstrained.builds = 2;
dag.test.unconstrained.downloads = 2;
}
diamond
];
};
diamond-unbuilt-4 = {
imports = [
{
dag.nodes.d.goal = true;
dag.test.unconstrained.builds = 4;
dag.test.unconstrained.downloads = 0;
}
diamond
];
};

sunset-unbuilt-9 = {
imports = [
{
dag = {
test.unconstrained.builds = 9;

constraints.builds = 5;
test.constrained.builds = 3;

nodes = {
a.test = {
chosen = true;
needed = true;
};
b.test = {
chosen = true;
needed = true;
};
c.test = {
chosen = true;
needed = true;
};

d.test.needed = true;
e.test.needed = true;
u.test.needed = true;
v.test.needed = true;
w.test.needed = true;
x.test.needed = true;
};
};
}
sunset
];
};
}
Loading

0 comments on commit 37d813b

Please sign in to comment.