{
description = "virtual environment with python and streamlit";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
python=pkgs.python311;
f = ps: with ps;[
ipython
matplotlib
pandas
];
pip_python_packages= python.withPackages(f);
myDevTools = [
pip_python_packages
pkgs.streamlit
];
outputName = builtins.attrNames self.outputs self.outputs;
in {
devShells.default = pkgs.mkShell {
buildInputs = myDevTools;
};
packages.default = pkgs.poetry2nix.mkPoetryApplication {
projectDir = self;
};
apps.default = {
program = "${python}/bin/python";
args = [ "main.py" ];
src = "./.";
type = "app";
};
});
}
the command nix run "works". Not as intended, it opens only the python interpreter but this is another question.
But the command nix run doesn't work
error: … while evaluating the attribute 'pkgs.buildPythonPackage'
at /nix/store/s1z7nb9n6r5n0r34fabp6yybwkbr8mjk-source/pkgs/development/interpreters/python/passthrufun.nix:87:5: 86| withPackages = import ./with-packages.nix { inherit buildEnv pythonPackages;}; 87| pkgs = pythonPackages; | ^ 88| interpreter = "${self}/bin/${executable}"; … while calling the 'mapAttrs' builtin at /nix/store/s1z7nb9n6r5n0r34fabp6yybwkbr8mjk-source/pkgs/development/interpreters/python/passthrufun.nix:31:8: 30| value; 31| in lib.mapAttrs func items; | ^ 32| in ensurePythonModules (callPackage (stack trace truncated; use '--show-trace' to show the full trace) error: getting status of '/nix/store/ggvg85rp5qzyr9bngsl6r0pcrkyxqa49-source/poetry.lock': No
such file or directory
This error message doesn't refer to any part of my code. This is difficult to know which part causes a problem
Why 'nix run' opens the python interpreter
The 'apps' attrset in a flake only supports the 'program' and 'type' attrs. It can only be used with binaries or shell scripts. It's ignoring your args and just running 'python' with zero args. You can fix that by either creating a single binary/script to run and using that, or by using nix develop with a shellHook instead.
Why 'nix build' doesn't work
poetry.lock has most likely not been added to your git repo with 'git add.' Flakes are only aware of files that have been committed or staged in your git repository