Merge pull request #226977 from mac-chaffee/sws-module
This commit is contained in:
commit
a86a7dafdf
|
@ -9841,6 +9841,11 @@
|
||||||
fingerprint = "1147 43F1 E707 6F3E 6F4B 2C96 B9A8 B592 F126 F8E8";
|
fingerprint = "1147 43F1 E707 6F3E 6F4B 2C96 B9A8 B592 F126 F8E8";
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
mac-chaffee = {
|
||||||
|
name = "Mac Chaffee";
|
||||||
|
github = "mac-chaffee";
|
||||||
|
githubId = 7581860;
|
||||||
|
};
|
||||||
maddiethecafebabe = {
|
maddiethecafebabe = {
|
||||||
email = "maddie@cafebabe.date";
|
email = "maddie@cafebabe.date";
|
||||||
github = "maddiethecafebabe";
|
github = "maddiethecafebabe";
|
||||||
|
|
|
@ -1282,6 +1282,7 @@
|
||||||
./services/web-servers/pomerium.nix
|
./services/web-servers/pomerium.nix
|
||||||
./services/web-servers/rustus.nix
|
./services/web-servers/rustus.nix
|
||||||
./services/web-servers/stargazer.nix
|
./services/web-servers/stargazer.nix
|
||||||
|
./services/web-servers/static-web-server.nix
|
||||||
./services/web-servers/tomcat.nix
|
./services/web-servers/tomcat.nix
|
||||||
./services/web-servers/traefik.nix
|
./services/web-servers/traefik.nix
|
||||||
./services/web-servers/trafficserver/default.nix
|
./services/web-servers/trafficserver/default.nix
|
||||||
|
|
68
nixos/modules/services/web-servers/static-web-server.nix
Normal file
68
nixos/modules/services/web-servers/static-web-server.nix
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.services.static-web-server;
|
||||||
|
toml = pkgs.formats.toml {};
|
||||||
|
configFilePath = toml.generate "config.toml" cfg.configuration;
|
||||||
|
in {
|
||||||
|
options = {
|
||||||
|
services.static-web-server = {
|
||||||
|
enable = lib.mkEnableOption (lib.mdDoc ''Static Web Server'');
|
||||||
|
listen = lib.mkOption {
|
||||||
|
default = "[::]:8787";
|
||||||
|
type = lib.types.str;
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The "ListenStream" used in static-web-server.socket.
|
||||||
|
This is equivalent to SWS's "host" and "port" options.
|
||||||
|
See here for specific syntax: <https://www.freedesktop.org/software/systemd/man/systemd.socket.html#ListenStream=>
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
root = lib.mkOption {
|
||||||
|
type = lib.types.path;
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The location of files for SWS to serve. Equivalent to SWS's "root" config value.
|
||||||
|
NOTE: This folder must exist before starting SWS.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
configuration = lib.mkOption {
|
||||||
|
default = { };
|
||||||
|
type = toml.type;
|
||||||
|
example = {
|
||||||
|
general = { log-level = "error"; directory-listing = true; };
|
||||||
|
};
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
Configuration for Static Web Server. See
|
||||||
|
<https://static-web-server.net/configuration/config-file/>.
|
||||||
|
NOTE: Don't set "host", "port", or "root" here. They will be ignored.
|
||||||
|
Use the top-level "listen" and "root" options instead.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
environment.systemPackages = [ pkgs.static-web-server ];
|
||||||
|
systemd.packages = [ pkgs.static-web-server ];
|
||||||
|
# Have to set wantedBy since systemd.packages ignores the "Install" section
|
||||||
|
systemd.sockets.static-web-server = {
|
||||||
|
wantedBy = [ "sockets.target" ];
|
||||||
|
# Start with empty string to reset upstream option
|
||||||
|
listenStreams = [ "" cfg.listen ];
|
||||||
|
};
|
||||||
|
systemd.services.static-web-server = {
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
# Remove upstream sample environment file; use config.toml exclusively
|
||||||
|
EnvironmentFile = [ "" ];
|
||||||
|
ExecStart = [ "" "${pkgs.static-web-server}/bin/static-web-server --fd 0 --config-file ${configFilePath} --root ${cfg.root}" ];
|
||||||
|
# Supplementary groups doesn't work unless we create the group ourselves
|
||||||
|
SupplementaryGroups = [ "" ];
|
||||||
|
# If the user is serving files from their home dir, override ProtectHome to allow that
|
||||||
|
ProtectHome = if lib.hasPrefix "/home" cfg.root then "tmpfs" else "true";
|
||||||
|
BindReadOnlyPaths = cfg.root;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
meta.maintainers = with lib.maintainers; [ mac-chaffee ];
|
||||||
|
}
|
|
@ -709,6 +709,7 @@ in {
|
||||||
sssd-ldap = handleTestOn ["x86_64-linux"] ./sssd-ldap.nix {};
|
sssd-ldap = handleTestOn ["x86_64-linux"] ./sssd-ldap.nix {};
|
||||||
stargazer = runTest ./web-servers/stargazer.nix;
|
stargazer = runTest ./web-servers/stargazer.nix;
|
||||||
starship = handleTest ./starship.nix {};
|
starship = handleTest ./starship.nix {};
|
||||||
|
static-web-server = handleTest ./web-servers/static-web-server.nix {};
|
||||||
step-ca = handleTestOn ["x86_64-linux"] ./step-ca.nix {};
|
step-ca = handleTestOn ["x86_64-linux"] ./step-ca.nix {};
|
||||||
stratis = handleTest ./stratis {};
|
stratis = handleTest ./stratis {};
|
||||||
strongswan-swanctl = handleTest ./strongswan-swanctl.nix {};
|
strongswan-swanctl = handleTest ./strongswan-swanctl.nix {};
|
||||||
|
|
32
nixos/tests/web-servers/static-web-server.nix
Normal file
32
nixos/tests/web-servers/static-web-server.nix
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import ../make-test-python.nix ({ pkgs, lib, ... } : {
|
||||||
|
name = "static-web-server";
|
||||||
|
meta = {
|
||||||
|
maintainers = with lib.maintainers; [ mac-chaffee ];
|
||||||
|
};
|
||||||
|
|
||||||
|
nodes.machine = { pkgs, ... }: {
|
||||||
|
services.static-web-server = {
|
||||||
|
enable = true;
|
||||||
|
listen = "[::]:8080";
|
||||||
|
root = toString (pkgs.writeTextDir "nixos-test.html" ''
|
||||||
|
<h1>Hello NixOS!</h1>
|
||||||
|
'');
|
||||||
|
configuration = {
|
||||||
|
general = { directory-listing = true; };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = ''
|
||||||
|
machine.start()
|
||||||
|
machine.wait_for_unit("static-web-server.socket")
|
||||||
|
machine.wait_for_open_port(8080)
|
||||||
|
# We don't use wait_until_succeeds() because we're testing socket
|
||||||
|
# activation which better work on the first request
|
||||||
|
response = machine.succeed("curl -fsS localhost:8080")
|
||||||
|
assert "nixos-test.html" in response, "The directory listing page did not include a link to our nixos-test.html file"
|
||||||
|
response = machine.succeed("curl -fsS localhost:8080/nixos-test.html")
|
||||||
|
assert "Hello NixOS!" in response
|
||||||
|
machine.wait_for_unit("static-web-server.service")
|
||||||
|
'';
|
||||||
|
})
|
|
@ -1,4 +1,4 @@
|
||||||
{ lib, rustPlatform, fetchFromGitHub, stdenv, darwin }:
|
{ lib, rustPlatform, fetchFromGitHub, stdenv, darwin, nixosTests }:
|
||||||
|
|
||||||
rustPlatform.buildRustPackage rec {
|
rustPlatform.buildRustPackage rec {
|
||||||
pname = "static-web-server";
|
pname = "static-web-server";
|
||||||
|
@ -24,6 +24,13 @@ rustPlatform.buildRustPackage rec {
|
||||||
"--skip=handle_precondition"
|
"--skip=handle_precondition"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
# Need to copy in the systemd units for systemd.packages to discover them
|
||||||
|
postInstall = ''
|
||||||
|
install -Dm444 -t $out/lib/systemd/system/ systemd/static-web-server.{service,socket}
|
||||||
|
'';
|
||||||
|
|
||||||
|
passthru.tests = { inherit (nixosTests) static-web-server; };
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
description = "An asynchronus web server for static files-serving";
|
description = "An asynchronus web server for static files-serving";
|
||||||
homepage = "https://static-web-server.net/";
|
homepage = "https://static-web-server.net/";
|
||||||
|
|
Loading…
Reference in a new issue