about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/networking/ratman/default.nix
blob: 65f32add0f6bf2a7cb3dc5c3ec0d57d4bee05000 (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
{ lib
, fetchFromGitLab
, installShellFiles
, libsodium
, pkg-config
, protobuf
, rustPlatform
, fetchYarnDeps
, prefetch-yarn-deps
, stdenv
, yarn
, nodejs
}:

rustPlatform.buildRustPackage rec {
  pname = "ratman";
  version = "0.4.0";

  src = fetchFromGitLab {
    domain = "git.irde.st";
    owner = "we";
    repo = "irdest";
    rev = "${pname}-${version}";
    sha256 = "sha256-ZZ7idZ67xvQFmQJqIFU/l77YU+yDQOqNthX5NR/l4k8=";
  };

  cargoSha256 = "Nsux0QblBtzlhLEgfKYvkQrOz8+oVd2pqT3CL8TnQEc=";

  nativeBuildInputs = [ protobuf pkg-config installShellFiles ];

  cargoBuildFlags = [ "--all-features" "-p" "ratman" ];
  cargoTestFlags = cargoBuildFlags;

  buildInputs = [ libsodium ];

  postInstall = ''
    installManPage docs/man/ratmand.1
  '';

  SODIUM_USE_PKG_CONFIG = 1;

  dashboard = stdenv.mkDerivation rec {
    pname = "ratman-dashboard";
    inherit version src;
    sourceRoot = "${src.name}/ratman/dashboard";

    yarnDeps = fetchYarnDeps {
      yarnLock = src + "/ratman/dashboard/yarn.lock";
      sha256 = "sha256-pWjKL41r/bTvWv+5qCgCFVL9+o64BiV2/ISdLeKEOqE=";
    };

    nativeBuildInputs = [ yarn nodejs prefetch-yarn-deps ];

    outputs = [ "out" "dist" ];

    buildPhase = ''
      # Yarn writes temporary files to $HOME. Copied from mkYarnModules.
      export HOME=$NIX_BUILD_TOP/yarn_home

      # Make yarn install packages from our offline cache, not the registry
      yarn config --offline set yarn-offline-mirror ${yarnDeps}

      # Fixup "resolved"-entries in yarn.lock to match our offline cache
      fixup-yarn-lock yarn.lock

      yarn install --offline --frozen-lockfile --ignore-scripts --no-progress --non-interactive

      patchShebangs node_modules/

      # Build into `./dist/`, suppress formatting.
      yarn --offline build | cat
    '';

    installPhase = ''
      cp -R . $out

      mv $out/dist $dist
      ln -s $dist $out/dist
    '';
  };

  prePatch = ''
    cp -r ${dashboard.dist} ratman/dashboard/dist
  '';

  meta = with lib; {
    description = "A modular decentralised peer-to-peer packet router and associated tools";
    homepage = "https://git.irde.st/we/irdest";
    platforms = platforms.unix;
    license = licenses.agpl3Only;
    maintainers = with maintainers; [ spacekookie yuka ];
  };
}