NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.28k stars 13.54k forks source link

Unable to add / run packages with pixi #316443

Open skyl4b opened 3 months ago

skyl4b commented 3 months ago

Describe the bug

I've been trying out the pixi package manager from prefix.dev on NixOS and I can't seem to use any packages installed with it. To the best of my knowledge, this is because it is based on the conda ecosystem, therefore requiring a FHS environment.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Enter a Nix shell with the pixi package available
    nix shell nixpkgs#pixi
  2. Create an empty directory for pixi
    mkdir pixi-test
  3. Initialize the directory
    cd pixi-test && pixi init
  4. Add the python package (for example)
    pixi add python
  5. Error from NixOS cannot run unpatched binaries
    [user@system:/tmp/pixi-test]$ pixi add python
    × Querying Python at `/tmp/pixi-test/.pixi/envs/default/bin/python3.12` failed with status exit status: 127 with exit status: 127
    │ --- stdout:
    │
    │ --- stderr:
    │ Could not start dynamically linked executable: /tmp/pixi-test/.pixi/envs/default/bin/python3.12
    │ NixOS cannot run dynamically linked executables intended for generic
    │ linux environments out of the box. For more information, see:
    │ https://nix.dev/permalink/stub-ld
    │ ---

Expected behavior

The package is added properly and is available with pixi shell.

It seems to me that pixi requires a similar workflow as conda with nix, therefore expecting an FHS user environment created with a pixi-shell command (or similar, since it's a bit confusing). Inside this environment, it should be possible to add / execute packages.

Additional context

I have a limited experience with Nix. If I am wrong about this, I would appreciate some suggestions / criticism.

Notify maintainers

@aaronjheng @edmundmiller

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.32, NixOS, 24.11 (Vicuña), 24.11.20240529.ad57eef`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - nixpkgs: `/nix/store/qgbn0imyridkb9527v6gnv6z3jzzprb9-source`

Add a :+1: reaction to issues you find important.

aaronjheng commented 3 months ago

I'm sorry you have this problem. I don't use NixOS. Hope someone can solve it.

jonas-w commented 3 months ago

It seems to me that pixi requires a similar workflow as conda with nix, therefore expecting an FHS user environment created with a pixi-shell command (or similar, since it's a bit confusing). Inside this environment, it should be possible to add / execute packages.

Yes, correct. I just solved this by first creating a nix FHS shell, with the following flake.nix:

{
  description = "pixi env";
  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
  };
  outputs =
    { flake-utils, nixpkgs, ... }:
    flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = import nixpkgs { inherit system; };
        fhs = pkgs.buildFHSUserEnv {
          name = "pixi-env";

          targetPkgs = _: [ pkgs.pixi ];
        };
      in
      {
        devShell = fhs.env;
      }
    );
}

Drop this in your python project, and then execute nix develop. (You'll need flake support activated) This is the same way I use conda/micromamba.

I also have not that much experience with NixOS, but I don't think that this can be solved in the pixi package itself.

carschandler commented 1 month ago

Any packages you install outside of nix that include pre-compiled binaries are going to give you trouble on NixOS. pixi is really just a little package manager has no concept of nix's inner workings. FHS environment should be a viable solution in theory, but I always ended up having trouble with it back when I tried it with micromamba. Another viable option is nix-ld/nix-ld-rs; it's working nicely for me... depending on what packages you're using, you may need to add some libraries to programs.nix-ld.libraries (I needed to add pkgs.libGL for one of my projects). Including this in your system configuration should get you started:

programs = {
  nix-ld = {
    enable = true;
    package = pkgs.nix-ld-rs;
    libraries = [
      # pkgs.libGL, any other libraries your code may need...
      # See nix-alien and nix-autobahn for help finding which 
      # libraries you need to install... not sure the best way
      # to use these to find required libraries for Python packages
    ];
  };
};
jennydaman commented 19 hours ago

I prefer using pkgs.buildFHSUserEnv to wrap pixi installed using home-manager (so that I don't have to use nix develop and bash).

Here's what I did:

{ lib, pkgs, ... }:
{
  home.packages = [
    (pkgs.buildFHSUserEnv {
      name = "pixi";
      runScript = "pixi";
      targetPkgs = pkgs: with pkgs; [ pixi ];
    })
  ];
}