| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- {
- config,
- lib,
- pkgs,
- ...
- }:
- let
- cfg = config.services.gogs;
- iniFormat = pkgs.formats.ini { };
- configFile = iniFormat.generate "gogs.ini" cfg.settings;
- in
- {
- options.services.gogs = {
- enable = lib.mkEnableOption "Gogs Git service";
- package = lib.mkPackageOption pkgs "gogs" { };
- user = lib.mkOption {
- type = lib.types.str;
- default = "gogs";
- description = "User account under which Gogs runs.";
- };
- group = lib.mkOption {
- type = lib.types.str;
- default = "gogs";
- description = "Group under which Gogs runs.";
- };
- stateDir = lib.mkOption {
- type = lib.types.str;
- default = "/var/lib/gogs";
- description = "Persistent data directory.";
- };
- environmentFile = lib.mkOption {
- type = lib.types.nullOr lib.types.path;
- default = null;
- description = ''
- File containing environment variables to pass to the Gogs service,
- formatted as VARIABLE=VALUE per line. Values set here are merged into
- the service's environment and can be used to pass secrets (e.g.
- database passwords) without putting them in the Nix store.
- '';
- };
- settings = lib.mkOption {
- type = iniFormat.type;
- default = { };
- example = lib.literalExpression ''
- {
- server = {
- DOMAIN = "git.example.com";
- ROOT_URL = "https://git.example.com/";
- HTTP_PORT = 3000;
- };
- database = {
- TYPE = "sqlite3";
- PATH = "/var/lib/gogs/data/gogs.db";
- };
- }
- '';
- description = ''
- Settings written to app.ini.
- See:
- https://gogs.io/docs/advanced/configuration_cheat_sheet
- '';
- };
- };
- config = lib.mkIf cfg.enable {
- users.users.${cfg.user} = {
- isSystemUser = true;
- group = cfg.group;
- home = cfg.stateDir;
- createHome = true;
- };
- users.groups.${cfg.group} = { };
- systemd.tmpfiles.rules = [
- "d ${cfg.stateDir} 0750 ${cfg.user} ${cfg.group} -"
- "d ${cfg.stateDir}/repositories 0750 ${cfg.user} ${cfg.group} -"
- "d ${cfg.stateDir}/data 0750 ${cfg.user} ${cfg.group} -"
- "d ${cfg.stateDir}/log 0750 ${cfg.user} ${cfg.group} -"
- ];
- systemd.services.gogs = {
- description = "Gogs Git Service";
- after = [ "network.target" ];
- wantedBy = [ "multi-user.target" ];
- serviceConfig = {
- Type = "simple";
- User = cfg.user;
- Group = cfg.group;
- WorkingDirectory = cfg.stateDir;
- ExecStart = "${lib.getExe cfg.package} web --config ${configFile}";
- Restart = "on-failure";
- EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
- NoNewPrivileges = true;
- PrivateTmp = true;
- ProtectSystem = "strict";
- ProtectHome = true;
- ReadWritePaths = [
- cfg.stateDir
- ];
- };
- };
- };
- }
|