Skip to content

Instantly share code, notes, and snippets.

@blackgnezdo
Created November 9, 2022 00:26
Show Gist options
  • Save blackgnezdo/3eba5ac091f3d3244333d18b3bf957ad to your computer and use it in GitHub Desktop.
Save blackgnezdo/3eba5ac091f3d3244333d18b3bf957ad to your computer and use it in GitHub Desktop.
% docker run -i -t --mount type=bind,src=$PWD/examples/,dst=/examples nixos/nix:latest bash
bash-5.1# cd /examples
bash-5.1# ls
CMakeLists.txt a.cpp abseil-cpp bar.cpp build-gcc-10 build-nix foo.cpp hello_world.cc
bash-5.1# mkdir build-contained
bash-5.1# cd build-contained
bash-5.1# nix-shell -p gcc cmake
these 18 paths will be fetched (60.71 MiB download, 262.81 MiB unpacked):
/nix/store/2m2y6r15v65cxx29ibq6jqcn9ivaq2jc-cmake-3.22.3
/nix/store/35swvg68q1j3m9fbhcdnqwk9mlm8plvn-diffutils-3.8
/nix/store/4gkcrzpn31sb12fnzclyfzhpd8xh8l6x-gnumake-4.3
/nix/store/7xkdhpw90k9nclnr2svp3k92fvvmfkzx-libuv-1.44.1
/nix/store/ag2bpk0lzjvj409znklrz5krkpc5imzs-gcc-wrapper-11.3.0
/nix/store/as1xzrm2921pnxx4jvxj39jn4v88wdy1-gcc-11.3.0
/nix/store/c0hmdlwdd85gzmilafg4gzzdb2vpg176-patch-2.7.6
/nix/store/di13vk35bbbfm4gm4lrjxdnd1768db6l-expand-response-params
/nix/store/dwsi3wsqpqm0hpzdm9fsxc7q732p9xwi-glibc-2.34-210-dev
/nix/store/i8kc0p5d45lxzywl0grx9gynxa7vmi11-ed-1.18
/nix/store/jc67i0j4bxapwx50jh8kzqq0zd369b7s-rhash-1.4.2
/nix/store/k7ma6hvw11nrmjbvb7v518scxrshbg14-curl-7.83.1
/nix/store/knssayvl4p7gfapib4wcfhzy14169kva-patchelf-0.14.5
/nix/store/l4y7m2li6yw7ssbsxmr0qlgkag6z5mxa-linux-headers-5.17
/nix/store/rq6bh3qfrqnyqwik0w3q6w180zg3w2pa-binutils-2.38
/nix/store/w3p77mkdy3pigg12iyha8y9dqakhjsxn-gawk-5.1.1
/nix/store/w4yyp4pm2czqhr0078c0wwlx2dk2dzqw-stdenv-linux
/nix/store/wp7kc5y840ldi5sd8j81fj4dabccff2d-binutils-wrapper-2.38
copying path '/nix/store/di13vk35bbbfm4gm4lrjxdnd1768db6l-expand-response-params' from 'https://cache.nixos.org'...
copying path '/nix/store/rq6bh3qfrqnyqwik0w3q6w180zg3w2pa-binutils-2.38' from 'https://cache.nixos.org'...
copying path '/nix/store/k7ma6hvw11nrmjbvb7v518scxrshbg14-curl-7.83.1' from 'https://cache.nixos.org'...
copying path '/nix/store/35swvg68q1j3m9fbhcdnqwk9mlm8plvn-diffutils-3.8' from 'https://cache.nixos.org'...
copying path '/nix/store/i8kc0p5d45lxzywl0grx9gynxa7vmi11-ed-1.18' from 'https://cache.nixos.org'...
copying path '/nix/store/w3p77mkdy3pigg12iyha8y9dqakhjsxn-gawk-5.1.1' from 'https://cache.nixos.org'...
copying path '/nix/store/4gkcrzpn31sb12fnzclyfzhpd8xh8l6x-gnumake-4.3' from 'https://cache.nixos.org'...
copying path '/nix/store/7xkdhpw90k9nclnr2svp3k92fvvmfkzx-libuv-1.44.1' from 'https://cache.nixos.org'...
copying path '/nix/store/l4y7m2li6yw7ssbsxmr0qlgkag6z5mxa-linux-headers-5.17' from 'https://cache.nixos.org'...
copying path '/nix/store/c0hmdlwdd85gzmilafg4gzzdb2vpg176-patch-2.7.6' from 'https://cache.nixos.org'...
copying path '/nix/store/dwsi3wsqpqm0hpzdm9fsxc7q732p9xwi-glibc-2.34-210-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/knssayvl4p7gfapib4wcfhzy14169kva-patchelf-0.14.5' from 'https://cache.nixos.org'...
copying path '/nix/store/wp7kc5y840ldi5sd8j81fj4dabccff2d-binutils-wrapper-2.38' from 'https://cache.nixos.org'...
copying path '/nix/store/as1xzrm2921pnxx4jvxj39jn4v88wdy1-gcc-11.3.0' from 'https://cache.nixos.org'...
copying path '/nix/store/jc67i0j4bxapwx50jh8kzqq0zd369b7s-rhash-1.4.2' from 'https://cache.nixos.org'...
copying path '/nix/store/ag2bpk0lzjvj409znklrz5krkpc5imzs-gcc-wrapper-11.3.0' from 'https://cache.nixos.org'...
copying path '/nix/store/2m2y6r15v65cxx29ibq6jqcn9ivaq2jc-cmake-3.22.3' from 'https://cache.nixos.org'...
copying path '/nix/store/w4yyp4pm2czqhr0078c0wwlx2dk2dzqw-stdenv-linux' from 'https://cache.nixos.org'...
[nix-shell:/examples/build-contained]# cmake ..
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /nix/store/ag2bpk0lzjvj409znklrz5krkpc5imzs-gcc-wrapper-11.3.0/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/ag2bpk0lzjvj409znklrz5krkpc5imzs-gcc-wrapper-11.3.0/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /examples/build-contained
[nix-shell:/examples/build-contained]# cmake --build . --target hello_world
...
[ 89%] Built target absl_failure_signal_handler
[ 93%] Building CXX object CMakeFiles/hello_world.dir/a.cpp.o
[ 93%] Building CXX object CMakeFiles/hello_world.dir/bar.cpp.o
[ 96%] Building CXX object CMakeFiles/hello_world.dir/foo.cpp.o
[100%] Linking CXX executable hello_world
[100%] Built target hello_world
[nix-shell:/examples/build-contained]# ./hello_world
*** SIGSEGV received at time=1667953278 on cpu 4 ***
PC: @ 0x4027c0 (unknown) bar()
Segmentation fault (core dumped)
[nix-shell:/examples/build-contained]#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment