infrastructure

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

forgejo.nix (1414B)


      1 {
      2   config,
      3   lib,
      4   ...
      5 }:
      6 
      7 let
      8   cfg = config.services.local.forgejo;
      9 in
     10 {
     11   options.services.local.forgejo = {
     12     enable = lib.mkEnableOption "Forgejo git server";
     13 
     14     domain = lib.mkOption {
     15       type = lib.types.str;
     16       description = "Domain for Forgejo";
     17     };
     18 
     19     httpPort = lib.mkOption {
     20       type = lib.types.port;
     21       default = 3001;
     22       description = "HTTP port for Forgejo";
     23     };
     24 
     25     lfsEnable = lib.mkOption {
     26       type = lib.types.bool;
     27       default = true;
     28       description = "Enable Git LFS";
     29     };
     30 
     31     disableRegistration = lib.mkOption {
     32       type = lib.types.bool;
     33       default = true;
     34       description = "Disable public registration";
     35     };
     36   };
     37 
     38   config = lib.mkIf cfg.enable {
     39     services.forgejo = {
     40       enable = true;
     41       database.type = "postgres";
     42       lfs.enable = cfg.lfsEnable;
     43       settings = {
     44         server = {
     45           DOMAIN = cfg.domain;
     46           ROOT_URL = "https://${cfg.domain}/";
     47           HTTP_PORT = cfg.httpPort;
     48         };
     49         service = {
     50           DISABLE_REGISTRATION = cfg.disableRegistration;
     51         };
     52         session = {
     53           COOKIE_SECURE = true;
     54         };
     55       };
     56     };
     57 
     58     services.nginx.virtualHosts.${cfg.domain} = {
     59       enableACME = true;
     60       forceSSL = true;
     61       locations."/" = {
     62         proxyPass = "http://127.0.0.1:${toString cfg.httpPort}";
     63         proxyWebsockets = true;
     64       };
     65     };
     66   };
     67 }