2023-07-15 17:15:38 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
literalExpression
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
2024-01-02 11:29:13 +00:00
|
|
|
mkPackageOption
|
2023-07-15 17:15:38 +00: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 = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "legit git web frontend";
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "legit-web" { };
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "legit";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "User account under which legit runs.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "legit";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Group account under which legit runs.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
default = { };
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00: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;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Directory where legit will scan for repositories.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
readme = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Readme files to look for.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
mainBranch = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "main" "master" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Main branch to look for.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
ignore = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Repositories to ignore.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
options.dirs = {
|
|
|
|
templates = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "${pkgs.legit-web}/lib/legit/templates";
|
|
|
|
defaultText = literalExpression ''"''${pkgs.legit-web}/lib/legit/templates"'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Directories where template files are located.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
static = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "${pkgs.legit-web}/lib/legit/static";
|
|
|
|
defaultText = literalExpression ''"''${pkgs.legit-web}/lib/legit/static"'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Directories where static files are located.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
options.meta = {
|
|
|
|
title = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "legit";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Website title.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
description = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "git frontend";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Website description.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
options.server = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Server name.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Host address.";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 5555;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Legit port.";
|
2023-07-15 17:15:38 +00: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";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|