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

Make it possible to use .withPackages and .pkgs #26

Merged
merged 2 commits into from
Jan 11, 2024

Conversation

ento
Copy link
Contributor

@ento ento commented Nov 30, 2023

I got hit by both #12 and the error noted in #14.

I added builtins.trace to various places and observed that...

error: function 'anonymous lambda' called with unexpected argument 'x11Support'

In my case, this was coming from tkinter, and python.override.__functionArgs at that point was an attribute set of ["nixpkgs-python", "version"]. My understanding is callPackage ./self.nix { inherit version; } returns an overrideable version of the function defined in self.nix, and that's being passed down as the python object. I changed it to use the bare packages.${version} instead, but I'm not sure if that breaks something else.

error: builder for '/nix/store/jwc3cbbp74lc3krq8ilkhgd7izg8bdxd-Python-3.8.17.tar.xz.drv' failed with exit code 1;

i.e. src and hash not getting overriden - I traced it down to this call chain:

/nix/store/yag8q0cdid0wljdkkzzkfg61y8azsj1c-xs5pk051y9dahjl2n28rsppq8fajz125-source/pkgs/development/interpreters/python/hooks/default.nix
  pythonInterpreter = super.python.pythonForBuild.interpreter;

/nix/store/yag8q0cdid0wljdkkzzkfg61y8azsj1c-xs5pk051y9dahjl2n28rsppq8fajz125-source/pkgs/development/interpreters/python/passthrufun.nix
    pythonForBuild = pythonOnBuildForHost.override { inherit packageOverrides; self = pythonForBuild; };

/nix/store/yag8q0cdid0wljdkkzzkfg61y8azsj1c-xs5pk051y9dahjl2n28rsppq8fajz125-source/pkgs/development/interpreters/python/cpython/default.nix
    pythonOnBuildForHost = override pkgsBuildHost.${pythonAttr};

..and I forcefully replaced pkgsBuildHost with an attrset with ${pythonAttr} set to nixpkgs-python's Python package, which worked, but I'm not sure if that's the right or the cleanest way.

Also needed to use newScope to make packages under xorg available in callPackage calls, e.g. xorgproto.

A slightly stripped down version of a `flake.nix` that I wanted to use `withPackage` with, which now works with this patch

{
  description = "Description for the project";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nixpkgs-python.url = "github:ento/nixpkgs-python/with-packages-fix";
    devenv.url = "github:cachix/devenv";
    nix2container.url = "github:nlewo/nix2container";
    nix2container.inputs.nixpkgs.follows = "nixpkgs";
    mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
  };

  nixConfig = {
    extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
    extra-substituters = "https://devenv.cachix.org";
  };

  outputs = inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [
        inputs.devenv.flakeModule
      ];
      systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];

      perSystem = { config, self', inputs', pkgs, system, lib, ... }:
        let
          pythonVersions = [
            "3.8"
            "3.9"
            "3.10"
            "3.11"
          ];
          mkShell = v:
            let
              isDefaultPython = v == (lib.versions.majorMinor pkgs.python3.version);
              python =
                if isDefaultPython then
                  pkgs.python3
                else
                  inputs'.nixpkgs-python.packages.${v};
              pythonPackages = ps: with ps; [
                build
                pip-tools
                tox
                twine
              ];
              pythonWithPackages = (python.withPackages pythonPackages);
              shell = {
                name = v;
                packages = [
                  pkgs.pre-commit
                  python.pkgs.wrapPython
                ];
                languages.python.enable = true;
                languages.python.version = v;
                languages.python.package = lib.mkForce pythonWithPackages;
              };
            in
              [ { name = lib.replaceStrings ["."] [""] v; value = shell; } ]
              ++ (lib.optionals isDefaultPython [ { name = "default"; value = shell; }]);
        in {
        devenv.shells = lib.trivial.pipe pythonVersions [
          (map mkShell)
          lib.flatten
          lib.listToAttrs
        ];
      };
    };
}
nix develop .#310 --impure

ento added 2 commits November 29, 2023 18:34
This may not cover *all* references, and overwriting pkgsBuildHost
like this feels wrong
@domenkozar domenkozar merged commit cd1f364 into cachix:main Jan 11, 2024
@domenkozar
Copy link
Member

Thank you ❤️

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 this pull request may close these issues.

2 participants