feat(nix-flake): rework nix package

This commit is contained in:
Alois 2026-08-30 15:58:34 +02:00
commit f74ca52f4f
Signed by: alois
SSH key fingerprint: SHA256:GBzT2DXvAuGV9XIV5W3WrzVpjU54FThmxHXdbz95J24
2 changed files with 111 additions and 111 deletions

View file

@ -311,58 +311,3 @@ jobs:
"$API/repos/$REPO/releases/$release_id" "$API/repos/$REPO/releases/$release_id"
done < "$DELETE_RELEASES" done < "$DELETE_RELEASES"
EOF EOF
- name: Update root flake release hash
env:
TAG: ${{ steps.version.outputs.tag }}
run: |
nix develop .#electron --command bash <<'EOF'
set -eu
DEB="$(find releases -maxdepth 1 -type f -name 'Tensamin-*-linux-amd64.deb' -print -quit)"
test -n "$DEB"
HASH="$(node -e 'const fs = require("fs"); const crypto = require("crypto"); const file = process.argv[1]; console.log("sha256-" + crypto.createHash("sha256").update(fs.readFileSync(file)).digest("base64"));' "$DEB")"
export HASH
node -e '
const fs = require("fs");
const version = process.env.TAG;
const hash = process.env.HASH;
let content = fs.readFileSync("flake.nix", "utf8");
content = content.replace(/version = "[^"]+";/, `version = "${version}";`);
content = content.replace(/x86_64DebHash = "sha256-[^"]+";/, `x86_64DebHash = "${hash}";`);
fs.writeFileSync("flake.nix", content);
'
if git diff --quiet -- flake.nix; then
echo "flake.nix already has the current release hash on main."
else
git add flake.nix
git -c user.name="forgejo-actions" -c user.email="forgejo-actions@localhost" commit -m "(qol): update release flake hash"
git push
fi
git fetch origin dev
git worktree add ../dev-flake-update origin/dev
cd ../dev-flake-update
node -e '
const fs = require("fs");
const version = process.env.TAG;
const hash = process.env.HASH;
let content = fs.readFileSync("flake.nix", "utf8");
content = content.replace(/version = "[^"]+";/, `version = "${version}";`);
content = content.replace(/x86_64DebHash = "sha256-[^"]+";/, `x86_64DebHash = "${hash}";`);
fs.writeFileSync("flake.nix", content);
'
if git diff --quiet -- flake.nix; then
echo "flake.nix already has the current release hash on dev."
exit 0
fi
git add flake.nix
git -c user.name="forgejo-actions" -c user.email="forgejo-actions@localhost" commit -m "(qol): update release flake hash"
git push origin HEAD:dev
EOF

181
flake.nix
View file

