forked from Zaczero/CBBI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.nix
74 lines (64 loc) · 2.06 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
74
{ isDevelopment ? true }:
let
# Currently using nixpkgs-unstable
# Update with `nixpkgs-update` command
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/a3ed7406349a9335cb4c2a71369b697cecd9d351.tar.gz") { };
libraries' = with pkgs; [
# Base libraries
stdenv.cc.cc.lib
zlib.out
];
# Wrap Python to override LD_LIBRARY_PATH
wrappedPython = with pkgs; (symlinkJoin {
name = "python";
paths = [ python312 ];
buildInputs = [ makeWrapper ];
postBuild = ''
wrapProgram "$out/bin/python3.12" --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath libraries'}"
'';
});
packages' = with pkgs; [
# Base packages
wrappedPython
] ++ lib.optionals isDevelopment [
# Development packages
poetry
ruff
# Scripts
# -- Misc
(writeShellScriptBin "nixpkgs-update" ''
set -e
hash=$(git ls-remote https://github.com/NixOS/nixpkgs nixpkgs-unstable | cut -f 1)
sed -i -E "s|/nixpkgs/archive/[0-9a-f]{40}\.tar\.gz|/nixpkgs/archive/$hash.tar.gz|" shell.nix
echo "Nixpkgs updated to $hash"
'')
(writeShellScriptBin "docker-build-push" ''
set -e
if command -v podman &> /dev/null; then docker() { podman "$@"; } fi
docker push $(docker load < $(nix-build --no-out-link) | sed -En 's/Loaded image: (\S+)/\1/p')
'')
];
shell' = with pkgs; lib.optionalString isDevelopment ''
current_python=$(readlink -e .venv/bin/python || echo "")
current_python=''${current_python%/bin/*}
[ "$current_python" != "${wrappedPython}" ] && rm -r .venv
echo "Installing Python dependencies"
export POETRY_VIRTUALENVS_IN_PROJECT=1
poetry env use "${wrappedPython}/bin/python"
poetry install --no-root --compile
echo "Activating Python virtual environment"
source .venv/bin/activate
# Development environment variables
export PYTHONNOUSERSITE=1
if [ -f .env ]; then
echo "Loading .env file"
set -o allexport
source .env set
+o allexport
fi
'';
in
pkgs.mkShell {
buildInputs = packages';
shellHook = shell';
}