mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-10-30 22:21:26 +00:00
76583ee81a
* Move `hostname` and `root` into a settings submodule with a freeform type, allowing users to also use options not known to the NixOS service. Compatibility with a warning for the renamed options is also trivial to achieve. * `port` stays where it is as we don't actually use the `port` option of spacecookie to set up the socket, but only to inform spacecookie about the port we have set in the `systemd.socket` file, this makes more sense. Additionally the configuration of the listening port and address change in the next spacecookie release — we can dodge this issue altogether by doing our own thing, but I'm interested to hear opinions on this. To ensure that this is not misconfigured, we add an assertion for the port option. * Add an assertion for `user` in settings which has no effect the way we are starting spacecookie as it wouldn't be able to call setuid. The message also explains how a specific user can be used with spacecookie if desired.
57 lines
1.8 KiB
Nix
57 lines
1.8 KiB
Nix
let
|
|
gopherRoot = "/tmp/gopher";
|
|
gopherHost = "gopherd";
|
|
gopherClient = "client";
|
|
fileContent = "Hello Gopher!\n";
|
|
fileName = "file.txt";
|
|
in
|
|
import ./make-test-python.nix ({...}: {
|
|
name = "spacecookie";
|
|
nodes = {
|
|
${gopherHost} = {
|
|
systemd.services.spacecookie = {
|
|
preStart = ''
|
|
mkdir -p ${gopherRoot}/directory
|
|
printf "%s" "${fileContent}" > ${gopherRoot}/${fileName}
|
|
'';
|
|
};
|
|
|
|
services.spacecookie = {
|
|
enable = true;
|
|
openFirewall = true;
|
|
settings = {
|
|
root = gopherRoot;
|
|
hostname = gopherHost;
|
|
};
|
|
};
|
|
};
|
|
|
|
${gopherClient} = {};
|
|
};
|
|
|
|
testScript = ''
|
|
start_all()
|
|
|
|
# with daemon type notify, the unit being started
|
|
# should also mean the port is open
|
|
${gopherHost}.wait_for_unit("spacecookie.service")
|
|
${gopherClient}.wait_for_unit("network.target")
|
|
|
|
fileResponse = ${gopherClient}.succeed("curl -f -s gopher://${gopherHost}/0/${fileName}")
|
|
|
|
# the file response should return our created file exactly
|
|
if not (fileResponse == "${builtins.replaceStrings [ "\n" ] [ "\\n" ] fileContent}"):
|
|
raise Exception("Unexpected file response")
|
|
|
|
# sanity check on the directory listing: we serve a directory and a file
|
|
# via gopher, so the directory listing should have exactly two entries,
|
|
# one with gopher file type 0 (file) and one with file type 1 (directory).
|
|
dirResponse = ${gopherClient}.succeed("curl -f -s gopher://${gopherHost}")
|
|
dirEntries = [l[0] for l in dirResponse.split("\n") if len(l) > 0]
|
|
dirEntries.sort()
|
|
|
|
if not (["0", "1"] == dirEntries):
|
|
raise Exception("Unexpected directory response")
|
|
'';
|
|
})
|