Skip to content

Commit e1b1ef9

Browse files
authored
Merge pull request #229 from seakrueger/flake-setup-venv
ci(flake): create and activate venv via Nix Flake
2 parents 3fcf602 + 15ee13c commit e1b1ef9

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ _Learn more about setting up a virtual environment [here](https://docs.python.or
6464

6565
- 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`.
6666

67-
- **NixOS** (TagStudio.sh)
67+
- **NixOS** (Nix Flake)
6868
> [!WARNING]
6969
> Support for NixOS is still a work in progress.
70-
- Use the provided `flake.nix` file to create and enter a working environment by running `nix develop`. Then, run the `TagStudio.sh` script.
70+
- 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.
7171

7272
- **Any** (No Scripts)
7373

flake.lock

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

flake.nix

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
2+
description = "Tag Studio Development Environment";
3+
24
inputs = {
35
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
46

57
qt6Nixpkgs = {
6-
# Commit bumping to qt6.6.3
7-
url = "github:NixOS/nixpkgs/f862bd46d3020bcfe7195b3dad638329271b0524";
8+
# Commit bumping to qt6.7.1
9+
url = "github:NixOS/nixpkgs/47da0aee5616a063015f10ea593688646f2377e4";
810
};
911
};
1012

@@ -15,6 +17,9 @@
1517
qt6Pkgs = qt6Nixpkgs.legacyPackages.x86_64-linux;
1618
in {
1719
devShells.x86_64-linux.default = pkgs.mkShell {
20+
name = "Tag Studio Virtual Environment";
21+
venvDir = "./.venv";
22+
1823
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
1924
pkgs.gcc-unwrapped
2025
pkgs.zlib
@@ -35,18 +40,19 @@
3540
qt6Pkgs.qt6.full
3641
qt6Pkgs.qt6.qtbase
3742
];
43+
3844
buildInputs = with pkgs; [
3945
cmake
4046
gdb
4147
zstd
42-
python312Packages.pip
4348
python312Full
44-
python312Packages.virtualenv # run virtualenv .
49+
python312Packages.pip
4550
python312Packages.pyusb # fixes the pyusb 'No backend available' when installed directly via pip
51+
python312Packages.venvShellHook # Initializes a venv in $venvDir
52+
ruff # Ruff cannot be installed via pip
53+
mypy # MyPy cannot be installed via pip
4654

4755
libgcc
48-
makeWrapper
49-
bashInteractive
5056
glib
5157
libxkbcommon
5258
freetype
@@ -70,14 +76,34 @@
7076
# this is for the shellhook portion
7177
qt6Pkgs.qt6.wrapQtAppsHook
7278
];
79+
80+
# Run after the virtual environment is created
81+
postVenvCreation = ''
82+
unset SOURCE_DATE_EPOCH
83+
84+
echo Installing dependencies into virtual environment
85+
pip install -r requirements.txt
86+
pip install -r requirements-dev.txt
87+
# Hacky solution to not fight with other dev deps
88+
# May show failure if skipped due to same version with nixpkgs
89+
pip uninstall -y mypy ruff
90+
'';
91+
7392
# set the environment variables that Qt apps expect
74-
shellHook = ''
75-
export QT_QPA_PLATFORM=wayland
93+
postShellHook = ''
94+
unset SOURCE_DATE_EPOCH
95+
96+
export QT_QPA_PLATFORM="wayland;xcb"
7697
export LIBRARY_PATH=/usr/lib:/usr/lib64:$LIBRARY_PATH
7798
# export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib/:/run/opengl-driver/lib/
7899
export QT_PLUGIN_PATH=${pkgs.qt6.qtbase}/${pkgs.qt6.qtbase.qtPluginPrefix}
79100
bashdir=$(mktemp -d)
80101
makeWrapper "$(type -p bash)" "$bashdir/bash" "''${qtWrapperArgs[@]}"
102+
103+
echo Activating Virtual Environment
104+
source $venvDir/bin/activate
105+
export PYTHONPATH=$PWD/$venvDir/${pkgs.python312Full.sitePackages}:$PYTHONPATH
106+
81107
exec "$bashdir/bash"
82108
'';
83109
};

0 commit comments

Comments
 (0)