From 9fec4822c198c83c6b8266defe2b7076cf84ce79 Mon Sep 17 00:00:00 2001 From: Sean Krueger Date: Mon, 3 Jun 2024 11:51:41 -0500 Subject: [PATCH 1/6] Setup and activate virtual environment via flake When using the nix flake to generate a development shell, the python virtual environment will now automatically be created and dependecies from both requirements.txt and requirements-dev.txt will be installed. This removes the need for using the setup script after entering the dev shell. Exec bash must be the last thing called, as any other commands past it will not get executed by the shell hook. Also removes some duplicate dependencies that I found. --- flake.nix | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index dbe54de5..3aacca51 100644 --- a/flake.nix +++ b/flake.nix @@ -1,4 +1,6 @@ { + description = "Tag Studio Development Environment"; + inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; @@ -15,6 +17,9 @@ qt6Pkgs = qt6Nixpkgs.legacyPackages.x86_64-linux; in { devShells.x86_64-linux.default = pkgs.mkShell { + name = "Tag Studio Virtual Environment"; + venvDir = "./.venv"; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.gcc-unwrapped pkgs.zlib @@ -35,18 +40,17 @@ qt6Pkgs.qt6.full qt6Pkgs.qt6.qtbase ]; + buildInputs = with pkgs; [ cmake gdb zstd - python312Packages.pip python312Full - python312Packages.virtualenv # run virtualenv . + python312Packages.pip python312Packages.pyusb # fixes the pyusb 'No backend available' when installed directly via pip + python312Packages.venvShellHook # Initializes a venv in $venvDir libgcc - makeWrapper - bashInteractive glib libxkbcommon freetype @@ -70,14 +74,31 @@ # this is for the shellhook portion qt6Pkgs.qt6.wrapQtAppsHook ]; + + # Run after the virtual environment is created + postVenvCreation = '' + unset SOURCE_DATE_EPOCH + + echo Installing dependencies into virtual environment + pip install -r requirements.txt + pip install -r requirements-dev.txt + ''; + # set the environment variables that Qt apps expect - shellHook = '' + postShellHook = '' + unset SOURCE_DATE_EPOCH + export QT_QPA_PLATFORM=wayland export LIBRARY_PATH=/usr/lib:/usr/lib64:$LIBRARY_PATH # export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib/:/run/opengl-driver/lib/ export QT_PLUGIN_PATH=${pkgs.qt6.qtbase}/${pkgs.qt6.qtbase.qtPluginPrefix} bashdir=$(mktemp -d) makeWrapper "$(type -p bash)" "$bashdir/bash" "''${qtWrapperArgs[@]}" + + echo Activating Virtual Environment + source $venvDir/bin/activate + export PYTHONPATH=$PWD/$venvDir/${pkgs.python312Full.sitePackages}:$PYTHONPATH + exec "$bashdir/bash" ''; }; From cc827108efa3f8c61e0033e57dbae246eb031d5c Mon Sep 17 00:00:00 2001 From: Sean Krueger Date: Thu, 6 Jun 2024 20:50:22 -0500 Subject: [PATCH 2/6] Add xcb as fallback when wayland fails to load Mostly as a fallback for xserver. --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 3aacca51..23df6225 100644 --- a/flake.nix +++ b/flake.nix @@ -88,7 +88,7 @@ postShellHook = '' unset SOURCE_DATE_EPOCH - export QT_QPA_PLATFORM=wayland + export QT_QPA_PLATFORM="wayland;xcb" export LIBRARY_PATH=/usr/lib:/usr/lib64:$LIBRARY_PATH # export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib/:/run/opengl-driver/lib/ export QT_PLUGIN_PATH=${pkgs.qt6.qtbase}/${pkgs.qt6.qtbase.qtPluginPrefix} From 31038711f2e692daecc2b8bb9e604b88caded253 Mon Sep 17 00:00:00 2001 From: Sean Krueger Date: Fri, 7 Jun 2024 18:09:42 -0500 Subject: [PATCH 3/6] Install ruff via nixpkgs --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 23df6225..2549173e 100644 --- a/flake.nix +++ b/flake.nix @@ -49,6 +49,7 @@ python312Packages.pip python312Packages.pyusb # fixes the pyusb 'No backend available' when installed directly via pip python312Packages.venvShellHook # Initializes a venv in $venvDir + ruff # Ruff cannot be installed via pip libgcc glib @@ -82,6 +83,7 @@ echo Installing dependencies into virtual environment pip install -r requirements.txt pip install -r requirements-dev.txt + pip uninstall -y ruff # Hacky solution to not fight with other dev deps ''; # set the environment variables that Qt apps expect From 4f193613deaa8179ce131ccff6fb2f156f9464b6 Mon Sep 17 00:00:00 2001 From: Sean Krueger Date: Mon, 10 Jun 2024 19:16:24 -0500 Subject: [PATCH 4/6] Update Contributing documentation for dev on Nix Moves the previous updated blurb from the README to the new CONTRIBUTING file. Also reworks some wording to link to the Flake nix wiki page for nix users who haven't enable flakes yet. --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 942aa3eb..24f3b0e3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -64,10 +64,10 @@ _Learn more about setting up a virtual environment [here](https://docs.python.or - Run the "TagStudio.sh" script and the program should launch! (Make sure that the script is marked as executable if on Linux). Note that launching from the script from outside of a terminal will not launch a terminal window with any debug or crash information. If you wish to see this information, just launch the shell script directly from your terminal with `./TagStudio.sh`. - - **NixOS** (TagStudio.sh) + - **NixOS** (Nix Flake) > [!WARNING] > Support for NixOS is still a work in progress. - - Use the provided `flake.nix` file to create and enter a working environment by running `nix develop`. Then, run the `TagStudio.sh` script. + - Use the provided [Flake](https://nixos.wiki/wiki/Flakes) to create and enter a working environment by running `nix develop`. Then, run the program via `python3 tagstudio/tag_studio.py` from the root directory. - **Any** (No Scripts) From 49ad8117ef4fb661096296da8a22030c2777f6d6 Mon Sep 17 00:00:00 2001 From: Xarvex Date: Sun, 16 Jun 2024 02:59:59 -0500 Subject: [PATCH 5/6] fix(flake): resolve mypy access to libraries --- flake.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 2549173e..ccca2cb7 100644 --- a/flake.nix +++ b/flake.nix @@ -50,6 +50,7 @@ python312Packages.pyusb # fixes the pyusb 'No backend available' when installed directly via pip python312Packages.venvShellHook # Initializes a venv in $venvDir ruff # Ruff cannot be installed via pip + mypy # MyPy cannot be installed via pip libgcc glib @@ -81,9 +82,12 @@ unset SOURCE_DATE_EPOCH echo Installing dependencies into virtual environment + pip install PySide6==6.6.2 # 6.6.3 has faulty .pyi files pip install -r requirements.txt pip install -r requirements-dev.txt - pip uninstall -y ruff # Hacky solution to not fight with other dev deps + # Hacky solution to not fight with other dev deps + # May show failure if skipped due to same version with nixpkgs + pip uninstall -y mypy ruff ''; # set the environment variables that Qt apps expect From 15ee13c7b4666d36968ee9bc459b6993cab61370 Mon Sep 17 00:00:00 2001 From: Sean Krueger Date: Mon, 17 Jun 2024 13:02:52 -0500 Subject: [PATCH 6/6] Bump Qt6 version to 6.7.1 --- flake.lock | 14 +++++++------- flake.nix | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/flake.lock b/flake.lock index e6a43b0b..f83ab58f 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1717602782, - "narHash": "sha256-pL9jeus5QpX5R+9rsp3hhZ+uplVHscNJh8n8VpqscM0=", + "lastModified": 1718318537, + "narHash": "sha256-4Zu0RYRcAY/VWuu6awwq4opuiD//ahpc2aFHg2CWqFY=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e8057b67ebf307f01bdcc8fba94d94f75039d1f6", + "rev": "e9ee548d90ff586a6471b4ae80ae9cfcbceb3420", "type": "github" }, "original": { @@ -18,17 +18,17 @@ }, "qt6Nixpkgs": { "locked": { - "lastModified": 1711460435, - "narHash": "sha256-Qb/J9NFk2Qemg7vTl8EDCto6p3Uf/GGORkGhTQJLj9U=", + "lastModified": 1716287118, + "narHash": "sha256-iUTrXABmJAkPRhwPB8GEP7k52OWHVSRtMzlKQ2kIrz4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f862bd46d3020bcfe7195b3dad638329271b0524", + "rev": "47da0aee5616a063015f10ea593688646f2377e4", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "f862bd46d3020bcfe7195b3dad638329271b0524", + "rev": "47da0aee5616a063015f10ea593688646f2377e4", "type": "github" } }, diff --git a/flake.nix b/flake.nix index ccca2cb7..69adee17 100644 --- a/flake.nix +++ b/flake.nix @@ -5,8 +5,8 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; qt6Nixpkgs = { - # Commit bumping to qt6.6.3 - url = "github:NixOS/nixpkgs/f862bd46d3020bcfe7195b3dad638329271b0524"; + # Commit bumping to qt6.7.1 + url = "github:NixOS/nixpkgs/47da0aee5616a063015f10ea593688646f2377e4"; }; }; @@ -82,7 +82,6 @@ unset SOURCE_DATE_EPOCH echo Installing dependencies into virtual environment - pip install PySide6==6.6.2 # 6.6.3 has faulty .pyi files pip install -r requirements.txt pip install -r requirements-dev.txt # Hacky solution to not fight with other dev deps