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

file collisions in public.pyEnv #1071

Open
jian-lin opened this issue Nov 15, 2024 · 2 comments · May be fixed by #1073
Open

file collisions in public.pyEnv #1071

jian-lin opened this issue Nov 15, 2024 · 2 comments · May be fixed by #1073

Comments

@jian-lin
Copy link
Member

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

@DavHau
Copy link
Member

DavHau commented Nov 19, 2024

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

I guess the removal of ignoreCollisions must have slipped in somehow. Feel free to open a PR enabling it again.

jian-lin added a commit to linj-fork/dream2nix that referenced this issue Nov 19, 2024
@jian-lin jian-lin linked a pull request Nov 19, 2024 that will close this issue
@jian-lin
Copy link
Member Author

@DavHau I created #1073, PTAL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants