From 17cc0ef24d23598c2bab33d25ca7a8e4d90015f3 Mon Sep 17 00:00:00 2001 From: xfo-0 Date: Sat, 17 Jan 2026 16:36:39 -0800 Subject: [PATCH] feat: add Nix flake for native build with PySide6/Qt6 - Builds Vial natively without AppImage sandbox - Uses system Qt6 theming via wrapQtAppsHook - Patches app_context.py paths for Nix store compatibility - Includes udev rules and desktop entry --- flake.lock | 61 ++++++++++++++++++++++++ flake.nix | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..83716747ec --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1768135262, + "narHash": "sha256-PVvu7OqHBGWN16zSi6tEmPwwHQ4rLPU9Plvs8/1TUBY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "80daad04eddbbf5a4d883996a73f3f542fa437ac", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1768564909, + "narHash": "sha256-Kell/SpJYVkHWMvnhqJz/8DqQg2b6PguxVWOuadbHCc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e4bae1bd10c9c57b2cf517953ab70060a828ee6f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1765674936, + "narHash": "sha256-k00uTP4JNfmejrCLJOwdObYC9jHRrr/5M/a/8L2EIdo=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "2075416fcb47225d9b68ac469a5c4801a9c4dd85", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..e95eda1c3f --- /dev/null +++ b/flake.nix @@ -0,0 +1,136 @@ +{ + description = "Vial - Open-source GUI for configuring QMK keyboards"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = + inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + + perSystem = + { pkgs, self', ... }: + let + pythonEnv = pkgs.python3.withPackages ( + ps: with ps; [ + pyside6 + qtpy + hidapi + simpleeval + certifi + ] + ); + in + { + packages = { + default = self'.packages.vial; + + vial = pkgs.stdenv.mkDerivation { + pname = "vial"; + version = "0.8.0-ilc"; + + src = ./.; + + nativeBuildInputs = with pkgs; [ + qt6.wrapQtAppsHook + makeWrapper + ]; + + buildInputs = with pkgs; [ + qt6.qtbase + libusb1 + ]; + + qtWrapperArgs = [ + "--unset QT_STYLE_OVERRIDE" + ]; + + propagatedBuildInputs = [ pythonEnv ]; + + dontBuild = true; + + installPhase = '' + runHook preInstall + + mkdir -p $out/share/vial + cp -r src/main/python/* $out/share/vial/ + cp -r src/main/resources/base/* $out/share/vial/ + + # Create build_settings.json in the resource directory + cat > $out/share/vial/build_settings.json << SETTINGS + { + "app_name": "Vial", + "author": "ilc", + "version": "0.8.0-ilc" + } + SETTINGS + + # Patch app_context.py to use our Nix-compatible paths + substituteInPlace $out/share/vial/app_context.py \ + --replace-fail "return os.path.normpath(os.path.join(script_dir, '..', '..', 'build', 'settings', 'base.json'))" \ + "return os.path.join(script_dir, 'build_settings.json')" \ + --replace-fail "return os.path.normpath(os.path.join(script_dir, '..', 'resources', 'base'))" \ + "return script_dir" + + # Create launcher script + mkdir -p $out/bin + makeWrapper ${pythonEnv}/bin/python $out/bin/vial \ + --add-flags "$out/share/vial/main.py" + + # udev rules + mkdir -p $out/etc/udev/rules.d + echo 'KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0666", TAG+="uaccess", TAG+="udev-acl"' > $out/etc/udev/rules.d/92-vial.rules + + # Desktop entry + mkdir -p $out/share/applications + cat > $out/share/applications/vial.desktop << DESKTOP + [Desktop Entry] + Name=Vial + Comment=Configure your QMK keyboard + Exec=$out/bin/vial + Icon=vial + Terminal=false + Type=Application + Categories=Utility; + DESKTOP + + # Icons (if available) + if [ -d "src/main/icons" ]; then + mkdir -p $out/share/icons + cp -r src/main/icons/* $out/share/icons/ + fi + + runHook postInstall + ''; + + dontWrapQtApps = false; + + preFixup = '' + wrapQtApp $out/bin/vial + ''; + + meta = with pkgs.lib; { + description = "Open-source GUI for configuring QMK keyboards in real time"; + homepage = "https://get.vial.today"; + license = licenses.gpl2Plus; + platforms = platforms.linux; + mainProgram = "vial"; + }; + }; + }; + + devShells.default = pkgs.mkShell { + packages = [ + pythonEnv + pkgs.qt6.qtbase + ]; + }; + }; + }; +}