How to install a Python package with optional dependencies? I.e. with pip I would do pip install httpx[cli] but how to do that with flox? Running flox install nixpkgs#python310Packages.httpx does not install the optional dependencies (as expected)?
edit: After I got some help from #nixos IRC, I tried flox install nixpkgs#python310Packages.httpx.optional-dependencies.cli which errors with error: value is a list while a set was expected.
edit2: Maybe this is a case where editing a more declarative config would make sense?
This is actually an issue that I had to deal with recently with Python packages in the flox CLI. This is something we’re hoping to improve in the future, but the good news is that I can probably help you out.
You’re right that you’re going to need to make a declaration for this - for two reasons.
The optional-dependencies.cli value is a list of derivations, not single derivation. So if you want all of them you’ll need to “link”/join
The CLI currently won’t let you access sub-attributes easily .
So you’ll want to create a flox.nix file ( flox init -t project; ) and add the following file to ./pkgs/httpx-cli/default.nix:
Could you share the contents of your flox.nix file?
Also can you confirm that the path is exactly ./pkgs/httpx-cli/default.nix? The “name” of the package matches the folder name, so a different name could cause this failure.
I did not touch flox.nix after flox init -t project so the contents are:
{
# flox environment
#
# To learn basics about flox commands see:
# https://floxdev.com/docs/basics
#
# Check other options you can configure in this file:
# https://floxdev.com/docs/reference/flox-nix-config
#
# Get help:
# https://discourse.flox.dev
#
# Happy hacking!
# Look for more packages with `flox search` command.
#packages.nixpkgs-flox.go = {};
#packages.nixpkgs-flox.nodejs = {}
# Set environment variables
#environmentVariables.LANG = "en_US.UTF-8";
# Run shell hook when you enter flox environment
#shell.hook = ''
# echo "Welcome to flox environment"
#'';
}
and I triple-checked the folder name as I suspected that as well: