nixpkgs/nixos/modules/services/networking/legit.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

182 lines
5.3 KiB
Nix
Raw Normal View History

2023-05-24 14:47:50 +02:00
{ config, lib, pkgs, ... }:
let
inherit (lib)
literalExpression
mkEnableOption
mkIf
mkOption
mkPackageOption
2023-05-24 14:47:50 +02:00
optionalAttrs
optional
types;
cfg = config.services.legit;
yaml = pkgs.formats.yaml { };
configFile = yaml.generate "legit.yaml" cfg.settings;
defaultStateDir = "/var/lib/legit";
defaultStaticDir = "${cfg.settings.repo.scanPath}/static";
defaultTemplatesDir = "${cfg.settings.repo.scanPath}/templates";
in
{
options.services.legit = {
enable = mkEnableOption "legit git web frontend";
2023-05-24 14:47:50 +02:00
package = mkPackageOption pkgs "legit-web" { };
2023-05-24 14:47:50 +02:00
user = mkOption {
type = types.str;
default = "legit";
description = "User account under which legit runs.";
2023-05-24 14:47:50 +02:00
};
group = mkOption {
type = types.str;
default = "legit";
description = "Group account under which legit runs.";
2023-05-24 14:47:50 +02:00
};
settings = mkOption {
default = { };
description = ''
2023-05-24 14:47:50 +02:00
The primary legit configuration. See the
[sample configuration](https://github.com/icyphox/legit/blob/master/config.yaml)
for possible values.
'';
type = types.submodule {
options.repo = {
scanPath = mkOption {
type = types.path;
default = defaultStateDir;
description = "Directory where legit will scan for repositories.";
2023-05-24 14:47:50 +02:00
};
readme = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Readme files to look for.";
2023-05-24 14:47:50 +02:00
};
mainBranch = mkOption {
type = types.listOf types.str;
default = [ "main" "master" ];
description = "Main branch to look for.";
2023-05-24 14:47:50 +02:00
};
ignore = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Repositories to ignore.";
2023-05-24 14:47:50 +02:00
};
};
options.dirs = {
templates = mkOption {
type = types.path;
default = "${pkgs.legit-web}/lib/legit/templates";
defaultText = literalExpression ''"''${pkgs.legit-web}/lib/legit/templates"'';
description = "Directories where template files are located.";
2023-05-24 14:47:50 +02:00
};
static = mkOption {
type = types.path;
default = "${pkgs.legit-web}/lib/legit/static";
defaultText = literalExpression ''"''${pkgs.legit-web}/lib/legit/static"'';
description = "Directories where static files are located.";
2023-05-24 14:47:50 +02:00
};
};
options.meta = {
title = mkOption {
type = types.str;
default = "legit";
description = "Website title.";
2023-05-24 14:47:50 +02:00
};
description = mkOption {
type = types.str;
default = "git frontend";
description = "Website description.";
2023-05-24 14:47:50 +02:00
};
};
options.server = {
name = mkOption {
type = types.str;
default = "localhost";
description = "Server name.";
2023-05-24 14:47:50 +02:00
};
host = mkOption {
type = types.str;
default = "127.0.0.1";
description = "Host address.";
2023-05-24 14:47:50 +02:00
};
port = mkOption {
type = types.port;
default = 5555;
description = "Legit port.";
2023-05-24 14:47:50 +02:00
};
};
};
};
};
config = mkIf cfg.enable {
users.groups = optionalAttrs (cfg.group == "legit") {
"${cfg.group}" = { };
};
users.users = optionalAttrs (cfg.user == "legit") {
"${cfg.user}" = {
group = cfg.group;
isSystemUser = true;
};
};
systemd.services.legit = {
description = "legit git frontend";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
restartTriggers = [ configFile ];
serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
ExecStart = "${cfg.package}/bin/legit -config ${configFile}";
Restart = "always";
WorkingDirectory = cfg.settings.repo.scanPath;
StateDirectory = [ ] ++
optional (cfg.settings.repo.scanPath == defaultStateDir) "legit" ++
optional (cfg.settings.dirs.static == defaultStaticDir) "legit/static" ++
optional (cfg.settings.dirs.templates == defaultTemplatesDir) "legit/templates";
# Hardening
CapabilityBoundingSet = [ "" ];
DeviceAllow = [ "" ];
LockPersonality = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateTmp = true;
PrivateUsers = true;
ProcSubset = "pid";
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
ProtectSystem = "strict";
ReadWritePaths = cfg.settings.repo.scanPath;
RemoveIPC = true;
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
SystemCallFilter = [ "@system-service" "~@privileged" ];
UMask = "0077";
};
};
};
}