-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
73 lines (64 loc) · 2.04 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{ isDevelopment ? true }:
let
# Update packages with `nixpkgs-update` command
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/9299cdf978e15f448cf82667b0ffdd480b44ee48.tar.gz") { };
pythonLibs = with pkgs; [
stdenv.cc.cc.lib
zlib.out
];
# Override LD_LIBRARY_PATH to load Python libraries
python' = with pkgs; symlinkJoin {
name = "python";
paths = [ python313 ];
buildInputs = [ makeWrapper ];
postBuild = ''
wrapProgram "$out/bin/python3.13" --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath pythonLibs}"
'';
};
packages' = with pkgs; [
coreutils
python'
poetry
ruff
pyright
watchexec
(writeShellScriptBin "run-tests" ''
set -e
python -m pytest . \
--verbose \
--no-header \
--cov starlette_compress \
--cov-report "''${1:-xml}"
pyright
'')
(writeShellScriptBin "watch-tests" "watchexec --watch starlette_compress --watch tests --exts py run-tests")
(writeShellScriptBin "nixpkgs-update" ''
set -e
hash=$(
curl --silent --location \
https://prometheus.nixos.org/api/v1/query \
-d "query=channel_revision{channel=\"nixpkgs-unstable\"}" | \
grep --only-matching --extended-regexp "[0-9a-f]{40}")
sed -i -E "s|/nixpkgs/archive/[0-9a-f]{40}\.tar\.gz|/nixpkgs/archive/$hash.tar.gz|" shell.nix
echo "Nixpkgs updated to $hash"
'')
];
shell' = with pkgs; lib.optionalString isDevelopment ''
current_python=$(readlink -e .venv/bin/python || echo "")
current_python=''${current_python%/bin/*}
[ "$current_python" != "${python'}" ] && rm -rf .venv/
echo "Installing Python dependencies"
export POETRY_VIRTUALENVS_IN_PROJECT=1
poetry env use "${python'}/bin/python"
poetry install --compile
echo "Activating Python virtual environment"
source .venv/bin/activate
# Development environment variables
export PYTHONNOUSERSITE=1
export TZ=UTC
'';
in
pkgs.mkShell {
buildInputs = packages';
shellHook = shell';
}