Skip to content

Instantly share code, notes, and snippets.

@silverjam
Created March 5, 2018 22:38
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 silverjam/eb99f52df26e60879084de49ca3da70a to your computer and use it in GitHub Desktop.
Save silverjam/eb99f52df26e60879084de49ca3da70a to your computer and use it in GitHub Desktop.
{ pkgs ? import <nixpkgs> {} }:
let fhs = pkgs.buildFHSUserEnv {
name = "piksi-env";
targetPkgs = pkgs: with pkgs; [
bash
bc
bison
bzip2
cacert
ccache
cmake
coreutils
cpio
curl
db
file
flex
gcc6
git
gnumake
gnugrep
gnused
gnutar
mercurial
ncurses
ncurses.dev
openssl
openssl.dev
patch
perl
python27Full
readline
readline.dev
rsync
sqlite
sqlite.dev
unzip
wget
which
xz
zlib
vim
];
multiPkgs = pkgs: with pkgs; [
# zlib
];
runScript = "bash";
# We need to disable the gcc hardening that's enabled by default in the gcc
# wrapper for NixOS, otherwise it'll cause packages to fail to compile in the
# nix-shell environment.
#
# References:
# - https://szibele.com/developing-software-on-nixos/
# - https://github.com/NixOS/nixpkgs/issues/18995
#
# So we add hardeningDisable=all to the shell environment or we add it as an
# argument to the mkDerivation call (however, since buildFHSUserEnv doesn't
# understand this argument, it's added to the bash environement).
profile = ''
# buildFHSUserEnv seems to export NIX_CFLAGS_COMPILE and NIX_LDFLAGS_BEFORE
# but the cc-wrapper wants a var that includes a marker for the build
# triplet that it's wrapping:
#
export NIX_x86_64_unknown_linux_gnu_CFLAGS_COMPILE=$NIX_CFLAGS_COMPILE
export NIX_x86_64_unknown_linux_gnu_LDFLAGS_BEFORE=$NIX_LDFLAGS_BEFORE
# Make sure buildroot Python loads dynamic modules from the right place
export LD_LIBRARY_PATH=$PWD/buildroot/output/host/usr/lib
# See note about hardeningDisable above
export hardeningDisable=all
# This is intended to be picked up by PS1 to mark that this is a subshell
export debian_chroot='piksi-nix'
# Workaround issus with SSL cert store not being propegrated for some
# reason, per:
#
# - https://github.com/NixOS/nixpkgs/issues/8534
# - https://github.com/NixOS/nixpkgs/issues/3382
#
export GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt
export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
'';
};
in pkgs.stdenv.mkDerivation rec {
name = "piksi-buildroot-env";
nativeBuildInputs = [ fhs ];
buildInputs = [ ];
env = pkgs.buildEnv { name = name; paths = buildInputs; ignoreCollisions = true; };
#installPhase = ''
# echo preShellHook
# mkdir -p $out/lib
# ln -s ${pkgs.ncurses.out}/lib/libncursesw.so.5 $out/lib/libtinfo.so.5
#'';
shellHook = ''
mkdir -p $out/lib
ln -s ${pkgs.ncurses.out}/lib/libncursesw.so.5 $out/lib/libtinfo.so.5
exec piksi-env
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment