From cb4798b71595c113c0519af4991ad52b60adaa31 Mon Sep 17 00:00:00 2001 From: xarvex Date: Sat, 24 Aug 2024 22:57:00 -0500 Subject: [PATCH 1/5] feat(flake): complete revamp with devenv/direnv Not perfect, and mostly a port of the previous edition. Hours have already been sunk into this, and need to get this out for consumption, and for ironing out. For more information see: https://devenv.sh NOTE: impure is used only because of the devenv-managed state, do not be alarmed! --- .envrc | 10 + .gitignore | 3 + flake.lock | 534 +++++++++++++++++++++++++++++++++++++++++++++++++++-- flake.nix | 235 ++++++++++++++--------- 4 files changed, 679 insertions(+), 103 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..5bce6abd --- /dev/null +++ b/.envrc @@ -0,0 +1,10 @@ +if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then + source_url 'https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc' 'sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=' +fi + +watch_file flake.nix +watch_file flake.lock + +if ! use flake . --impure; then + printf '%s\n' "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 +fi diff --git a/.gitignore b/.gitignore index 4c9ce401..459e6d88 100644 --- a/.gitignore +++ b/.gitignore @@ -253,3 +253,6 @@ compile_commands.json .TagStudio TagStudio.ini # End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,python,qt + +.direnv +.devenv diff --git a/flake.lock b/flake.lock index f83ab58f..76b655a0 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,417 @@ { "nodes": { + "cachix": { + "inputs": { + "devenv": "devenv_2", + "flake-compat": [ + "devenv", + "flake-compat" + ], + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "pre-commit-hooks": [ + "devenv", + "pre-commit-hooks" + ] + }, + "locked": { + "lastModified": 1712055811, + "narHash": "sha256-7FcfMm5A/f02yyzuavJe06zLa9hcMHsagE28ADcmQvk=", + "owner": "cachix", + "repo": "cachix", + "rev": "02e38da89851ec7fec3356a5c04bc8349cae0e30", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "cachix", + "type": "github" + } + }, + "devenv": { + "inputs": { + "cachix": "cachix", + "flake-compat": "flake-compat_2", + "nix": "nix_2", + "nixpkgs": "nixpkgs_2", + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1724504184, + "narHash": "sha256-gP6000c2+zHKJHAxCD3BftvAjmb4CPAZamRAHNxN2MM=", + "owner": "cachix", + "repo": "devenv", + "rev": "51338b58fd666f448db7486ec145dbe52db9b829", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "devenv_2": { + "inputs": { + "flake-compat": [ + "devenv", + "cachix", + "flake-compat" + ], + "nix": "nix", + "nixpkgs": "nixpkgs", + "poetry2nix": "poetry2nix", + "pre-commit-hooks": [ + "devenv", + "cachix", + "pre-commit-hooks" + ] + }, + "locked": { + "lastModified": 1708704632, + "narHash": "sha256-w+dOIW60FKMaHI1q5714CSibk99JfYxm0CzTinYWr+Q=", + "owner": "cachix", + "repo": "devenv", + "rev": "2ee4450b0f4b95a1b90f2eb5ffea98b90e48c196", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "python-rewrite", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722555600, + "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nix": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": [ + "devenv", + "cachix", + "devenv", + "nixpkgs" + ], + "nixpkgs-regression": "nixpkgs-regression" + }, + "locked": { + "lastModified": 1712911606, + "narHash": "sha256-BGvBhepCufsjcUkXnEEXhEVjwdJAwPglCC2+bInc794=", + "owner": "domenkozar", + "repo": "nix", + "rev": "b24a9318ea3f3600c1e24b4a00691ee912d4de12", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.21", + "repo": "nix", + "type": "github" + } + }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "devenv", + "cachix", + "devenv", + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688870561, + "narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "165b1650b753316aa7f1787f3005a8d2da0f5301", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, + "nix2container": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720642556, + "narHash": "sha256-qsnqk13UmREKmRT7c8hEnz26X3GFFyIQrqx4EaRc1Is=", + "owner": "nlewo", + "repo": "nix2container", + "rev": "3853e5caf9ad24103b13aa6e0e8bcebb47649fe4", + "type": "github" + }, + "original": { + "owner": "nlewo", + "repo": "nix2container", + "type": "github" + } + }, + "nix_2": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-regression": "nixpkgs-regression_2" + }, + "locked": { + "lastModified": 1712911606, + "narHash": "sha256-BGvBhepCufsjcUkXnEEXhEVjwdJAwPglCC2+bInc794=", + "owner": "domenkozar", + "repo": "nix", + "rev": "b24a9318ea3f3600c1e24b4a00691ee912d4de12", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.21", + "repo": "nix", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1718318537, - "narHash": "sha256-4Zu0RYRcAY/VWuu6awwq4opuiD//ahpc2aFHg2CWqFY=", + "lastModified": 1692808169, + "narHash": "sha256-x9Opq06rIiwdwGeK2Ykj69dNc2IvUH1fY55Wm7atwrE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9201b5ff357e781bf014d0330d18555695df7ba8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-qt6": { + "locked": { + "lastModified": 1718428119, + "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5", + "type": "github" + } + }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, + "nixpkgs-regression_2": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1713361204, + "narHash": "sha256-TA6EDunWTkc5FvDCqU3W2T3SFn0gRZqh6D/hJnM02MM=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "285676e87ad9f0ca23d8714a6ab61e7e027020c6", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1724224976, + "narHash": "sha256-Z/ELQhrSd7bMzTO8r7NZgi9g5emh+aRKoCdaAv5fiO0=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e9ee548d90ff586a6471b4ae80ae9cfcbceb3420", + "rev": "c374d94f1536013ca8e92341b540eba4c22f9c62", "type": "github" }, "original": { @@ -16,26 +421,127 @@ "type": "github" } }, - "qt6Nixpkgs": { + "poetry2nix": { + "inputs": { + "flake-utils": "flake-utils", + "nix-github-actions": "nix-github-actions", + "nixpkgs": [ + "devenv", + "cachix", + "devenv", + "nixpkgs" + ] + }, "locked": { - "lastModified": 1716287118, - "narHash": "sha256-iUTrXABmJAkPRhwPB8GEP7k52OWHVSRtMzlKQ2kIrz4=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "47da0aee5616a063015f10ea593688646f2377e4", + "lastModified": 1692876271, + "narHash": "sha256-IXfZEkI0Mal5y1jr6IRWMqK8GW2/f28xJenZIPQqkY0=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "d5006be9c2c2417dafb2e2e5034d83fabd207ee3", "type": "github" }, "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "47da0aee5616a063015f10ea593688646f2377e4", + "owner": "nix-community", + "repo": "poetry2nix", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1713775815, + "narHash": "sha256-Wu9cdYTnGQQwtT20QQMg7jzkANKQjwBD9iccfGKkfls=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "2ac4dcbf55ed43f3be0bae15e181f08a57af24a4", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", "type": "github" } }, "root": { "inputs": { - "nixpkgs": "nixpkgs", - "qt6Nixpkgs": "qt6Nixpkgs" + "devenv": "devenv", + "flake-parts": "flake-parts", + "nix2container": "nix2container", + "nixpkgs": "nixpkgs_3", + "nixpkgs-qt6": "nixpkgs-qt6", + "systems": "systems_4" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_4": { + "locked": { + "lastModified": 1689347949, + "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", + "owner": "nix-systems", + "repo": "default-linux", + "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default-linux", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 69adee17..cef5574a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,111 +1,168 @@ { - description = "Tag Studio Development Environment"; + description = "TagStudio"; inputs = { + devenv.url = "github:cachix/devenv"; + + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + + nix2container = { + url = "github:nlewo/nix2container"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - qt6Nixpkgs = { - # Commit bumping to qt6.7.1 - url = "github:NixOS/nixpkgs/47da0aee5616a063015f10ea593688646f2377e4"; - }; + # Pinned to Qt version 6.7.1 + nixpkgs-qt6.url = "github:NixOS/nixpkgs/e6cea36f83499eb4e9cd184c8a8e823296b50ad5"; + + systems.url = "github:nix-systems/default-linux"; }; - outputs = { self, nixpkgs, qt6Nixpkgs }: - let - pkgs = nixpkgs.legacyPackages.x86_64-linux; + outputs = { flake-parts, nixpkgs, nixpkgs-qt6, self, systems, ... }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ inputs.devenv.flakeModule ]; - qt6Pkgs = qt6Nixpkgs.legacyPackages.x86_64-linux; - in { - devShells.x86_64-linux.default = pkgs.mkShell { - name = "Tag Studio Virtual Environment"; - venvDir = "./.venv"; + systems = import systems; - LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ - pkgs.gcc-unwrapped - pkgs.zlib - pkgs.libglvnd - pkgs.glib - pkgs.stdenv.cc.cc - pkgs.fontconfig - pkgs.libxkbcommon - pkgs.xorg.libxcb - pkgs.freetype - pkgs.dbus - pkgs.zstd - # For PySide6 Multimedia - pkgs.libpulseaudio - pkgs.libkrb5 + perSystem = { config, pkgs, system, ... }: + let + inherit (nixpkgs) lib; - qt6Pkgs.qt6.qtwayland - qt6Pkgs.qt6.full - qt6Pkgs.qt6.qtbase - ]; + qt6Pkgs = import nixpkgs-qt6 { inherit system; }; + in + { + devenv.shells = rec { + default = tagstudio; - buildInputs = with pkgs; [ - cmake - gdb - zstd - python312Full - 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 + tagstudio = + let + cfg = config.devenv.shells.tagstudio; + in + { + # NOTE: many things were simply transferred over from previous, + # there must be additional work in ensuring all relevant dependencies + # are in place (and no extraneous). I have already spent much + # work making this in the first place and just need to get it out + # there, especially after my promises. Would appreciate any help + # (possibly PRs!) on taking care of this. Otherwise, just expect + # this to get ironed out over time. + # + # Thank you! -Xarvex - libgcc - glib - libxkbcommon - freetype - binutils - dbus - coreutils - libGL - libGLU - fontconfig - xorg.libxcb + name = "TagStudio"; - # this is for the shellhook portion - makeWrapper - bashInteractive - ] ++ [ - qt6Pkgs.qt6.qtbase - qt6Pkgs.qt6.full - qt6Pkgs.qt6.qtwayland - qt6Pkgs.qtcreator + dotenv.disableHint = true; - # this is for the shellhook portion - qt6Pkgs.qt6.wrapQtAppsHook - ]; + # Derived from previous flake iteration. + packages = (with pkgs; [ + cmake + binutils + coreutils + dbus + fontconfig + freetype + gdb + glib + libGL + libGLU + libgcc + libxkbcommon + mypy + ruff + xorg.libxcb + zstd + ]) + ++ (with qt6Pkgs; [ + qt6.full + qt6.qtbase + qt6.qtwayland + qtcreator + ]); - # Run after the virtual environment is created - postVenvCreation = '' - unset SOURCE_DATE_EPOCH + enterShell = + let + setQtEnv = pkgs.runCommand "set-qt-env" + { + buildInputs = with qt6Pkgs.qt6; [ + qtbase # Needed by wrapQtAppsHook. + wrapQtAppsHook + ]; + nativeBuildInputs = with pkgs; [ makeShellWrapper ]; + } + '' + makeShellWrapper "$(type -p sh)" "$out" "''${qtWrapperArgs[@]}" + sed "/^exec/d" -i "$out" + ''; + in + '' + source ${setQtEnv} + ''; - 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 - ''; + scripts.tagstudio.exec = '' + python ${cfg.devenv.root}/tagstudio/tag_studio.py + ''; - # set the environment variables that Qt apps expect - postShellHook = '' - unset SOURCE_DATE_EPOCH + env = { + QT_QPA_PLATFORM = "wayland;xcb"; - 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[@]}" + # Derived from previous flake iteration. + # Not desired given LD_LIBRARY_PATH pollution. + # See supposed alternative below, further research required. + LD_LIBRARY_PATH = lib.makeLibraryPath ( + (with pkgs; [ + dbus + fontconfig + freetype + gcc-unwrapped + glib + libglvnd + libkrb5 + libpulseaudio + libxkbcommon + stdenv.cc.cc.lib + xorg.libxcb + zlib + zstd + ]) + ++ (with qt6Pkgs.qt6; [ + qtbase + qtwayland + full + ]) + ); + }; - echo Activating Virtual Environment - source $venvDir/bin/activate - export PYTHONPATH=$PWD/$venvDir/${pkgs.python312Full.sitePackages}:$PYTHONPATH + languages.python = { + enable = true; + venv = { + enable = true; + quiet = true; + requirements = + let + excludeDeps = req: deps: builtins.concatStringsSep "\n" + (builtins.filter (line: !(lib.any (elem: lib.hasPrefix elem line) deps)) + (lib.splitString "\n" req)); + in + '' + ${builtins.readFile ./requirements.txt} + ${excludeDeps (builtins.readFile ./requirements-dev.txt) [ + "mypy" + "ruff" + ]} + ''; + }; - exec "$bashdir/bash" - ''; + # Should be able to replace LD_LIBRARY_PATH? + # Was not quite able to get working, + # will be consulting cachix community. -Xarvex + # libraries = with pkgs; [ ]; + }; + }; + }; + }; }; - }; } From 750cbf0f9ce848d321237f36a6837b1d5961b35f Mon Sep 17 00:00:00 2001 From: xarvex Date: Thu, 29 Aug 2024 19:32:30 -0500 Subject: [PATCH 2/5] fix(flake): add missing media dependencies Fixes: #417 Did not opt for setting VDPAU_DRIVER, should be done on user side See: https://wiki.archlinux.org/title/Hardware_video_acceleration#Configuring_VA-API --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index cef5574a..50689b6d 100644 --- a/flake.nix +++ b/flake.nix @@ -124,7 +124,9 @@ libpulseaudio libxkbcommon stdenv.cc.cc.lib + wayland xorg.libxcb + xorg.libXrandr zlib zstd ]) From 4b35df0924aad2e5f0394aff3010dbe5b84ceda5 Mon Sep 17 00:00:00 2001 From: Florian Zier <9168602+zierf@users.noreply.github.com> Date: Fri, 30 Aug 2024 06:49:00 +0200 Subject: [PATCH 3/5] fix(flake): GPU hardware acceleration * Enable hardware acceleration for Nix devenv Section "nativeBuildInputs" needs the dependency "qt6.full" to provide hardware acceleration in QT. Library "wayland" is needed to create a proper OpenGL context under Wayland as well. Provide a check for open AMD driver and use it for VDPAU video hardware acceleration. Move "wrapQtAppsHook" to it's correct place under "nativeBuildInputs". * Add xorg.libXrandr for hardware accelerated video playback. Using libva and openssl libraries eliminates the need for a dependency on the qt6.full library. --- flake.nix | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 50689b6d..ab653ea5 100644 --- a/flake.nix +++ b/flake.nix @@ -88,10 +88,15 @@ setQtEnv = pkgs.runCommand "set-qt-env" { buildInputs = with qt6Pkgs.qt6; [ - qtbase # Needed by wrapQtAppsHook. - wrapQtAppsHook + qtbase ]; - nativeBuildInputs = with pkgs; [ makeShellWrapper ]; + + nativeBuildInputs = (with pkgs; [ + makeShellWrapper + ]) + ++ (with qt6Pkgs.qt6; [ + wrapQtAppsHook + ]); } '' makeShellWrapper "$(type -p sh)" "$out" "''${qtWrapperArgs[@]}" @@ -122,7 +127,9 @@ libglvnd libkrb5 libpulseaudio + libva libxkbcommon + openssl stdenv.cc.cc.lib wayland xorg.libxcb From bc38e568fa3da18e7a05c2931472a98a0e9ac2bc Mon Sep 17 00:00:00 2001 From: xarvex Date: Fri, 30 Aug 2024 14:44:13 -0500 Subject: [PATCH 4/5] feat(flake): remove impurity, update nix-direnv Use path as an input that can be overriden automatically when direnv is in use. nix-direnv version present in .envrc has been updated, using watch_file on the flake is already handled. --- .envrc | 11 +++++------ flake.lock | 37 +++++++++++++++++++++++++------------ flake.nix | 14 ++++++++++++-- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/.envrc b/.envrc index 5bce6abd..650d3bd6 100644 --- a/.envrc +++ b/.envrc @@ -1,10 +1,9 @@ -if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then - source_url 'https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc' 'sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=' +if ! has nix_direnv_version || ! nix_direnv_version 3.0.5; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.5/direnvrc" "sha256-RuwIS+QKFj/T9M2TFXScjBsLR6V3A17YVoEW/Q6AZ1w=" fi -watch_file flake.nix -watch_file flake.lock - -if ! use flake . --impure; then +DEVENV_ROOT_FILE="$(mktemp)" +printf %s "${PWD}" > "${DEVENV_ROOT_FILE}" +if ! use flake . --override-input devenv-root "file+file://${DEVENV_ROOT_FILE}"; then printf '%s\n' "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 fi diff --git a/flake.lock b/flake.lock index 76b655a0..c26dd0ec 100644 --- a/flake.lock +++ b/flake.lock @@ -39,11 +39,11 @@ "pre-commit-hooks": "pre-commit-hooks" }, "locked": { - "lastModified": 1724504184, - "narHash": "sha256-gP6000c2+zHKJHAxCD3BftvAjmb4CPAZamRAHNxN2MM=", + "lastModified": 1724763216, + "narHash": "sha256-oW2bwCrJpIzibCNK6zfIDaIQw765yMAuMSG2gyZfGv0=", "owner": "cachix", "repo": "devenv", - "rev": "51338b58fd666f448db7486ec145dbe52db9b829", + "rev": "1e4ef61205b9aa20fe04bf1c468b6a316281c4f1", "type": "github" }, "original": { @@ -52,6 +52,18 @@ "type": "github" } }, + "devenv-root": { + "flake": false, + "locked": { + "narHash": "sha256-d6xi4mKdjkX2JFicDIv5niSzpyI0m/Hnm8GGAIU04kY=", + "type": "file", + "url": "file:///dev/null" + }, + "original": { + "type": "file", + "url": "file:///dev/null" + } + }, "devenv_2": { "inputs": { "flake-compat": [ @@ -122,11 +134,11 @@ ] }, "locked": { - "lastModified": 1722555600, - "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", + "lastModified": 1725024810, + "narHash": "sha256-ODYRm8zHfLTH3soTFWE452ydPYz2iTvr9T8ftDMUQ3E=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", + "rev": "af510d4a62d071ea13925ce41c95e3dec816c01d", "type": "github" }, "original": { @@ -269,11 +281,11 @@ ] }, "locked": { - "lastModified": 1720642556, - "narHash": "sha256-qsnqk13UmREKmRT7c8hEnz26X3GFFyIQrqx4EaRc1Is=", + "lastModified": 1724996935, + "narHash": "sha256-njRK9vvZ1JJsP8oV2OgkBrpJhgQezI03S7gzskCcHos=", "owner": "nlewo", "repo": "nix2container", - "rev": "3853e5caf9ad24103b13aa6e0e8bcebb47649fe4", + "rev": "fa6bb0a1159f55d071ba99331355955ae30b3401", "type": "github" }, "original": { @@ -407,11 +419,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1724224976, - "narHash": "sha256-Z/ELQhrSd7bMzTO8r7NZgi9g5emh+aRKoCdaAv5fiO0=", + "lastModified": 1724819573, + "narHash": "sha256-GnR7/ibgIH1vhoy8cYdmXE6iyZqKqFxQSVkFgosBh6w=", "owner": "nixos", "repo": "nixpkgs", - "rev": "c374d94f1536013ca8e92341b540eba4c22f9c62", + "rev": "71e91c409d1e654808b2621f28a327acfdad8dc2", "type": "github" }, "original": { @@ -477,6 +489,7 @@ "root": { "inputs": { "devenv": "devenv", + "devenv-root": "devenv-root", "flake-parts": "flake-parts", "nix2container": "nix2container", "nixpkgs": "nixpkgs_3", diff --git a/flake.nix b/flake.nix index ab653ea5..86529cc1 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,11 @@ inputs = { devenv.url = "github:cachix/devenv"; + devenv-root = { + url = "file+file:///dev/null"; + flake = false; + }; + flake-parts = { url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; @@ -53,9 +58,14 @@ # # Thank you! -Xarvex - name = "TagStudio"; + devenv.root = + let + devenvRoot = builtins.readFile inputs.devenv-root.outPath; + in + # If not overriden (/dev/null), --impure is necessary. + pkgs.lib.mkIf (devenvRoot != "") devenvRoot; - dotenv.disableHint = true; + name = "TagStudio"; # Derived from previous flake iteration. packages = (with pkgs; [ From 38626ac6902cbe1988a05bf7aa13f5c88c1b3eaf Mon Sep 17 00:00:00 2001 From: xarvex Date: Sat, 31 Aug 2024 13:16:27 -0500 Subject: [PATCH 5/5] chore(direnv): update .envrc - Cleanup direnv-root file - Set filetype for vi-like editors - Format and lint according to shellcheck and shfmt --- .envrc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.envrc b/.envrc index 650d3bd6..e84ab0f8 100644 --- a/.envrc +++ b/.envrc @@ -1,9 +1,13 @@ +# vi: ft=bash + if ! has nix_direnv_version || ! nix_direnv_version 3.0.5; then - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.5/direnvrc" "sha256-RuwIS+QKFj/T9M2TFXScjBsLR6V3A17YVoEW/Q6AZ1w=" + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.5/direnvrc" "sha256-RuwIS+QKFj/T9M2TFXScjBsLR6V3A17YVoEW/Q6AZ1w=" fi -DEVENV_ROOT_FILE="$(mktemp)" -printf %s "${PWD}" > "${DEVENV_ROOT_FILE}" -if ! use flake . --override-input devenv-root "file+file://${DEVENV_ROOT_FILE}"; then +devenv_root_file="$(mktemp -t devenv-root-XXXXXXXX)" +printf %s "${PWD}" >"${devenv_root_file}" +if ! use flake . --override-input devenv-root "file+file://${devenv_root_file}"; then printf '%s\n' "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 fi +rm "${devenv_root_file}" +unset devenv_root_file