mirror of
https://github.com/donovanglover/nix-config.git
synced 2024-11-22 08:14:00 +01:00
meta: Begin writing tests in Nix
Now that I've figured out how to dynamically import modules and use those modules as outputs, the next step is to ensure that these modules work as intended when being used by end users. NixOS offers a built-in testing solution that enables us to conveniently spin up virtual machines with a given configuration, then verify their correctness through python scripting. The lib.nix file in particular is based on Jörg Thalheim's very useful blog post that explains how to use the built-in testing functionality with Nix flakes, which isn't covered in official documentation. See: https://blog.thalheim.io/2023/01/08/how-to-use-nixos-testing-framework-with-flakes/
This commit is contained in:
parent
1d165d3068
commit
95b10ec3ef
10
flake.nix
10
flake.nix
@ -25,6 +25,11 @@
|
|||||||
inherit (nixpkgs.lib) nixosSystem;
|
inherit (nixpkgs.lib) nixosSystem;
|
||||||
inherit (nixpkgs.legacyPackages.x86_64-linux) nixpkgs-fmt callPackage;
|
inherit (nixpkgs.legacyPackages.x86_64-linux) nixpkgs-fmt callPackage;
|
||||||
|
|
||||||
|
checkArgs = {
|
||||||
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||||
|
inherit self;
|
||||||
|
};
|
||||||
|
|
||||||
flakeOutputs = [ "overlays" "nixosModules" "homeManagerModules" "packages" ];
|
flakeOutputs = [ "overlays" "nixosModules" "homeManagerModules" "packages" ];
|
||||||
flakeDirectories = [ "overlays" "modules" "home" "packages" ];
|
flakeDirectories = [ "overlays" "modules" "home" "packages" ];
|
||||||
packageDirectory = "packages";
|
packageDirectory = "packages";
|
||||||
@ -55,6 +60,11 @@
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
checks.x86_64-linux = {
|
||||||
|
hyprland = import ./tests/hyprland.nix checkArgs;
|
||||||
|
neovim = import ./tests/neovim.nix checkArgs;
|
||||||
|
};
|
||||||
} //
|
} //
|
||||||
(builtins.listToAttrs
|
(builtins.listToAttrs
|
||||||
(builtins.map
|
(builtins.map
|
||||||
|
15
tests/hyprland.nix
Normal file
15
tests/hyprland.nix
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# TODO: Write test to ensure that Hyprland starts with basic config
|
||||||
|
(import ./lib.nix) {
|
||||||
|
name = "hyprland";
|
||||||
|
|
||||||
|
nodes.machine = { self, pkgs, ... }: {
|
||||||
|
imports = with self.nixosModules; [
|
||||||
|
hyprland
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = /* python */ ''
|
||||||
|
output = machine.succeed("echo 'Hello world'")
|
||||||
|
assert "Hello world" in output
|
||||||
|
'';
|
||||||
|
}
|
13
tests/lib.nix
Normal file
13
tests/lib.nix
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
test: { pkgs, self }:
|
||||||
|
let
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
nixos-lib = import (pkgs.path + "/nixos/lib") { };
|
||||||
|
in
|
||||||
|
(nixos-lib.runTest {
|
||||||
|
hostPkgs = pkgs;
|
||||||
|
defaults.documentation.enable = lib.mkDefault false;
|
||||||
|
node.specialArgs = {
|
||||||
|
inherit self;
|
||||||
|
};
|
||||||
|
imports = [ test ];
|
||||||
|
}).config.result
|
15
tests/neovim.nix
Normal file
15
tests/neovim.nix
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# TODO: Ensure that neovim config works without errors on startup
|
||||||
|
(import ./lib.nix) {
|
||||||
|
name = "neovim";
|
||||||
|
|
||||||
|
nodes.machine = { self, pkgs, ... }: {
|
||||||
|
imports = with self.nixosModules; [
|
||||||
|
neovim
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = /* python */ ''
|
||||||
|
output = machine.succeed("echo 'Hello world'")
|
||||||
|
assert "Hello world" in output
|
||||||
|
'';
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user