Last active
July 10, 2022 05:24
-
-
Save aabs/fba5cd1a8038fb84a46909250d34a5c1 to your computer and use it in GitHub Desktop.
A simple nix-shell script to establish an environment for Phoenix, Elixir and PostgreSQL development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ nixpkgs ? import <nixpkgs> {} | |
, version ? "0.1" | |
, proxy ? "http://10.183.23.58:3128" | |
}: | |
with nixpkgs; | |
let | |
elixir = beam.packages.erlangR21.elixir_1_7; | |
nodejs = nodejs-10_x; | |
postgresql = postgresql100; | |
deps = | |
[ elixir | |
nodejs | |
git | |
postgresql | |
glibcLocales | |
fish | |
neovim | |
vimPlugins.spacevim | |
inotify-tools | |
]; | |
env = buildEnv { | |
name = "ex-build-environment"; | |
paths = deps; | |
}; | |
in | |
stdenv.mkDerivation rec { | |
name = "ex-${version}"; | |
buildInputs = [ env ]; | |
phases = ["nobuild"]; | |
postPatch = "patchShebangs ."; | |
preConfigure = '' | |
echo Running preConfigure... | |
echo ${version} > VERSION | |
((git log -1 --pretty=format:"%H") || echo dirty) > GIT_COMMIT_ID | |
./boot | |
''; | |
HTTP_PROXY = "${proxy}"; | |
HTTPS_PROXY = "${proxy}"; | |
http_proxy = "${proxy}"; | |
https_proxy = "${proxy}"; | |
shellHook = '' | |
# "nix-shell --pure" resets LANG to POSIX, this breaks "make TAGS". | |
export LANG="en_US.UTF-8" | |
export PGDATA="$PWD/db" | |
mix local.hex | |
mix archive.install hex phx_new 1.4.0 | |
''; | |
enableParallelBuilding = true; | |
stripDebugFlags = [ "-S" ]; | |
# Without this, we see a whole bunch of warnings about LANG, LC_ALL and locales in general. | |
# In particular, this makes many tests fail because those warnings show up in test outputs too... | |
# The solution is from: https://github.com/NixOS/nix/issues/318#issuecomment-52986702 | |
LOCALE_ARCHIVE = if stdenv.isLinux then "${glibcLocales}/lib/locale/locale-archive" else ""; | |
nobuild = '' | |
echo Do not run this derivation with nix-build, it can only be used with nix-shell | |
''; | |
} |
Owe you a beer/nutella/etc for the locale-archive
solution! Don't know how long it took you to track it down, but it made my life easier.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
nix-shell --pure
to enter shell with no environment leakage...