Skip to content

Commit 6827fb5

Browse files
y0usafpinage404cjpais
authored
Add Nix flake for NixOS support (#561)
* Add Nix flake for NixOS support Provides: - handy-appimage: AppImage-based package (default) - devShell: Development environment for building from source * fix(nix): address PR feedback for flake.nix - Remove aarch64-linux from supportedSystems (ARM64 builds not produced) - Read version dynamically from Cargo.toml instead of hardcoding This enables automated updates during GitHub releases * chore(nix): add GitHub Actions workflow to auto-update AppImage hash Adds a separate workflow triggered on release publication that: - Fetches the released AppImage - Computes the SRI hash using nix-prefetch-url - Updates flake.nix with the new hash - Commits and pushes changes directly Includes retry logic for timing issues and defensive checks to verify the hash was actually updated and skip commits if unchanged. * Update flake.nix hash to resolve mismatch Co-authored-by: pinage404 <pinage404@gmail.com> * Update flake.nix to install dependencies automatically Co-authored-by: pinage404 <pinage404@gmail.com> * fix: update AppImage hash for v0.7.0 * modified description --------- Co-authored-by: pinage404 <pinage404@gmail.com> Co-authored-by: CJ Pais <cj@cjpais.com>
1 parent 713d0b3 commit 6827fb5

File tree

3 files changed

+179
-0
lines changed

3 files changed

+179
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: "Update Flake Hash"
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
update-flake:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Install Nix
18+
uses: DeterminateSystems/nix-installer-action@main
19+
20+
- name: Get AppImage hash
21+
id: hash
22+
env:
23+
RELEASE_VERSION: ${{ github.event.release.tag_name }}
24+
run: |
25+
# Remove 'v' prefix from tag if present
26+
VERSION="${RELEASE_VERSION#v}"
27+
APPIMAGE_URL="https://github.com/${{ github.repository }}/releases/download/v${VERSION}/Handy_${VERSION}_amd64.AppImage"
28+
29+
echo "Computing hash for: $APPIMAGE_URL"
30+
31+
# Retry logic in case AppImage isn't immediately available
32+
for i in {1..30}; do
33+
HASH=$(nix-prefetch-url --name "Handy_${VERSION}_amd64.AppImage" "$APPIMAGE_URL" 2>&1 | grep "^sha256-" || true)
34+
if [ -n "$HASH" ]; then
35+
echo "hash=$HASH" >> "$GITHUB_OUTPUT"
36+
echo "Successfully computed hash: $HASH"
37+
exit 0
38+
fi
39+
echo "Attempt $i: AppImage not yet available, waiting..."
40+
sleep 5
41+
done
42+
43+
echo "Failed to fetch AppImage after retries"
44+
exit 1
45+
46+
- name: Update flake.nix
47+
env:
48+
HASH: ${{ steps.hash.outputs.hash }}
49+
run: |
50+
sed -i "s|hash = \"sha256-[^\"]*\"|hash = \"$HASH\"|" flake.nix
51+
52+
# Verify the hash was actually updated
53+
if ! grep -q "hash = \"$HASH\"" flake.nix; then
54+
echo "ERROR: Failed to update hash in flake.nix"
55+
exit 1
56+
fi
57+
echo "Successfully updated flake.nix with hash: $HASH"
58+
59+
- name: Commit and push
60+
env:
61+
VERSION: ${{ github.event.release.tag_name }}
62+
run: |
63+
git config user.name "github-actions[bot]"
64+
git config user.email "github-actions[bot]@users.noreply.github.com"
65+
66+
# Only commit if flake.nix actually changed
67+
if git diff --quiet flake.nix; then
68+
echo "Hash already up-to-date, no commit needed"
69+
else
70+
git add flake.nix
71+
git commit -m "chore(nix): update AppImage hash for ${VERSION}"
72+
git push
73+
echo "Successfully pushed hash update"
74+
fi

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
description = "Handy - A free, open source, and extensible speech-to-text application that works completely offline";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
};
7+
8+
outputs = {
9+
self,
10+
nixpkgs,
11+
}: let
12+
supportedSystems = ["x86_64-linux"];
13+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
14+
# Read version from Cargo.toml
15+
cargoToml = builtins.fromTOML (builtins.readFile ./src-tauri/Cargo.toml);
16+
version = cargoToml.package.version;
17+
in {
18+
packages = forAllSystems (system: let
19+
pkgs = nixpkgs.legacyPackages.${system};
20+
in {
21+
# AppImage-based package
22+
handy-appimage = let
23+
appimage = pkgs.appimageTools.wrapType2 {
24+
pname = "handy-appimage-unwrapped";
25+
inherit version;
26+
src = pkgs.fetchurl {
27+
url = "https://github.com/cjpais/Handy/releases/download/v${version}/Handy_${version}_amd64.AppImage";
28+
hash = "sha256-tTswFYLCPGtMbHAb2bQMsklRiRCVXLrtu4pQC8IHdqQ=";
29+
};
30+
extraPkgs = p:
31+
with p; [
32+
alsa-lib
33+
];
34+
};
35+
in
36+
pkgs.writeShellScriptBin "handy" ''
37+
export WEBKIT_DISABLE_DMABUF_RENDERER=1
38+
exec ${appimage}/bin/handy-appimage-unwrapped "$@"
39+
'';
40+
41+
default = self.packages.${system}.handy-appimage;
42+
});
43+
44+
# Development shell for building from source
45+
devShells = forAllSystems (system: let
46+
pkgs = nixpkgs.legacyPackages.${system};
47+
in {
48+
default = pkgs.mkShell {
49+
buildInputs = with pkgs; [
50+
# Rust
51+
rustc
52+
cargo
53+
rust-analyzer
54+
clippy
55+
# Frontend
56+
nodejs
57+
bun
58+
# Native deps
59+
pkg-config
60+
openssl
61+
alsa-lib
62+
libsoup_3
63+
webkitgtk_4_1
64+
gtk3
65+
glib
66+
# Tauri CLI
67+
cargo-tauri
68+
];
69+
70+
shellHook = ''
71+
echo "Handy development environment"
72+
bun install
73+
echo "Run 'bun run tauri dev' to start"
74+
'';
75+
};
76+
});
77+
};
78+
}

0 commit comments

Comments
 (0)