20 cfg = config.services.legit;
22 yaml = pkgs.formats.yaml { };
23 configFile = yaml.generate "legit.yaml" cfg.settings;
25 defaultStateDir = "/var/lib/legit";
26 defaultStaticDir = "${cfg.settings.repo.scanPath}/static";
27 defaultTemplatesDir = "${cfg.settings.repo.scanPath}/templates";
30 options.services.legit = {
31 enable = mkEnableOption "legit git web frontend";
33 package = mkPackageOption pkgs "legit-web" { };
38 description = "User account under which legit runs.";
44 description = "Group account under which legit runs.";
50 The primary legit configuration. See the
51 [sample configuration](https://github.com/icyphox/legit/blob/master/config.yaml)
54 type = types.submodule {
58 default = defaultStateDir;
59 description = "Directory where legit will scan for repositories.";
62 type = types.listOf types.str;
64 description = "Readme files to look for.";
66 mainBranch = mkOption {
67 type = types.listOf types.str;
72 description = "Main branch to look for.";
75 type = types.listOf types.str;
77 description = "Repositories to ignore.";
81 templates = mkOption {
83 default = "${pkgs.legit-web}/lib/legit/templates";
84 defaultText = literalExpression ''"''${pkgs.legit-web}/lib/legit/templates"'';
85 description = "Directories where template files are located.";
89 default = "${pkgs.legit-web}/lib/legit/static";
90 defaultText = literalExpression ''"''${pkgs.legit-web}/lib/legit/static"'';
91 description = "Directories where static files are located.";
98 description = "Website title.";
100 description = mkOption {
102 default = "git frontend";
103 description = "Website description.";
109 default = "localhost";
110 description = "Server name.";
114 default = "127.0.0.1";
115 description = "Host address.";
120 description = "Legit port.";
127 config = mkIf cfg.enable {
128 users.groups = optionalAttrs (cfg.group == "legit") {
129 "${cfg.group}" = { };
132 users.users = optionalAttrs (cfg.user == "legit") {
139 systemd.services.legit = {
140 description = "legit git frontend";
142 after = [ "network.target" ];
143 wantedBy = [ "multi-user.target" ];
144 restartTriggers = [ configFile ];
150 ExecStart = "${cfg.package}/bin/legit -config ${configFile}";
153 WorkingDirectory = cfg.settings.repo.scanPath;
156 ++ optional (cfg.settings.repo.scanPath == defaultStateDir) "legit"
157 ++ optional (cfg.settings.dirs.static == defaultStaticDir) "legit/static"
158 ++ optional (cfg.settings.dirs.templates == defaultTemplatesDir) "legit/templates";
161 CapabilityBoundingSet = [ "" ];
162 DeviceAllow = [ "" ];
163 LockPersonality = true;
164 MemoryDenyWriteExecute = true;
165 NoNewPrivileges = true;
166 PrivateDevices = true;
171 ProtectControlGroups = true;
173 ProtectHostname = true;
174 ProtectKernelLogs = true;
175 ProtectKernelModules = true;
176 ProtectKernelTunables = true;
177 ProtectProc = "invisible";
178 ProtectSystem = "strict";
179 ReadWritePaths = cfg.settings.repo.scanPath;
181 RestrictAddressFamilies = [
185 RestrictNamespaces = true;
186 RestrictRealtime = true;
187 RestrictSUIDSGID = true;
188 SystemCallArchitectures = "native";