Unverified Commit 6779ff00 authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

nixos/glitchtip: fix sourcemap uploads, add stateDir option (#438957)

parents dc85fea6 6ef10ab0
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -58,6 +58,12 @@ in
        default = 8000;
      };

      stateDir = lib.mkOption {
        type = lib.types.path;
        description = "State directory of glitchtip.";
        default = "/var/lib/glitchtip";
      };

      settings = lib.mkOption {
        description = ''
          Configuration of GlitchTip. See <https://glitchtip.com/documentation/install#configuration> for more information.
@@ -189,6 +195,7 @@ in
          StateDirectory = "glitchtip";
          EnvironmentFile = cfg.environmentFiles;
          WorkingDirectory = "${pkg}/lib/glitchtip";
          BindPaths = [ "${cfg.stateDir}/uploads:${pkg}/lib/glitchtip/uploads" ];

          # hardening
          AmbientCapabilities = "";
@@ -220,6 +227,7 @@ in
            "@system-service"
            "~@privileged"
            "~@resources"
            "@chown"
          ];
          UMask = "0077";
        };
@@ -271,7 +279,6 @@ in

    users.users = lib.mkIf (cfg.user == "glitchtip") {
      glitchtip = {
        home = "/var/lib/glitchtip";
        group = cfg.group;
        extraGroups = lib.optionals cfg.redis.createLocally [ "redis-glitchtip" ];
        isSystemUser = true;
@@ -280,6 +287,8 @@ in

    users.groups = lib.mkIf (cfg.group == "glitchtip") { glitchtip = { }; };

    systemd.tmpfiles.settings.glitchtip."${cfg.stateDir}/uploads".d = { inherit (cfg) user group; };

    environment.systemPackages =
      let
        glitchtip-manage = pkgs.writeShellScriptBin "glitchtip-manage" ''
+69 −58
Original line number Diff line number Diff line
@@ -42,7 +42,9 @@ in
    ];
  };

  testScript = ''
  testScript =
    { nodes, ... }: # python
    ''
      import json
      import re
      import time
@@ -99,5 +101,14 @@ in
      assert len(resp) == 1
      assert resp[0]["title"] == "hello world"
      assert int(resp[0]["count"]) == 1

      # create api token
      csrf_token = machine.succeed(f"grep csrftoken {cookie_jar_path} | cut -f7").rstrip()
      resp = json.loads(machine.succeed(f"{curl} {origin_url}/api/0/api-tokens/ -s -H 'X-Csrftoken: {csrf_token}' -H 'Content-Type: application/json' -d '{{\"label\":\"token\",\"scopes\":[\"project:write\"]}}'"))
      token = resp["token"]

      # upload sourcemaps
      machine.succeed(f"sentry-cli --url {origin_url} --auth-token {token} sourcemaps upload --org main --project test ${nodes.machine.services.glitchtip.package.frontend}/*.map")
      assert machine.succeed("ls /var/lib/glitchtip/uploads/file_blobs/").strip()
    '';
}