1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-19 07:59:24 +03:00
nixpkgs/nixos/modules/services/web-servers/static-web-server.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

83 lines
2.7 KiB
Nix

{
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 ''Static Web Server'';
listen = lib.mkOption {
default = "[::]:8787";
type = lib.types.str;
description = ''
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 = ''
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 = ''
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 ];
}