Skip to content

Instantly share code, notes, and snippets.

@mwmdev
Last active September 27, 2024 09:51
Show Gist options
  • Select an option

  • Save mwmdev/04ce97f10cd09e3e14e57fc2328fca68 to your computer and use it in GitHub Desktop.

Select an option

Save mwmdev/04ce97f10cd09e3e14e57fc2328fca68 to your computer and use it in GitHub Desktop.
Setup script for python environment on nixos.
#!/usr/bin/env bash
# Step 1: Check if shell.nix exists; if not, create it
if [ ! -f shell.nix ]; then
cat <<'EOF' > shell.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.python3
pkgs.python3.pkgs.virtualenv
pkgs.gcc
pkgs.glibc
pkgs.git
pkgs.stdenv.cc.cc.lib
];
# Set environment variables
env = {
LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.glibc}/lib";
};
shellHook = ''
if [ ! -d ".venv" ]; then
virtualenv .venv
source .venv/bin/activate
else
source .venv/bin/activate
fi
'';
}
EOF
fi
# Step 2: Run nix-shell to enter the Nix shell environment
nix-shell
@mwmdev
Copy link
Author

mwmdev commented Sep 25, 2024

Can be executed remotely with an alias like :

alias nxpy='bash <(curl -sSL https://gist.githubusercontent.com/mwmdev/04ce97f10cd09e3e14e57fc2328fca68/raw/3c11660568bf109215b1ae41f92a58d9ddff8598/nixpy.sh)'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment