Skip to content

file collisions in public.pyEnv #1071

Open
@jian-lin

Description

@jian-lin

Some packages have collisions, which makes users unable to get a devshell.

I am not sure if the collision is an issue of those packages. But I think it would be good if dream2nix could ignore them.

I can create a PR to add ignoreCollisions = true; to pyEnv, but I am not sure if it should be gated behind an option.

cc @phaer: author of #951 which removes ignoreCollisions.


To reproduce this issue, run nix build .#default.devShell in a flake with the following files and you will get this error:

error: builder for '/nix/store/q4nyhwnpm2fbxs2rxpazmh0x2njgzphq-python3-3.10.15-env.drv' failed with exit code 25;
       last 1 log lines:
       > error: collision between `/nix/store/gn08rmcymykhpjlw77mll03gcpzq0shm-python3.10-pyside6-addons-6.4.2/lib/python3.10/site-packages/PySide6/__pycache__/__init__.cpython-310.pyc' and `/nix/store/54i2003qb1lym4dqcdqc00w0fzkbk9zx-python3.10-pyside6-6.4.2/lib/python3.10/site-packages/PySide6/__pycache__/__init__.cpython-310.pyc'
# flake.nix
{
  inputs = {
    dream2nix.url = "github:nix-community/dream2nix?rev=44d41411686bc798876bd6d9f36a4c1143138d85";
    nixpkgs.follows = "dream2nix/nixpkgs";
  };

  outputs =
    {
      self,
      dream2nix,
      nixpkgs,
    }:
    let
      eachSystem = nixpkgs.lib.genAttrs [
        "aarch64-darwin"
        "aarch64-linux"
        "x86_64-darwin"
        "x86_64-linux"
      ];
    in
    {
      packages = eachSystem (system: {
        default = dream2nix.lib.evalModules {
          packageSets.nixpkgs = nixpkgs.legacyPackages.${system};
          modules = [
            ./package.nix
            {
              paths.projectRoot = ./.;
              paths.projectRootFile = "flake.nix";
              paths.package = ./.;
            }
          ];
        };
      });
      devShells = eachSystem (system: {
        default =
          let
            pkgs = nixpkgs.legacyPackages.${system};
            myPkg = self.packages.${system}.default;
          in
          pkgs.mkShell {
            inputsFrom = [ myPkg.devShell ];
          };
      });
    };
}
# package.nix

{
  config,
  lib,
  dream2nix,
  ...
}:

let
  pyproject = lib.importTOML (config.mkDerivation.src + /pyproject.toml);
in
{
  imports = [
    dream2nix.modules.dream2nix.pip
  ];

  deps =
    { nixpkgs, ... }:
    {
      python = nixpkgs.python310;
      tbb = nixpkgs.tbb_2021_11;
      inherit (nixpkgs)
        atk
        cairo
        cups
        dbus
        fetchFromGitHub
        fontconfig
        freetype
        gst_all_1
        gtk3
        krb5
        libdrm
        libxkbcommon
        pango
        pcsclite
        qt6
        wayland
        xorg
        ;
    };

  inherit (pyproject.project) name version;

  mkDerivation = {
    src = lib.cleanSourceWith {
      src = lib.cleanSource ./.;
      filter =
        name: type:
        !(builtins.any (x: x) [
          (lib.hasSuffix ".nix" name)
          (lib.hasPrefix "." (builtins.baseNameOf name))
          (lib.hasSuffix "flake.lock" name)
        ]);
    };
  };

  buildPythonPackage = {
    pyproject = true;
    pythonImportsCheck = [ "my_tool" ];
  };

  pip = {
    pipVersion = "24.3.1";
    requirementsList = pyproject.build-system.requires or [ ] ++ pyproject.project.dependencies;
    flattenDependencies = true;
    overrides = {
      pyside6-essentials = {
        mkDerivation.buildInputs = with config.deps; [
          atk
          cairo
          cups
          dbus
          fontconfig
          freetype
          gtk3
          krb5
          libdrm
          libxkbcommon
          pango
          qt6.qt3d
          qt6.qtpositioning
          qt6.qtscxml
          qt6.qtvirtualkeyboard
          qt6.qtwebengine
          wayland
          xorg.libxcb
        ];
        env = {
          dontWrapQtApps = true;
          autoPatchelfIgnoreMissingDeps = [ "libmysqlclient.so*" ];
        };
      };
      pyside6-addons = {
        mkDerivation.buildInputs = with config.deps; [
          gst_all_1.gst-plugins-base
          gst_all_1.gstreamer
          pcsclite
          qt6.qtmultimedia
        ];
        env = {
          dontWrapQtApps = true;
        };
      };
    };
  };
}
# pyproject.toml
[build-system]
requires = [ "setuptools" ]
build-backend = "setuptools.build_meta"

[project]
name = "my-tool"
description = "my tool"
version = "1.0.0"
dependencies = [
  "pyside6==6.4.2",
]

[project.scripts]
my-tool = "my_tool:main"
# src/my_tool/__init__.py

import PySide6


def main():
    print("Hello World!")

lock.x86_64-linux.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions