Skip to content

Commit

Permalink
Merge pull request #229 from seakrueger/flake-setup-venv
Browse files Browse the repository at this point in the history
ci(flake): create and activate venv via Nix Flake
  • Loading branch information
xarvex authored Aug 23, 2024
2 parents 3fcf602 + 15ee13c commit e1b1ef9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
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

0 comments on commit e1b1ef9

Please sign in to comment.