From 6a984fb9b04c55b6cfd4bf7923f094b39b7a9678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Wei=C3=9Fenborn?= Date: Mon, 20 Feb 2023 22:40:45 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Add=20flake.nix=20for=20creating?= =?UTF-8?q?=20dev=20shells=20with=20nix.=20(#1253)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .gitignore | 2 ++ flake.lock | 43 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 ++ 4 files changed, 99 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index b6b850f2c..de944d44d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ pyvenv.cfg /.venv* /venv* /.env/ +/.direnv/ +.envrc # sensitive environment variables .env diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..6f5f869b2 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1676283394, + "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1676721149, + "narHash": "sha256-mN2EpTGxxVNnFZLoLWRwh6f7UWhXy4qE+wO2CZyrXps=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5f4e07deb7c44f27d498f8df9c5f34750acf52d2", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..503f9ceb9 --- /dev/null +++ b/flake.nix @@ -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 + ''; + + }; + } + ); +} diff --git a/pyproject.toml b/pyproject.toml index 2504650ab..b5eba90ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,6 +77,8 @@ ignore = [ ".sourcery.yaml", ".zenodo.json", "codecov.yml", + "flake.nix", + "flake.lock", "readthedocs.yml", "requirements_dev.txt", "tox.ini",