forked from extern/nixos-wiki-infra
add nixos test
This commit is contained in:
parent
7ec347b5c5
commit
1e67e0badb
15
checks/flake-module.nix
Normal file
15
checks/flake-module.nix
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{ self, ... }: {
|
||||||
|
perSystem =
|
||||||
|
{ pkgs
|
||||||
|
, ...
|
||||||
|
}: {
|
||||||
|
checks =
|
||||||
|
let
|
||||||
|
# this gives us a reference to our flake but also all flake inputs
|
||||||
|
checkArgs = { inherit self pkgs; };
|
||||||
|
in
|
||||||
|
{
|
||||||
|
test = import ./test.nix checkArgs;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
20
checks/lib.nix
Normal file
20
checks/lib.nix
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# tests/lib.nix
|
||||||
|
# The first argument to this function is the test module itself
|
||||||
|
test:
|
||||||
|
# These arguments are provided by `flake.nix` on import, see checkArgs
|
||||||
|
{ pkgs, self }:
|
||||||
|
let
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
# this imports the nixos library that contains our testing framework
|
||||||
|
nixos-lib = import (pkgs.path + "/nixos/lib") { };
|
||||||
|
in
|
||||||
|
(nixos-lib.runTest {
|
||||||
|
hostPkgs = pkgs;
|
||||||
|
# This speeds up the evaluation by skipping evaluating documentation (optional)
|
||||||
|
defaults.documentation.enable = lib.mkDefault false;
|
||||||
|
# This makes `self` available in the NixOS configuration of our virtual machines.
|
||||||
|
# This is useful for referencing modules or packages from your own flake
|
||||||
|
# as well as importing from other flakes.
|
||||||
|
node.specialArgs = { inherit self; };
|
||||||
|
imports = [ test ];
|
||||||
|
}).config.result
|
35
checks/test.nix
Normal file
35
checks/test.nix
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
(import ./lib.nix) {
|
||||||
|
name = "nixos-wiki";
|
||||||
|
nodes = {
|
||||||
|
# `self` here is set by using specialArgs in `lib.nix`
|
||||||
|
wiki = { self, pkgs, config, ... }: {
|
||||||
|
imports = [
|
||||||
|
self.nixosModules.nixos-wiki
|
||||||
|
];
|
||||||
|
security.acme.defaults.email = "admin@example.com";
|
||||||
|
services.nixos-wiki = {
|
||||||
|
hostname = "nixos-wiki.example.com";
|
||||||
|
adminPasswordFile = pkgs.writeText "adminPasswordFile" "Creation-Fabric-Untrimmed3";
|
||||||
|
githubClientId = "Iv1.95ed182c83df1d22";
|
||||||
|
githubClientSecretFile = pkgs.writeText "githubClientSecretFile" "secret";
|
||||||
|
emergencyContact = "nixos-wiki@thalheim.io";
|
||||||
|
passwordSender = "nixos-wiki@thalheim.io";
|
||||||
|
noReplyAddress = "nixos-wiki-no-reply@thalheim.io";
|
||||||
|
};
|
||||||
|
services.nginx.virtualHosts.${config.services.mediawiki.nginx.hostName} = {
|
||||||
|
enableACME = false;
|
||||||
|
forceSSL = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
# This is the test code that will check if our service is running correctly:
|
||||||
|
testScript = ''
|
||||||
|
start_all()
|
||||||
|
|
||||||
|
machine.wait_for_unit("phpfpm-mediawiki.service")
|
||||||
|
machine.wait_for_unit("nginx.service")
|
||||||
|
|
||||||
|
page = machine.succeed("curl -vL http://localhost/")
|
||||||
|
assert "MediaWiki has been installed" in page
|
||||||
|
'';
|
||||||
|
}
|
@ -34,6 +34,7 @@
|
|||||||
inputs.treefmt-nix.flakeModule
|
inputs.treefmt-nix.flakeModule
|
||||||
./targets/flake-module.nix
|
./targets/flake-module.nix
|
||||||
./modules/flake-module.nix
|
./modules/flake-module.nix
|
||||||
|
./checks/flake-module.nix
|
||||||
];
|
];
|
||||||
perSystem = { config, pkgs, ... }: {
|
perSystem = { config, pkgs, ... }: {
|
||||||
treefmt = {
|
treefmt = {
|
||||||
|
Loading…
Reference in New Issue
Block a user