Skip to content

Commit

Permalink
languages.python.venv.requirements can be a path
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Aug 7, 2023
1 parent 81e7928 commit c027ecb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions examples/python/devenv.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{ pkgs, lib, ... }:
{ pkgs, ... }:

{
languages.python = {
enable = true;
version = "3.11.3";

venv.enable = true;
venv.requirements = lib.readFile ./requirements.txt;
venv.requirements = ./requirements.txt;
};
}
}
10 changes: 8 additions & 2 deletions src/modules/languages/python.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
let
cfg = config.languages.python;

requirements = pkgs.writeText "requirements.txt" (
if lib.isPath cfg.venv.requirements
then builtins.readFile cfg.venv.requirements
else cfg.venv.requirements
);

nixpkgs-python = inputs.nixpkgs-python or (throw ''
To use languages.python.version, you need to add the following to your devenv.yaml:
Expand Down Expand Up @@ -34,7 +40,7 @@ let
fi
source "$VENV_PATH"/bin/activate
${lib.optionalString (cfg.venv.requirements != null) ''
"$VENV_PATH"/bin/pip install -r ${pkgs.writeText "requirements.txt" cfg.venv.requirements}
"$VENV_PATH"/bin/pip install -r ${requirements}
''}
'';

Expand Down Expand Up @@ -113,7 +119,7 @@ in
venv.enable = lib.mkEnableOption "Python virtual environment";

venv.requirements = lib.mkOption {
type = lib.types.nullOr lib.types.lines;
type = lib.types.nullOr (lib.types.either lib.types.lines lib.types.path);
default = null;
description = ''
Contents of pip requirements.txt file.
Expand Down

0 comments on commit c027ecb

Please sign in to comment.