Last active
February 4, 2025 05:26
-
-
Save pmarreck/9d86fe4375826e76cf136d3c08eceafe to your computer and use it in GitHub Desktop.
A basic flake.nix file for cross-platform Python projects. Use with "nix develop". pip, etc. should work via venv.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "A flake for pythonification"; | |
inputs = { | |
nixpkgs.url = "github:nixos/nixpkgs"; | |
flake-utils.url = "github:numtide/flake-utils"; | |
}; | |
outputs = { self, nixpkgs, flake-utils, ... }@inputs: | |
flake-utils.lib.eachSystem ["x86_64-darwin" "aarch64-darwin" "x86_64-linux" "aarch64-linux"] (system: | |
let | |
pkgs = import nixpkgs { inherit system; }; | |
pythonPackages = pkgs.python3Packages; | |
venvDir = "./env"; | |
runPackages = with nixpkgs; [ | |
pythonPackages.python | |
pythonPackages.venvShellHook | |
]; | |
devPackages = with nixpkgs; runPackages ++ [ | |
pythonPackages.pylint | |
pythonPackages.flake8 | |
pythonPackages.black | |
]; | |
postShellHook = '' | |
PYTHONPATH=\$PWD/\${venvDir}/\${pythonPackages.python.sitePackages}/:\$PYTHONPATH | |
''; | |
in { | |
runShell = pkgs.mkShell { | |
inherit venvDir; | |
name = "pythonify-run"; | |
packages = runPackages; | |
postShellHook = postShellHook; | |
}; | |
devShells = { | |
default = pkgs.mkShell { | |
inherit venvDir; | |
name = "pythonify-dev"; | |
packages = devPackages; | |
postShellHook = postShellHook; | |
}; | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you copy this into an existing non-Nixified git-cloned python project, remember to "git add flake.nix" or it won't be "seen".
Also, may need to modify based on your particular requirements.
I haven't tried it yet on linux, but it works on macOS.
You access it/drop into its environment via
nix develop
.I'm not 100% sure about the "runShell" definition. May need to modify this for runs and builds that are not "development", such as if you want any build products to be available on your PATH from elsewhere. (Happy to take recommendations here!)