Skip to content

Commit

Permalink
🔧 Add flake.nix for creating dev shells with nix. (#1253)
Browse files Browse the repository at this point in the history
This enables user with nix installed to work on pyglotaran. The flake creates a shell with python 3.10 and virtualenv installed and installs all dependencies on first creation.
  • Loading branch information
joernweissenborn authored Feb 20, 2023
1 parent 356b934 commit 6a984fb
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pyvenv.cfg
/.venv*
/venv*
/.env/
/.direnv/
.envrc

# sensitive environment variables
.env
Expand Down
43 changes: 43 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
inputs = {
nixpkgs = {
url = "github:nixos/nixpkgs/nixos-unstable";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
};
outputs = { nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
python = pkgs.python310;
lib-path = with pkgs; lib.makeLibraryPath [
stdenv.cc.cc
];


in
rec {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
python
pre-commit
(python3.withPackages (ps: with ps; [
virtualenvwrapper
]))
];
shellHook = ''
# Augment the dynamic linker path
export "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${lib-path}"
# Setup the virtual environment if it doesn't already exist.
VENV=.venv
if test ! -d $VENV; then
virtualenv $VENV
# Install Python dependencies
pip install -r requirements_dev.txt
pip install -e .
fi
source ./$VENV/bin/activate
export PYTHONPATH=`pwd`/$VENV/${python.sitePackages}/:$PYTHONPATH
pre-commit install
'';

};
}
);
}
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ ignore = [
".sourcery.yaml",
".zenodo.json",
"codecov.yml",
"flake.nix",
"flake.lock",
"readthedocs.yml",
"requirements_dev.txt",
"tox.ini",
Expand Down

0 comments on commit 6a984fb

Please sign in to comment.