devenv icon indicating copy to clipboard operation
devenv copied to clipboard

[Python] Using the output of a derivation as a requirements.txt?

Open YPares opened this issue 1 year ago • 1 comments

To circumvent https://github.com/cachix/devenv/issues/889, I'm pre-processing some requirements.txt files with runCommand.

I've managed to do it with:

{ pkgs, ... }:

let reqs = pkgs.runCommand "genReqs" {} ''
  mkdir $out
  # Inline the imported file:
  cat ${./shared/requirements.txt} >> $out/requirements.txt
  # Remove the import:
  sed '/^-r .*/d' < ${./requirements.txt} >> $out/requirements.txt
'';
in
{
  packages = [ pkgs.stdenv pkgs.git ];

  languages.python = {
    enable = true;
    package = pkgs.python39;
    venv = {
      enable = true;
      requirements = builtins.readFile "${reqs}/requirements.txt";
    };
  };
}

but that's sort of a hack, what I'd like to do is to use the output of the derivation as the requirements. Is there a way to do this? More generally, is it possible to parameterize devenv params from nix derivations?

YPares avatar Sep 04 '24 13:09 YPares

This issue is fixed and yes, you can reference other derivations just like in Nix.

domenkozar avatar Nov 22 '25 16:11 domenkozar