Skip to content

Instantly share code, notes, and snippets.

@luochen1990
Last active February 23, 2022 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luochen1990/3f37aaa0a6a2578918c10b18e6ecdeca to your computer and use it in GitHub Desktop.
Save luochen1990/3f37aaa0a6a2578918c10b18e6ecdeca to your computer and use it in GitHub Desktop.
nix-wrap: shebang to make your Nix file into executable
#!/usr/bin/env bash
#echo '$@ = ' "$@"
nixfile="$1"; shift
#echo "nixfile =" "$nixfile"
outpath="$(nix-build --pure $nixfile)"
#echo "outpath =" "$outpath"
[ $# -eq 0 ] && echo "Available subcommands:" $(ls "$outpath/bin") && exit 0
cmd="$1"; shift
#echo "cmd =" "$cmd"
#for ARG in "$@"; do
# echo "ARG =" $ARG
#done
exec "$outpath/bin/$cmd" "$@"
#!/usr/bin/env nix-wrap
# Usages:
#$ ./venv.nix bash
#$ nix run -f ./venv.nix '' -- -c 'python --version'
#$ nix run -f ./venv.nix ''
#$ nix bundle -f ./venv.nix
let
makeOverridable = f: f {} // { override = y: makeOverridable (x: f (x // y)); };
in
makeOverridable ({ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/c9a97ff47bb0db44f4a504015a5d1cedb3094c85.tar.gz") {} }:
pkgs.buildFHSUserEnv {
name = "bash";
targetPkgs = pkgs: (with pkgs; [
python37
python37Packages.pip
python37Packages.virtualenv
pythonManylinuxPackages.manylinux2014Package
]);
profile = ''
python3 -m venv ${builtins.toString ./.venv-py37}
source ${builtins.toString ./.venv-py37/bin/activate}
'';
runScript = "bash";
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment