返回列表 回复 发帖

[资源] 网络画板播放器 nixpkgs

将下面的代码保存为 flake.nix

在目录下
  1. NIXPKGS_ALLOW_UNFREE=1 nix build --impure .#
复制代码
后,
  1. ./result/bin/netpad-player
复制代码
就行.
  1. {
  2.   description = "Netpad Player - A Nix flake for the Netpad Player application.";

  3.   inputs = {
  4.     nixpkgs.url = "github:NixOS/nixpkgs/release-24.11"; # It's generally recommended to use a stable channel, but for accessing 'electron', unstable might be needed.  Adjust as necessary.
  5.     flake-utils.url = "github:numtide/flake-utils";
  6.   };

  7.   outputs = { self, nixpkgs, flake-utils }:
  8.     flake-utils.lib.eachDefaultSystem (system:
  9.       let
  10.         pkgs = nixpkgs.legacyPackages.${system};
  11.         pkgname = "netpad-player";
  12.         pkgver = "1.6.4";
  13.         src = pkgs.fetchurl {
  14.           url = "https://www.netpad.net.cn/download/NetpadPlayer-${pkgver}.exe";
  15.           sha256 = "7b53d020786843c71e13b260fb7d5d60c483b6eed0271fb9b1a5a1aeda1f2092";
  16.         };

  17.         #The prepare step. Extracts the asar archive and removes unnecessary files.
  18.         extractedApp = pkgs.stdenv.mkDerivation {
  19.           name = "${pkgname}-extracted";
  20.           version = pkgver;
  21.           src = src;
  22.           nativeBuildInputs = [ pkgs.asar pkgs.p7zip ];
  23.           unpackPhase = ''
  24.              mkdir -vp extracted
  25.              7z x $src -oextracted # Use 7z to extract from the exe.
  26.              7z x extracted/\$PLUGINSDIR/app-32.7z
  27.              asar extract resources/app.asar ./app
  28.           '';

  29.            installPhase = ''
  30.             mkdir -p $out
  31.             cp -r ./app $out/
  32.            # find $srcdir -name app.asar -exec asar e {} ./app \;   -> Above asar extract command.
  33.             find $out -type f -path "*/darwin/*" -delete
  34.             find $out -name "*.rar" -delete
  35.             find $out -path "*/bin/*.js" -delete
  36.             find $out -name "*.js.map" -delete
  37.           '';
  38.         };

  39.         # The desktop file content, embedded directly.  This is cleaner than a separate file.
  40.         desktopFileContent = ''
  41.           [Desktop Entry]
  42.           Version=1.0
  43.           Type=Application
  44.           Name=netpad-player
  45.           Name[zh_CN]=网络画板离线播放器
  46.           Comment=网络画板,用核心技术赋能智慧数学教育
  47.           Exec=netpad-player
  48.           Icon=netpad-player
  49.           Terminal=false
  50.           StartupNotify=false
  51.           Categories=Application;
  52.         '';


  53.       in
  54.       {
  55.         packages = {
  56.           default = pkgs.stdenv.mkDerivation {
  57.             name = pkgname;
  58.             version = pkgver;

  59.             src = extractedApp;  # Use the extracted app as the source.


  60.             nativeBuildInputs = [ pkgs.makeWrapper ]; # For creating the wrapper script.
  61.             buildInputs = [ pkgs.electron ]; # Provide electron for runtime.

  62.               installPhase = ''
  63.               mkdir -p $out/opt/${pkgname}
  64.               cp -r $src/* $out/opt/${pkgname}/

  65.               # Create a wrapper script to launch the application using electron.
  66.               makeWrapper ${pkgs.electron}/bin/electron $out/bin/${pkgname} \
  67.                 --add-flags "$out/opt/${pkgname}/app"

  68.                 # Create the desktop file.
  69.               mkdir -p $out/share/applications
  70.               echo "${desktopFileContent}" > $out/share/applications/${pkgname}.desktop

  71.               find $out -name "icon.png" -print -exec install -Dm644 {} $out/share/pixmaps/${pkgname}.png \;

  72.             '';


  73.              meta = with pkgs.lib; {
  74.               description = "网络画板,用核心技术赋能智慧数学教育";
  75.               homepage = "https://www.netpad.net.cn/";
  76.               license = licenses.unfree; #  'custom' is not a valid SPDX identifier, so use 'unfree'.
  77.               platforms = platforms.all; #  'any' arch, so it should work on all platforms that support Electron.
  78.               maintainers = [ "Asuka Minato <i at asukaminato dot eu dot org>" ]; # Maintainer info.
  79.             };

  80.           };
  81.           # netpad-player = self.packages.${system}.default;

  82.         };
  83.       });
  84. }
复制代码
已测试在 nixOS 上能成功运行.
返回列表