at 23.11-beta 74 lines 2.0 kB view raw
1{ lib 2, node_webkit 3, pkgs 4, copyDesktopItems 5, makeDesktopItem 6, stdenv 7, writeShellScript 8, wrapGAppsHook 9}: 10 11let 12 # parse the version from package.json 13 version = 14 let 15 packageJson = lib.importJSON ./package.json; 16 splits = builtins.split "^.*#v(.*)$" (builtins.getAttr "onlykey" (builtins.head packageJson)); 17 matches = builtins.elemAt splits 1; 18 elem = builtins.head matches; 19 in 20 elem; 21 22 # this must be updated anytime this package is updated. 23 onlykeyPkg = "onlykey-git+https://github.com/trustcrypto/OnlyKey-App.git#v${version}"; 24 25 # define a shortcut to get to onlykey. 26 onlykey = self."${onlykeyPkg}"; 27 28 super = import ./onlykey.nix { 29 inherit pkgs; 30 inherit (stdenv.hostPlatform) system; 31 }; 32 33 self = super // { 34 "${onlykeyPkg}" = super."${onlykeyPkg}".override (attrs: { 35 # when installing packages, nw tries to download nwjs in its postInstall 36 # script. There are currently no other postInstall scripts, so this 37 # should not break other things. 38 npmFlags = attrs.npmFlags or "" + " --ignore-scripts"; 39 40 # this package requires to be built in order to become runnable. 41 postInstall = '' 42 cd $out/lib/node_modules/${attrs.packageName} 43 npm run build 44 ''; 45 }); 46 }; 47 48 script = writeShellScript "${onlykey.packageName}-starter-${onlykey.version}" '' 49 ${node_webkit}/bin/nw ${onlykey}/lib/node_modules/${onlykey.packageName}/build 50 ''; 51in 52stdenv.mkDerivation { 53 pname = "${onlykey.packageName}"; 54 inherit (onlykey) version; 55 dontUnpack = true; 56 nativeBuildInputs = [ wrapGAppsHook copyDesktopItems ]; 57 desktopItems = [ 58 (makeDesktopItem { 59 name = onlykey.packageName; 60 exec = script; 61 icon = "${onlykey}/lib/node_modules/${onlykey.packageName}/resources/onlykey_logo_128.png"; 62 desktopName = onlykey.packageName; 63 genericName = onlykey.packageName; 64 }) 65 ]; 66 installPhase = '' 67 runHook preInstall 68 69 mkdir -p $out/bin 70 ln -s ${script} $out/bin/onlykey 71 72 runHook postInstall 73 ''; 74}