Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixosTests: WIP integration tests #14

Merged
merged 22 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
19c0120
nixosTests: init
SomeoneSerge Aug 1, 2024
97a78ba
flake.nix: add .#checks
SomeoneSerge Aug 8, 2024
9dfb301
nixosTests: drop unused args
sinanmohd Aug 11, 2024
5152832
nixosTests/all-tests: always import dsl
sinanmohd Aug 11, 2024
89ac91f
nixosTests/sunset: init
sinanmohd Aug 11, 2024
f6f682a
flake/devShell: add nixfmt-rfc-style
sinanmohd Aug 11, 2024
1465c27
nixosTests: runCommand.inputDerivatino: explain why
SomeoneSerge Aug 11, 2024
f09e70d
nixosTests/sunset-unbuilt-0: init
sinanmohd Aug 12, 2024
b31a759
nixosTests/dsl: change option names
sinanmohd Aug 12, 2024
ca46628
nixosTests/dsl: make sure cache value is valid
sinanmohd Aug 12, 2024
5ad39d3
nixosTests/dsl: verify choseBuilds
sinanmohd Aug 13, 2024
e1cedc0
nixosTests: drop nixos-lib
sinanmohd Aug 13, 2024
b79e15c
nixosTests/dsl: verify assertChosen
sinanmohd Aug 14, 2024
b2e4a13
nixosTests/dsl: clean up
sinanmohd Aug 14, 2024
6b11c34
nixosTests/dsl: verify assertNeeded
sinanmohd Aug 14, 2024
57caa68
nixosTests/sunset-unbuilt-0: set assertNeeded
sinanmohd Aug 14, 2024
e183d71
nixosTests: make options hierarchical
SomeoneSerge Aug 15, 2024
b895c64
nixosTests: sunset-unbuilt: rename to avoid confusion
SomeoneSerge Aug 16, 2024
b5e749c
nixosTests: sunset-unbuilt: refactor the dag
SomeoneSerge Aug 16, 2024
ac770cf
nixosTests/dsl: clean up
sinanmohd Aug 16, 2024
838f0e7
nixosTests: refactor the way common template and per-instance args ar…
SomeoneSerge Aug 16, 2024
59b1063
nixosTests: allow extending testScript without overriding it
SomeoneSerge Aug 16, 2024
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
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)"
26 changes: 26 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

inputsFrom = [ self.packages.${system}.evanix ];
packages = with pkgs; [
nixfmt-rfc-style
gdb
ccls
valgrind
Expand Down Expand Up @@ -63,5 +64,30 @@
});
}
);
legacyPackages = forAllSystems (
{ pkgs, ... }:
{
nixosTests = import ./nixos/tests/all-tests.nix pkgs;
sinanmohd marked this conversation as resolved.
Show resolved Hide resolved
}
);
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.
118 changes: 118 additions & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
pkgs:

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
abcInputs = {
u = { };
v = { };
};
in
{
a = {
request = true;
inputs = abcInputs;
};
b = {
request = true;
inputs = abcInputs;
};
c = {
request = true;
inputs = abcInputs;
};

d = {
request = true;
inputs.w = { };
};
e = {
request = true;
inputs.x = { };
};

u = { };
v = { };
w = { };
x = { };
};
};
in
builtins.mapAttrs
(
name: value:
pkgs.testers.runNixOSTest (
sinanmohd marked this conversation as resolved.
Show resolved Hide resolved
{
inherit name;
testScript = ''
start_all()
substituter.wait_for_unit("nix-serve.service")
builder.succeed("dag-test")
'';
}
// value
// {
imports = value.imports ++ [ dsl ];
}
)
)
{
diamond-unbuilt-0 = {
imports = [
{
dag.needBuilds = 0;
dag.needDownloads = 0;
}
diamond
];
};
diamond-unbuilt-2 = {
imports = [
{
dag.nodes.a.cache = "remote";
dag.nodes.b.cache = "remote";
dag.nodes.d.request = true;
dag.needBuilds = 2;
dag.needDownloads = 2;
SomeoneSerge marked this conversation as resolved.
Show resolved Hide resolved
}
diamond
];
};
diamond-unbuilt-4 = {
imports = [
{
dag.nodes.d.request = true;
dag.needBuilds = 4;
dag.needDownloads = 0;
}
diamond
];
};

sunset-unbuilt-0 = {
imports = [
{
# all builds
dag.needBuilds = 9;
# all builds allowed
dag.allowBuilds = 5;
# chosen builds requested
dag.choseBuilds = 3;
}
sunset
];
};
}
Loading