Skip to content

Commit

Permalink
Add overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
tfc authored and picnoir committed Dec 14, 2024
1 parent d6b5ec3 commit b9630e7
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 12 deletions.
38 changes: 38 additions & 0 deletions doc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,41 @@ $ ./result/bin/test-driver
```

on your CI.

## Using the Overlay

If you would like to use this testing library with your own nixpkgs, use our
overlay function.

The overlay function makes all linux distributions available under the attribute
`pkgs.testers.legacyDistros...`:

```nix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
nix-vm-test.url = "github:numtide/nix-vm-test";
};
outputs = { self, nixpkgs, nix-vm-test }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [
nix-vm-test.overlays.default
];
};
in
packages.x86_64-linux.mytest = pkgs.testers.legacyDistros.debian."13" {
sharedDirs.debDir = {
source = "${./.}";
target = "/mnt/debdir";
};
testScript = ''
vm.wait_for_unit("multi-user.target")
vm.succeed("apt-get -yq install /mnt/debdir/hello.deb")
'';
};
}
```
2 changes: 1 addition & 1 deletion fedora/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let
inherit (image) hash;
url = "https://download.fedoraproject.org/pub/fedora/linux/releases/${image.name}";
};
images = lib.mapAttrs (k: v: fetchImage v) imagesJSON.${system};
images = lib.mapAttrs (k: v: fetchImage v) (imagesJSON.${system} or {});
makeVmTestForImage = image: { testScript, sharedDirs, diskSize ? null, extraPathsToRegister ? [ ]}: generic.makeVmTest {
inherit system testScript sharedDirs;
image = prepareFedoraImage {
Expand Down
33 changes: 33 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};

outputs = { self, nixpkgs, ... }: rec {
lib.x86_64-linux = import ./lib.nix {
inherit nixpkgs;
outputs = { self, nixpkgs, flake-utils }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
overlays = [ self.overlays.default ];
localSystem = system;
};
in
{
lib.${system} = pkgs.testers.legacyDistros;

checks.${system} = import ./tests {
package = pkgs.testers.legacyDistros;
inherit pkgs system;
};

overlays.default = import ./overlay.nix;
};
checks.x86_64-linux = import ./tests { package = lib; pkgs = nixpkgs.legacyPackages.x86_64-linux; system = "x86_64-linux"; };
};
}
17 changes: 17 additions & 0 deletions overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
final: prev:

let
inherit (prev) system;
generic = import ./generic { inherit (prev) lib; pkgs = final; nixpkgs = prev.path; };
ubuntu = prev.callPackage ./ubuntu { inherit generic system; };
debian = prev.callPackage ./debian { inherit generic system; };
fedora = prev.callPackage ./fedora { inherit generic system; };
in

{
testers = prev.testers or { } // {
legacyDistros = {
inherit debian ubuntu fedora;
};
};
}
4 changes: 2 additions & 2 deletions tests/debian.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs, package, system }:
let
lib = package.${system};
lib = package;
multiUserTest = runner: (runner {
sharedDirs = {};
testScript = ''
Expand Down Expand Up @@ -49,4 +49,4 @@ in {
}).sandboxed;
} //
runTestOnEveryImage multiUserTest //
package.${system}.debian.images
package.debian.images
4 changes: 2 additions & 2 deletions tests/fedora.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs, package, system }:
let
lib = package.${system};
lib = package;
multiUserTest = runner: (runner {
sharedDirs = {};
testScript = ''
Expand Down Expand Up @@ -49,4 +49,4 @@ in {
}).sandboxed;
} //
runTestOnEveryImage multiUserTest //
package.${system}.fedora.images
package.fedora.images
4 changes: 2 additions & 2 deletions tests/ubuntu.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs, package, system }:

let
lib = package.${system};
lib = package;
multiUserTest = runner: (runner {
sharedDirs = {};
testScript = ''
Expand Down Expand Up @@ -50,5 +50,5 @@ in {
}).sandboxed;

}
// package.${system}.ubuntu.images
// package.ubuntu.images
// runTestOnEveryImage multiUserTest

0 comments on commit b9630e7

Please sign in to comment.