<commit_before>{ config, pkgs, lib, ... }:

with builtins;

let
  cfg = config.services.ekklesia.portal;

  defaultConfig = {

  };

  appConfigFile =
    pkgs.writeText "ekklesia-portal-config.json"
      (toJSON
        (lib.recursiveUpdate defaultConfig cfg.extraConfig));

  serveApp = import ../serve_app.nix {
    inherit appConfigFile;
    listen = "${cfg.address}:${toString cfg.port}";
    tmpdir = "/tmp";
  };

  staticFiles = import ../static_files.nix { };

  ekklesiaPortalConfig = pkgs.writeScriptBin "ekklesia-portal-config" ''
    systemctl cat ekklesia-portal.service | grep X-ConfigFile | cut -d"=" -f2
  '';

  ekklesiaPortalShowConfig = pkgs.writeScriptBin "ekklesia-portal-show-config" ''
    cat `${ekklesiaPortalConfig}/bin/ekklesia-portal-config`
  '';

in {
  options.services.ekklesia.portal = with lib; {

    enable = mkEnableOption "Enable the portal component of the Ekklesia e-democracy platform";

    user = mkOption {
      type = types.str;
      default = "ekklesia-portal";
      description = "User to run ekklesia-portal.";
    };

    group = mkOption {
      type = types.str;
      default = "ekklesia-portal";
      description = "Group to run ekklesia-portal.";
    };

    port = mkOption {
      type = types.int;
      default = 10000;
      description = "Port for gunicorn app server";
    };

    address = mkOption {
      type = types.str;
      default = "127.0.0.1";
      description = "Address for gunicorn app server";
    };

    extraConfig = mkOption {
      type = types.attrs;
      default = {};
      description = "Additional config options given as attribute set.";
    };

  };

  config = lib.mkIf cfg.enable {

    environment.systemPackages = [ ekklesiaPortalConfig ekklesiaPortalShowConfig ];

    users.users.ekklesia-portal = { };
    users.groups.ekklesia-portal = { };

    systemd.services.ekklesia-portal = {

      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

      serviceConfig = {
        User = cfg.user;
        Group = cfg.group;
        ExecStartPre = "${serveApp}/bin/migrate";
        ExecStart = "${serveApp}/bin/run";
        X-ConfigFile = appConfigFile;
      };

    };
<commit_msg>NixOS service: don't stop service on a unit change<commit_after>{ config, pkgs, lib, ... }:

with builtins;

let
  cfg = config.services.ekklesia.portal;

  defaultConfig = {

  };

  appConfigFile =
    pkgs.writeText "ekklesia-portal-config.json"
      (toJSON
        (lib.recursiveUpdate defaultConfig cfg.extraConfig));

  serveApp = import ../serve_app.nix {
    inherit appConfigFile;
    listen = "${cfg.address}:${toString cfg.port}";
    tmpdir = "/tmp";
  };

  staticFiles = import ../static_files.nix { };

  ekklesiaPortalConfig = pkgs.writeScriptBin "ekklesia-portal-config" ''
    systemctl cat ekklesia-portal.service | grep X-ConfigFile | cut -d"=" -f2
  '';

  ekklesiaPortalShowConfig = pkgs.writeScriptBin "ekklesia-portal-show-config" ''
    cat `${ekklesiaPortalConfig}/bin/ekklesia-portal-config`
  '';

in {
  options.services.ekklesia.portal = with lib; {

    enable = mkEnableOption "Enable the portal component of the Ekklesia e-democracy platform";

    user = mkOption {
      type = types.str;
      default = "ekklesia-portal";
      description = "User to run ekklesia-portal.";
    };

    group = mkOption {
      type = types.str;
      default = "ekklesia-portal";
      description = "Group to run ekklesia-portal.";
    };

    port = mkOption {
      type = types.int;
      default = 10000;
      description = "Port for gunicorn app server";
    };

    address = mkOption {
      type = types.str;
      default = "127.0.0.1";
      description = "Address for gunicorn app server";
    };

    extraConfig = mkOption {
      type = types.attrs;
      default = {};
      description = "Additional config options given as attribute set.";
    };

  };

  config = lib.mkIf cfg.enable {

    environment.systemPackages = [ ekklesiaPortalConfig ekklesiaPortalShowConfig ];

    users.users.ekklesia-portal = { };
    users.groups.ekklesia-portal = { };

    systemd.services.ekklesia-portal = {

      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      stopIfChanged = false;

      serviceConfig = {
        User = cfg.user;
        Group = cfg.group;
        ExecStartPre = "${serveApp}/bin/migrate";
        ExecStart = "${serveApp}/bin/run";
        X-ConfigFile = appConfigFile;
      };

    };

{'fraction_non_alphanumeric': 0.12880143112701253, 'fraction_numerical': 0.005366726296958855, 'mean_word_length': 2.5613057324840764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '320555', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1456, 'n_words': 298}