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 5054606
Show file tree
Hide file tree
Showing 2 changed files with 10 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;
};
}
}
9 changes: 7 additions & 2 deletions src/modules/languages/python.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
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 +39,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 +118,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 5054606

Please sign in to comment.