1 { config, lib, pkgs, ... }:
14 cfg = config.services.legit;
16 yaml = pkgs.formats.yaml { };
17 configFile = yaml.generate "legit.yaml" cfg.settings;
19 defaultStateDir = "/var/lib/legit";
20 defaultStaticDir = "${cfg.settings.repo.scanPath}/static";
21 defaultTemplatesDir = "${cfg.settings.repo.scanPath}/templates";
24 options.services.legit = {
25 enable = mkEnableOption "legit git web frontend";
27 package = mkPackageOption pkgs "legit-web" { };
32 description = "User account under which legit runs.";
38 description = "Group account under which legit runs.";
44 The primary legit configuration. See the
45 [sample configuration](https://github.com/icyphox/legit/blob/master/config.yaml)
48 type = types.submodule {
52 default = defaultStateDir;
53 description = "Directory where legit will scan for repositories.";
56 type = types.listOf types.str;
58 description = "Readme files to look for.";
60 mainBranch = mkOption {
61 type = types.listOf types.str;
62 default = [ "main" "master" ];
63 description = "Main branch to look for.";
66 type = types.listOf types.str;
68 description = "Repositories to ignore.";
72 templates = mkOption {
74 default = "${pkgs.legit-web}/lib/legit/templates";
75 defaultText = literalExpression ''"''${pkgs.legit-web}/lib/legit/templates"'';
76 description = "Directories where template files are located.";
80 default = "${pkgs.legit-web}/lib/legit/static";
81 defaultText = literalExpression ''"''${pkgs.legit-web}/lib/legit/static"'';
82 description = "Directories where static files are located.";
89 description = "Website title.";
91 description = mkOption {
93 default = "git frontend";
94 description = "Website description.";
100 default = "localhost";
101 description = "Server name.";
105 default = "127.0.0.1";
106 description = "Host address.";
111 description = "Legit port.";
118 config = mkIf cfg.enable {
119 users.groups = optionalAttrs (cfg.group == "legit") {
120 "${cfg.group}" = { };
123 users.users = optionalAttrs (cfg.user == "legit") {
130 systemd.services.legit = {
131 description = "legit git frontend";
133 after = [ "network.target" ];
134 wantedBy = [ "multi-user.target" ];
135 restartTriggers = [ configFile ];
141 ExecStart = "${cfg.package}/bin/legit -config ${configFile}";
144 WorkingDirectory = cfg.settings.repo.scanPath;
145 StateDirectory = [ ] ++
146 optional (cfg.settings.repo.scanPath == defaultStateDir) "legit" ++
147 optional (cfg.settings.dirs.static == defaultStaticDir) "legit/static" ++
148 optional (cfg.settings.dirs.templates == defaultTemplatesDir) "legit/templates";
151 CapabilityBoundingSet = [ "" ];
152 DeviceAllow = [ "" ];
153 LockPersonality = true;
154 MemoryDenyWriteExecute = true;
155 NoNewPrivileges = true;
156 PrivateDevices = true;
161 ProtectControlGroups = true;
163 ProtectHostname = true;
164 ProtectKernelLogs = true;
165 ProtectKernelModules = true;
166 ProtectKernelTunables = true;
167 ProtectProc = "invisible";
168 ProtectSystem = "strict";
169 ReadWritePaths = cfg.settings.repo.scanPath;
171 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
172 RestrictNamespaces = true;
173 RestrictRealtime = true;
174 RestrictSUIDSGID = true;
175 SystemCallArchitectures = "native";
176 SystemCallFilter = [ "@system-service" "~@privileged" ];