Skip to content

Instantly share code, notes, and snippets.

@aabs
Last active Jul 10, 2022
Embed
What would you like to do?
A simple nix-shell script to establish an environment for Phoenix, Elixir and PostgreSQL development
{ 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
'';
}
@aabs
Copy link
Author

aabs commented Jan 14, 2019

Use nix-shell --pure to enter shell with no environment leakage...

@toraritte
Copy link

toraritte commented Jul 15, 2019

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