-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcors-proxy.nix
60 lines (60 loc) · 1.63 KB
/
cors-proxy.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{ config, lib, pkgs, ... }:
let
cors-proxy = pkgs.buildNpmPackage {
name = "cors-proxy";
npmDepsHash = "sha256-csWMR3cHLrdePxaOMnwWeohP/zYaNaHuA+myx43zERg=";
src = pkgs.fetchFromGitHub {
owner = "isomorphic-git";
repo = "cors-proxy";
# v2.7.1
rev = "1b1c91e71d946544d97ccc7cf0ac62b859e03311";
sha256 = "sha256-YnSYVeq9Irc2QexvSuE7wq+hi8OGZhlLE2JlbRqzMi4=";
};
dontNpmBuild = true;
postInstall = ''
wrapProgram $out/bin/@isomorphic-git/cors-proxy --prefix PATH : ${pkgs.lib.makeBinPath (with pkgs; [ nodejs-18_x ])}
'';
};
cfg = config.services.cors-proxy;
in {
options.services.cors-proxy = with lib; {
enable = mkEnableOption "Enable @isomorphic-git/cors-proxy";
package = mkOption {
type = types.package;
default = cors-proxy;
};
port = mkOption {
type = types.int;
default = 9999;
description = ''
The port to listen to.
'';
};
allowOrigin = mkOption {
type = types.str;
default = "*";
description = ''
The value for the 'Access-Control-Allow-Origin' CORS header.
'';
};
};
config = lib.mkIf cfg.enable {
systemd.services.ligo-webide-cors-proxy = {
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
script = ''
${cfg.package}/bin/@isomorphic-git/cors-proxy start
'';
startLimitBurst = 5;
startLimitIntervalSec = 300;
serviceConfig = {
Restart = "on-failure";
RestartSec = 10;
};
environment = {
PORT = toString cfg.port;
ALLOW_ORIGIN = cfg.allowOrigin;
};
};
};
}