Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create and activate venv via Nix Flake #229

Merged
merged 6 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 7 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 34 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
description = "Tag Studio Development Environment";

inputs = {
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";
};
};

Expand All @@ -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
Expand All @@ -35,18 +40,19 @@
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
ruff # Ruff cannot be installed via pip
mypy # MyPy cannot be installed via pip

libgcc
makeWrapper
bashInteractive
glib
libxkbcommon
freetype
Expand All @@ -70,14 +76,34 @@
# 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
# 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
shellHook = ''
export QT_QPA_PLATFORM=wayland
postShellHook = ''
unset SOURCE_DATE_EPOCH

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}
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"
'';
};
Expand Down