Unverified Commit cc536e33 authored by jopejoe1's avatar jopejoe1 Committed by GitHub
Browse files

onlykey: migrate to buildNpmPackage (#440092)

parents bc239561 70c8650a
Loading
Loading
Loading
Loading
+59 −60
Original line number Diff line number Diff line
{
  buildNpmPackage,
  fetchFromGitHub,
  fetchpatch2,
  lib,
  node_webkit,
  pkgs,
  copyDesktopItems,
  makeDesktopItem,
  stdenv,
  writeShellScript,
  wrapGAppsHook3,
  nix-update-script,
  nwjs,
}:

let
  # parse the version from package.json
  version =
    let
      packageJson = lib.importJSON ./package.json;
      splits = builtins.split "^.*#v(.*)$" (builtins.getAttr "onlykey" (builtins.head packageJson));
      matches = builtins.elemAt splits 1;
      elem = builtins.head matches;
    in
    elem;
buildNpmPackage (finalAttrs: {
  pname = "onlykey";
  version = "5.5.0";

  # this must be updated anytime this package is updated.
  onlykeyPkg = "onlykey-git+https://github.com/trustcrypto/OnlyKey-App.git#v${version}";
  src = fetchFromGitHub {
    owner = "trustcrypto";
    repo = "OnlyKey-App";
    tag = "v${finalAttrs.version}";
    hash = "sha256-8MSdr+ghCBPeGp63Yi1T+gyEwXOEUW3vqi9CrCmozrw=";
  };

  # define a shortcut to get to onlykey.
  onlykey = self."${onlykeyPkg}";
  patches = [
    # Provides package-lock.json
    (fetchpatch2 {
      url = "https://github.com/trustcrypto/OnlyKey-App/commit/b8918cec80f5feda50c24a0aec3d6fb914ea8481.patch";
      hash = "sha256-ULMZI7fo5SJGrfCRqZzZVoGOTDQ8q/NG/uXMjNkQ+qk=";
    })
  ];

  super = import ./onlykey.nix {
    inherit pkgs;
    inherit (stdenv.hostPlatform) system;
  desktopItem = makeDesktopItem {
    name = "onlykey";
    exec = "onlykey";
    icon = "onlykey";
    desktopName = "OnlyKey";
    comment = finalAttrs.meta.description;
    categories = [
      "Utility"
    ];
    terminal = false;
  };

  self = super // {
    "${onlykeyPkg}" = super."${onlykeyPkg}".override (attrs: {
  npmDepsHash = "sha256-DpjB95KEHfAc4GBxY40uUjlN7ifBMUncufVTmTXqDo8=";

  # when installing packages, nw tries to download nwjs in its postInstall
  # script. There are currently no other postInstall scripts, so this
  # should not break other things.
      npmFlags = attrs.npmFlags or "" + " --ignore-scripts";
  npmFlags = [ "--ignore-scripts" ];

      # this package requires to be built in order to become runnable.
      postInstall = ''
        cd $out/lib/node_modules/${attrs.packageName}
        npm run build
      '';
    });
  };

  script = writeShellScript "${onlykey.packageName}-starter-${onlykey.version}" ''
    ${node_webkit}/bin/nw ${onlykey}/lib/node_modules/${onlykey.packageName}/build
  '';
in
stdenv.mkDerivation {
  pname = "${onlykey.packageName}";
  inherit (onlykey) version;
  dontUnpack = true;
  nativeBuildInputs = [
    wrapGAppsHook3
    copyDesktopItems
  ];
  desktopItems = [
    (makeDesktopItem {
      name = onlykey.packageName;
      exec = script;
      icon = "${onlykey}/lib/node_modules/${onlykey.packageName}/resources/onlykey_logo_128.png";
      desktopName = onlykey.packageName;
      genericName = onlykey.packageName;
    })
  ];
  installPhase = ''
    runHook preInstall

    mkdir -p $out/bin
    ln -s ${script} $out/bin/onlykey
    mkdir -p "$out/share"
    cp -r build "$out/share/onlykey"

    ln -s "${finalAttrs.desktopItem}/share/applications" "$out/share/applications"

    mkdir -p "$out/share/icons/hicolor/128x128/apps"
    install -D resources/onlykey_logo_128.png "$out/share/icons/hicolor/128x128/apps/onlykey.png"

    makeWrapper ${nwjs}/bin/nw "$out/bin/onlykey" \
      --add-flags "$out/share/onlykey"

    runHook postInstall
  '';
}

  passthru = {
    updateScript = nix-update-script { };
  };

  meta = {
    description = "Setup and configure OnlyKey";
    homepage = "https://github.com/trustcrypto/OnlyKey-App";
    changelog = "https://github.com/trustcrypto/OnlyKey-App/releases/tag/v${finalAttrs.version}";
    license = lib.licenses.asl20;
    mainProgram = "onlykey";
  };
})
+0 −5
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p nodePackages.node2nix

# XXX: --development is given here because we need access to gulp in order to build OnlyKey.
exec node2nix --nodejs-18 --development -i package.json -c onlykey.nix -e ../../../development/node-packages/node-env.nix --no-copy-node-env
+0 −6952

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −33
Original line number Diff line number Diff line
# This file has been generated by node2nix 1.11.1. Do not edit!

{
  pkgs ? import <nixpkgs> {
    inherit system;
  },
  system ? builtins.currentSystem,
  nodejs ? pkgs.nodejs_20,
}:

let
  nodeEnv = import ../../../development/node-packages/node-env.nix {
    inherit (pkgs)
      stdenv
      lib
      runCommand
      writeTextFile
      writeShellScript
      ;
    inherit pkgs nodejs;
    libtool = if pkgs.stdenv.hostPlatform.isDarwin then pkgs.cctools or pkgs.darwin.cctools else null;
  };
in
import ./node-packages.nix {
  inherit (pkgs)
    fetchurl
    nix-gitignore
    stdenv
    lib
    fetchgit
    ;
  inherit nodeEnv;
}
+0 −3
Original line number Diff line number Diff line
[
  {"onlykey": "git+https://github.com/trustcrypto/OnlyKey-App.git#v5.5.0"}
]
Loading