@ -17,8 +17,6 @@
systems = [ "x86_64-linux" ]; systems = [ "x86_64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs systems; forAllSystems = nixpkgs.lib.genAttrs systems;
version = "0.0.11"; version = "0.0.11";
x86_64DebHash = "sha256-iMEgdjY8Ghlx6K/YzKC5JAZbeHNJDIFHm8MKmM4efaI=";
forgejoBaseUrl = "https://git.methanium.net/tensamin/client/releases/download/${version}";
in in
{ {
packages = forAllSystems ( packages = forAllSystems (
@ -32,8 +30,6 @@
android_sdk.accept_license = true; android_sdk.accept_license = true;
}; };
}; };
debArtifact = "Tensamin-${version}-linux-amd64.deb";
electronRuntimeLibs = with pkgs; [ electronRuntimeLibs = with pkgs; [
alsa-lib alsa-lib
at-spi2-atk at-spi2-atk
@ -75,71 +71,130 @@
libXtst libXtst
libxcb libxcb
]; ];
packageDeb = electron = pkgs.electron;
src: pnpm = pkgs.pnpm;
pkgs.stdenv.mkDerivation { mtpTypeMaps = pkgs.fetchgit {
pname = "tensamin"; url = "https://git.methanium.net/tensamin/mtp-type-maps";
inherit version src; rev = "6e5122fe44f793c0e0d3229b3d34145ce17c2d31";
hash = "sha256-/4n8F0YLJaLncefKL907P5l+en1CTjpgdFmLBF3gbiQ=";
nativeBuildInputs = with pkgs; [ };
autoPatchelfHook mtpSource = pkgs.fetchzip {
dpkg url = "https://git.methanium.net/methanium/mtp/releases/download/0.3.0-dev-c7c7afe/mtp-0.3.0.tgz";
makeWrapper hash = "sha256-XLTa8DxP93Q4hBHRCLUzCPOqkbdb4V3aZxE5Iuq+kW0=";
]; };
buildInputs = electronRuntimeLibs; mtpCargoDeps = pkgs.rustPlatform.fetchCargoVendor {
src = mtpSource;
dontConfigure = true; hash = "sha256-8MZ65N/EtWPAggal0JkGDx3WSn+LxWQORinkqVbsrys=";
dontBuild = true; };
wasmBindgenCliSource = pkgs.fetchCrate {
unpackPhase = '' pname = "wasm-bindgen-cli";
runHook preUnpack version = "0.2.127";
dpkg-deb -x "$src" . hash = "sha256-di+qBAdd7pENLiIB9CoZoab+W5xeDoByMREcCGTSzWo=";
runHook postUnpack };
''; wasmBindgenCli = pkgs.buildWasmBindgenCli {
src = wasmBindgenCliSource;
installPhase = '' cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
runHook preInstall src = wasmBindgenCliSource;
hash = "sha256-FTv2GZIAQs0ePdIZXIXil7JbZ6kIT05VG6vqC1qNFxQ=";
mkdir -p "$out"
cp -r opt "$out/"
cp -r usr/* "$out/"
mkdir -p "$out/bin"
makeWrapper "$out/opt/Tensamin/tensamin" "$out/bin/tensamin" \
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath electronRuntimeLibs}"
substituteInPlace "$out/share/applications/Tensamin.desktop" \
--replace-fail "Exec=/opt/Tensamin/tensamin" "Exec=tensamin"
runHook postInstall
'';
}; };
defaultPackage = packageDeb ( };
pkgs.fetchurl { desktopItem = pkgs.makeDesktopItem {
url = "${forgejoBaseUrl}/${debArtifact}"; name = "tensamin";
hash = x86_64DebHash; desktopName = "Tensamin";
} exec = "tensamin";
); icon = "tensamin";
localDebPath = builtins.getEnv "TENSAMIN_DEB"; startupWMClass = "Tensamin";
localPathPackage = categories = [ "Network" ];
if localDebPath == "" then };
pkgs.writeShellScriptBin "tensamin" '' defaultPackage = pkgs.stdenv.mkDerivation (finalAttrs: {
echo "Set TENSAMIN_DEB to a local .deb path and run with --impure." >&2 pname = "tensamin";
exit 1 inherit version;
'' src = self;
else
packageDeb ( pnpmDeps = pkgs.fetchPnpmDeps {
builtins.path { inherit (finalAttrs) pname version src;
path = localDebPath; inherit pnpm;
name = debArtifact; fetcherVersion = 4;
} hash = "sha256-imP3MTr1YLc28Z9n617m0Wt/6vPirFznzoriKzojlEg=";
); };
nativeBuildInputs = with pkgs; [
copyDesktopItems
makeWrapper
nodejs_22
pnpm
pnpmConfigHook
cargo
lld
rustc
wasm-pack
wasmBindgenCli
binaryen
];
env.ELECTRON_SKIP_BINARY_DOWNLOAD = 1;
postPatch = ''
rm -rf mtp-type-maps
ln -s ${mtpTypeMaps} mtp-type-maps
node -e '
const fs = require("fs");
const path = "apps/electron/package.json";
const pkg = JSON.parse(fs.readFileSync(path, "utf8"));
pkg.version = "${version}";
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + "\n");
'
'';
buildPhase = ''
runHook preBuild
mkdir -p "$HOME/.cargo"
substitute ${mtpCargoDeps}/.cargo/config.toml "$HOME/.cargo/config.toml" \
--replace-fail @vendor@ ${mtpCargoDeps}
pnpm run copy-licenses
pnpm run build:packages
pnpm run build:web
pnpm --dir apps/tauri run gen-icons
pnpm --dir apps/electron run build
pnpm --dir apps/electron exec electron-builder --dir --linux --publish never \
--config.electronDist=${electron.dist} \
--config.electronVersion=${electron.version}
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out/lib/tensamin" "$out/bin"
cp -r apps/electron/release/linux-unpacked/. "$out/lib/tensamin/"
makeWrapper "$out/lib/tensamin/tensamin" "$out/bin/tensamin" \
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath electronRuntimeLibs}"
install -Dm644 apps/electron/build/icons/icon.png \
"$out/share/icons/hicolor/512x512/apps/tensamin.png"
runHook postInstall
'';
desktopItems = [ desktopItem ];
meta = {
description = "Tensamin desktop client";
homepage = "https://git.methanium.net/tensamin/client";
mainProgram = "tensamin";
platforms = pkgs.lib.platforms.linux;
};
});
in in
{ {
default = defaultPackage; default = defaultPackage;
tensamin = defaultPackage; tensamin = defaultPackage;
electron = defaultPackage; electron = defaultPackage;
localPathForDev = localPathPackage;
} }
); );