DavHau / mach-nix

Create highly reproducible python environments
MIT License
869 stars 106 forks source link

Overriding nixpkgs and R when `mach-nix` used as a flake #429

Open EmperorDali opened 2 years ago

EmperorDali commented 2 years ago

My apologies, this may not be an issue with mach-nix but rather me using it incorrectly. I'd be happy to contribute an example configuration if this is just me using things incorrectly.

I'm configuring a development environment that uses mach-nix via flakes. My flake.nix looks like:

  inputs = {
    mach-nix.url = "mach-nix/3.4.0";
  };

  outputs = { self, nixpkgs, mach-nix }:
      let
        l = nixpkgs.lib // builtins;
        supportedSystems = [ "x86_64-linux" "x86_64-darwin" ];
        forAllSystems = f: l.genAttrs supportedSystems
          (system: f system (import nixpkgs {inherit system;}));
      in
        {
          devShell = forAllSystems (system: pkgs:
            let
              python-env = mach-nix.lib."${system}".mkPython {
                python = "python39";
                requirements = ''
numpy
scipy
...
'';
              };
            in
              pkgs.mkShell {
                buildInputs =  [
                  python-env
                ];
              });
        };
}

This version of the flake works great, but I'm having some trouble extending and overriding various attributes.

  1. What's the correct way to make sure that my flake and the mach-nix flake both use the same version of nixpkgs? I tried adding inputs.mach-nix.inputs.nixpkgs.follows = "nixpkgs" to my flake, but then nix develop errors with
    • error: The pypiDataRev seems to be older than the nixpkgs which is currently used. Because of this, mach-nix might lack dependency information for some python packages in nixpkgs. This can degrade the quality of the generated environment or result in failing builds. It is recommended to pass a newer pypiDataRev to mach-nix during import. For flakes users: Update the pypi-deps-db input of mach-nix.

      • I tried also setting inputs.mach-nix.inputs.pypi-deps-db.inputs.nixpkgs.follows = "nixpkgs"; but the error persisted.
  2. What's the correct way to override the version of R that's used by mach-nix when installing rpy2? I have an R environment defined in my flake that's of the form nixpkgs.rWrapper.override { packages = [ myRPackages ]; } and I'd like to pass this R to rpy2 in my mach-nix mkPython call. If this isn't possible, what would be the recommended way to get both R and a mach-nix python environment with rpy2 that shares the same set of R packages?
charlesbaynham commented 2 years ago

I have a similar confusion. Trying to follow this advice: For flakes users: Update the pypi-deps-db input of mach-nix., I run nix flake update. However I find that this updates my mach-nix dependency, but not mach-nix's dependency on pypi-deps-db, which remains pinned to whatever it was in the flake.lock file of mach-nix.

jamesdbrock commented 2 years ago

When I add inputs.pypi-deps-db.follows = "nixpkgs"; to this template

    pypi-deps-db = {
      url = "github:DavHau/pypi-deps-db";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.mach-nix.follows = "mach-nix";
      follows = "nixpkgs";
    };

then it seems to solve the “error: The pypiDataRev seems to be older than the nixpkgs which is currently used.” (But then I have other errors).

G3zz commented 1 year ago

This is probably a stale issue by now, but I just came into this issue myself and it seems like pypi-deps-db has stopped updating: https://github.com/DavHau/pypi-deps-db/issues/16. For me, pinning to a nix package version before 8th December 2022 works.