Skip to content

Instantly share code, notes, and snippets.

@agoose77
Last active April 8, 2024 13:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save agoose77/9c63dc19d8671455cc6faae01228f485 to your computer and use it in GitHub Desktop.
Save agoose77/9c63dc19d8671455cc6faae01228f485 to your computer and use it in GitHub Desktop.
Python virtualenvironment flake
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = inputs @ {
self,
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
envWithScript = script:
(pkgs.buildFHSUserEnv {
name = "python-env";
targetPkgs = pkgs: (with pkgs; [
python3
python3Packages.pip
python3Packages.virtualenv
# Support binary wheels from PyPI
pythonManylinuxPackages.manylinux2014Package
# Enable building from sdists
cmake
ninja
gcc
pre-commit
]);
runScript = "${pkgs.writeShellScriptBin "runScript" (''
set -e
test -d .nix-venv || ${pkgs.python3.interpreter} -m venv .nix-venv
source .nix-venv/bin/activate
set +e
''
+ script)}/bin/runScript";
})
.env;
in {
devShell = envWithScript "bash";
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment