Skip to content

Instantly share code, notes, and snippets.

@asukaminato0721
Last active February 12, 2025 04:56
Show Gist options
  • Save asukaminato0721/bbb502961002522939a0b56c055ee3af to your computer and use it in GitHub Desktop.
Save asukaminato0721/bbb502961002522939a0b56c055ee3af to your computer and use it in GitHub Desktop.
flake.nix for netpad-player
{
description = "Netpad Player - A Nix flake for the Netpad Player application.";
inputs = {
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.
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
};
};
pkgname = "netpad-player";
pkgver = "1.6.4";
src = pkgs.fetchurl {
url = "https://www.netpad.net.cn/download/NetpadPlayer-${pkgver}.exe";
sha256 = "7b53d020786843c71e13b260fb7d5d60c483b6eed0271fb9b1a5a1aeda1f2092";
};
#The prepare step. Extracts the asar archive and removes unnecessary files.
extractedApp = pkgs.stdenv.mkDerivation {
name = "${pkgname}-extracted";
version = pkgver;
src = src;
nativeBuildInputs = [ pkgs.asar pkgs.p7zip ];
unpackPhase = ''
mkdir -vp extracted
7z x $src -oextracted # Use 7z to extract from the exe.
7z x extracted/\$PLUGINSDIR/app-32.7z
asar extract resources/app.asar ./app
'';
installPhase = ''
mkdir -p $out
cp -r ./app $out/
# find $srcdir -name app.asar -exec asar e {} ./app \; -> Above asar extract command.
find $out -type f -path "*/darwin/*" -delete
find $out -name "*.rar" -delete
find $out -path "*/bin/*.js" -delete
find $out -name "*.js.map" -delete
'';
};
# The desktop file content, embedded directly. This is cleaner than a separate file.
desktopFileContent = ''
[Desktop Entry]
Version=1.0
Type=Application
Name=netpad-player
Name[zh_CN]=网络画板离线播放器
Comment=网络画板,用核心技术赋能智慧数学教育
Exec=netpad-player
Icon=netpad-player
Terminal=false
StartupNotify=false
Categories=Application;
'';
in
{
packages = {
default = pkgs.stdenv.mkDerivation {
name = pkgname;
version = pkgver;
src = extractedApp; # Use the extracted app as the source.
nativeBuildInputs = [ pkgs.makeWrapper ]; # For creating the wrapper script.
buildInputs = [ pkgs.electron-bin ]; # Provide electron for runtime.
installPhase = ''
mkdir -p $out/opt/${pkgname}
cp -r $src/* $out/opt/${pkgname}/
# Create a wrapper script to launch the application using electron.
makeWrapper ${pkgs.electron-bin}/bin/electron $out/bin/${pkgname} \
--add-flags "$out/opt/${pkgname}/app"
# Create the desktop file.
mkdir -p $out/share/applications
echo "${desktopFileContent}" > $out/share/applications/${pkgname}.desktop
find $out -name "icon.png" -print -exec install -Dm644 {} $out/share/pixmaps/${pkgname}.png \;
'';
meta = with pkgs.lib; {
description = "网络画板,用核心技术赋能智慧数学教育";
homepage = "https://www.netpad.net.cn/";
license = licenses.unfree; # 'custom' is not a valid SPDX identifier, so use 'unfree'.
platforms = platforms.all; # 'any' arch, so it should work on all platforms that support Electron.
maintainers = [ "Asuka Minato <i at asukaminato dot eu dot org>" ]; # Maintainer info.
};
};
# netpad-player = self.packages.${system}.default;
};
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment