nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 105 lines 2.7 kB view raw
1{ 2 lib, 3 stdenv, 4 buildNpmPackage, 5 electron_36, 6 fetchFromGitHub, 7 jq, 8 makeDesktopItem, 9}: 10 11let 12 electron = electron_36; 13 description = "Visualizer for neural network, deep learning and machine learning models"; 14 icon = "netron"; 15 16in 17buildNpmPackage (finalAttrs: { 18 pname = "netron"; 19 version = "8.3.9"; 20 21 src = fetchFromGitHub { 22 owner = "lutzroeder"; 23 repo = "netron"; 24 tag = "v${finalAttrs.version}"; 25 hash = "sha256-4AnbhdZVkPhpzNxmjhRNcUTiWrxXNWqVrUxR8pO+ULo="; 26 }; 27 28 npmDepsHash = "sha256-71O2cMr44tLv4m/iM/pOE126k1Z2DTRDKI7o7aWUePg="; 29 30 nativeBuildInputs = [ jq ]; 31 32 env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1"; 33 34 makeCacheWritable = true; 35 36 preBuild = '' 37 if [[ $(jq --raw-output '.devDependencies.electron' < package.json | grep -E --only-matching '^[0-9]+') != ${lib.escapeShellArg (lib.versions.major electron.version)} ]]; then 38 echo 'ERROR: electron version mismatch' 39 exit 1 40 fi 41 ''; 42 43 # Do not run the default build script, it tries to do way too much that 44 # wouldn't work on NixOS and require patching. 45 dontNpmBuild = true; 46 47 postBuild = '' 48 npm exec electron-builder -- \ 49 --dir \ 50 --c.electronDist=${electron.dist} \ 51 --c.electronVersion=${electron.version} 52 ''; 53 54 installPhase = '' 55 runHook preInstall 56 57 mkdir $out 58 59 pushd dist/linux-${lib.optionalString stdenv.hostPlatform.isAarch64 "arm64-"}unpacked 60 mkdir -p $out/opt/netron 61 cp -r locales resources{,.pak} $out/opt/netron 62 popd 63 64 makeWrapper '${lib.getExe electron}' "$out/bin/netron" \ 65 --add-flags $out/opt/netron/resources/app.asar \ 66 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \ 67 --set-default ELECTRON_IS_DEV 0 \ 68 --inherit-argv0 69 70 pushd source 71 for icon in icon.*; do 72 dir=$out/share/icons/hicolor/"''${icon%.*}"/apps 73 mkdir -p "$dir" 74 cp "$icon" "$dir"/${icon}.png 75 done 76 popd 77 78 runHook postInstall 79 ''; 80 81 desktopItems = [ 82 (makeDesktopItem { 83 name = "Netron"; 84 exec = "netron %U"; 85 inherit icon; 86 comment = description; 87 desktopName = "Netron"; 88 categories = [ "Development" ]; 89 }) 90 ]; 91 92 meta = { 93 changelog = "https://github.com/lutzroeder/netron/releases/tag/v${finalAttrs.version}"; 94 inherit description; 95 homepage = "https://netron.app"; 96 license = lib.licenses.mit; 97 maintainers = with lib.maintainers; [ flokli ]; 98 mainProgram = "netron"; 99 platforms = electron.meta.platforms; 100 badPlatforms = [ 101 # Fails on darwin 102 lib.systems.inspect.patterns.isDarwin 103 ]; 104 }; 105})