about summary refs log tree commit diff
path: root/pkgs/applications/networking/instant-messengers/element/keytar/default.nix
blob: d43894e08239afbe6bd23c80e7ddb802a3c3cbcd (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
{ lib, stdenv, fetchFromGitHub, nodejs, python3, removeReferencesTo
, pkg-config, libsecret, xcbuild, Security, AppKit, fetchNpmDeps, npmHooks }:

let
  pinData = lib.importJSON ./pin.json;

in stdenv.mkDerivation rec {
  pname = "keytar";
  inherit (pinData) version;

  src = fetchFromGitHub {
    owner = "atom";
    repo = "node-keytar";
    rev = "v${version}";
    hash = pinData.srcHash;
  };

  nativeBuildInputs = [
    nodejs python3 pkg-config
    npmHooks.npmConfigHook
  ]
    ++ lib.optional  stdenv.isDarwin xcbuild;

  buildInputs = lib.optionals (!stdenv.isDarwin) [ libsecret ]
    ++ lib.optionals stdenv.isDarwin [ Security AppKit ];

  npmDeps = fetchNpmDeps {
    inherit src;
    hash = pinData.npmHash;
  };

  doCheck = false;

  postPatch = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
    pkg-config() { "''${PKG_CONFIG}" "$@"; }
    export -f pkg-config
  '';

  # https://nodejs.org/api/os.html#osarch
  npmFlagsArray = [ "--arch=${if stdenv.hostPlatform.parsed.cpu.name == "i686" then "ia32"
                             else if stdenv.hostPlatform.parsed.cpu.name == "x86_64" then "x64"
                             else if stdenv.hostPlatform.parsed.cpu.name == "aarch64" then "arm64"
                             else stdenv.hostPlatform.parsed.cpu.name}" ];

  installPhase = ''
    runHook preInstall
    shopt -s extglob
    rm -rf node_modules
    mkdir -p $out
    cp -r ./!(build) $out
    install -D -t $out/build/Release build/Release/keytar.node
    ${removeReferencesTo}/bin/remove-references-to -t ${stdenv.cc.cc} $out/build/Release/keytar.node
    runHook postInstall
  '';

  disallowedReferences = [ stdenv.cc.cc ];
}