summary refs log tree commit diff
path: root/pkgs/servers/pufferpanel/default.nix
blob: f1079a03fcece77f132e77c78757e0fbf88e29b3 (plain) (blame)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{ lib
, fetchFromGitHub
, fetchpatch
, applyPatches
, buildGoModule
, buildNpmPackage
, makeWrapper
, go-swag
, nixosTests
}:

buildGoModule rec {
  pname = "pufferpanel";
  version = "2.6.7";

  src = applyPatches {
    src = fetchFromGitHub {
      owner = "PufferPanel";
      repo = "PufferPanel";
      rev = "v${version}";
      hash = "sha256-ay9NNcK+6QFobe/rwtZF8USl0vMbDZBg5z57fjA5VLw=";
    };
    patches = [
      # Bump sha1cd package, otherwise i686-linux fails to build.
      ./bump-sha1cd.patch

      # Seems to be an anti-feature. Startup is the only place where user/group is
      # hardcoded and checked.
      #
      # There is no technical reason PufferPanel cannot run as a different user,
      # especially for simple commands like `pufferpanel version`.
      ./disable-group-checks.patch

      # Some tests do not have network requests stubbed :(
      ./skip-network-tests.patch
    ];
  };

  ldflags = [
    "-s"
    "-w"
    "-X=github.com/pufferpanel/pufferpanel/v2.Hash=none"
    "-X=github.com/pufferpanel/pufferpanel/v2.Version=${version}-nixpkgs"
  ];

  frontend = buildNpmPackage {
    pname = "pufferpanel-frontend";
    inherit version;

    src = "${src}/client";

    npmDepsHash = "sha256-oWFXtV/dxzHv3sfIi01l1lHE5tcJgpVq87XgS6Iy62g=";

    NODE_OPTIONS = "--openssl-legacy-provider";
    npmBuildFlags = [ "--" "--dest=${placeholder "out"}" ];
    dontNpmInstall = true;
  };

  nativeBuildInputs = [ makeWrapper go-swag ];

  vendorHash = "sha256-Esfk7SvqiWeiobXSI+4wYVEH9yVkB+rO7bxUQ5TzvG4=";
  proxyVendor = true;

  # Generate code for Swagger documentation endpoints (see web/swagger/docs.go).
  # Note that GOROOT embedded in go-swag is empty by default since it is built
  # with -trimpath (see https://go.dev/cl/399214). It looks like go-swag skips
  # file paths that start with $GOROOT, thus all files when it is empty.
  preBuild = ''
    GOROOT=''${GOROOT-$(go env GOROOT)} swag init --output web/swagger --generalInfo web/loader.go
  '';

  installPhase = ''
    runHook preInstall

    # Set up directory structure similar to the official PufferPanel releases.
    mkdir -p $out/share/pufferpanel
    cp "$GOPATH"/bin/cmd $out/share/pufferpanel/pufferpanel
    cp -r $frontend $out/share/pufferpanel/www
    cp -r $src/assets/email $out/share/pufferpanel/email
    cp web/swagger/swagger.{json,yaml} $out/share/pufferpanel

    # Wrap the binary with the path to the external files, but allow setting
    # custom paths if needed.
    makeWrapper $out/share/pufferpanel/pufferpanel $out/bin/pufferpanel \
      --set-default GIN_MODE release \
      --set-default PUFFER_PANEL_EMAIL_TEMPLATES $out/share/pufferpanel/email/emails.json \
      --set-default PUFFER_PANEL_WEB_FILES $out/share/pufferpanel/www

    runHook postInstall
  '';

  passthru.tests = {
    inherit (nixosTests) pufferpanel;
  };

  meta = with lib; {
    description = "A free, open source game management panel";
    homepage = "https://www.pufferpanel.com/";
    license = with licenses; [ asl20 ];
    maintainers = with maintainers; [ ckie tie ];
  };
}