nixpkgs/pkgs/by-name/hi/hiawatha/test.nix
aleksana 571c71e6f7 treewide: migrate packages to pkgs/by-name, take 1
We are migrating packages that meet below requirements:

1. using `callPackage`
2. called path is a directory
3. overriding set is empty (`{ }`)
4. not containing path expressions other than relative path (to
makenixpkgs-vet happy)
5. not referenced by nix files outside of the directory, other
than`pkgs/top-level/all-packages.nix`
6. not referencing nix files outside of the directory
7. not referencing `default.nix` (since it's changed to `package.nix`)
8. `outPath` doesn't change after migration

The tool is here: https://github.com/Aleksanaa/by-name-migrate.
2024-11-09 20:04:51 +08:00

85 lines
1.8 KiB
Nix

{ lib
, stdenvNoCC
, hiawatha
, curl
, mbedtls
, enableTls
}:
stdenvNoCC.mkDerivation {
name = "hiawatha-test";
nativeBuildInputs = [
hiawatha
curl
] ++ lib.optional enableTls mbedtls;
env = {
inherit enableTls;
};
buildCommand = ''
cp -r --no-preserve=mode ${hiawatha}/etc/hiawatha config
sed "1i set TEST_DIR = $(pwd)" $serverConfigPath > config/hiawatha.conf
mkdir www
echo "it works" > www/index.html
if [ -n "$enableTls" ]; then
echo "Generating self-signed certificate"
gen_key type=ec filename=server.key
cert_write selfsign=1 issuer_key=server.key output_file=server.crt
cat server.crt server.key > config/server.crt
fi
echo "Checking server configuration"
hiawatha -c ./config -k
echo "Starting server"
hiawatha -c ./config
testUrl() {
echo "Testing $1"
curl --verbose --insecure --fail "$1" | tee response
grep -q "it works" response
}
testUrl http://127.0.0.1:8000
if [ -n "$enableTls" ]; then
testUrl https://127.0.0.1:8443
fi
touch $out
'';
serverConfig = ''
# By default the server uses read-only directories like /var/lib and /etc
WorkDirectory = TEST_DIR
PIDfile = TEST_DIR/hiawatha.pid
SystemLogfile = TEST_DIR/system.log
GarbageLogfile = TEST_DIR/garbage.log
ExploitLogfile = TEST_DIR/exploit.log
AccessLogfile = TEST_DIR/access.log
ErrorLogfile = TEST_DIR/error.log
Binding {
Interface = 127.0.0.1
Port = 8000
}
${lib.optionalString enableTls ''
Binding {
Interface = 127.0.0.1
Port = 8443
TLScertFile = TEST_DIR/config/server.crt
}
''}
Hostname = 127.0.0.1
WebsiteRoot = TEST_DIR/www
StartFile = index.html
'';
passAsFile = [ "serverConfig" ];
}