With default.nix empty nix installs packages. Why?

Hi all,

I was surprised that with this in my default.nix practically empty:

{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
}

After entering my folder and switching to the development environment using direnv, nix goes ahead and automatically installs 40 libraries:

cd blank_nix
direnv: loading ~/Projects/blank_nix/.envrc
direnv: using nix
these 40 paths will be fetched (64.53 MiB download, 388.10 MiB unpacked):
  /nix/store/0hf2b8ilsapc5104jd3zzgiwxwrbq004-llvm-11.1.0
  /nix/store/1giaa8p2j8jcr0f95rs3g42y5ziqkz2j-patch-2.7.6
  /nix/store/1mrgbspjbkk55fhbfalka8r5lay8wx9k-findutils-4.9.0
  /nix/store/3ryix5hxi4afyl14ivswsmv02b4hcs7x-adv_cmds-119-locale
  /nix/store/41d5ywabivdap7dvb2zhimzn2rj3mjkd-openssl-1.1.1o
  /nix/store/4nkx7na7ry700lqpjg11khni95rcn4dm-expand-response-params
  /nix/store/5l8yxmazrxn90jnw1xavmbmrxy1g9bsy-cctools-port-949.0.1
  /nix/store/6x0zbrbr4hla2jzq9zf2i2bl45l3ys6y-bzip2-1.0.6.0.2-bin
  /nix/store/703jrlrx5333isyrr9mpsslr18hz1869-gawk-5.1.1
  /nix/store/75m7zzpbkg8arlb5kwbd479g926d71v5-gnumake-4.3
  /nix/store/7ys9hmfkj1084a3mwgj2n6l8ygsysshv-libSystem-11.0.0
  /nix/store/88bhsiq74bq4nngygk36jrvvsn88pnbd-libtapi-1100.0.11
  /nix/store/9k7dqfad56ywjmzvi5ghi6l1rq1lywim-bash-interactive-5.1-p16-info
  /nix/store/amasi5n0r4nkfz6nn356ni1vq96gf02l-gnu-config-2021-01-25
  /nix/store/an2h2ic7isza22j0dfdjixkjak849k0z-clang-11.1.0-lib
  /nix/store/c4v4c3qli1y8w7lzb18b48kfkac60477-bash-interactive-5.1-p16-doc
  /nix/store/c7v09lzp9shx23ivjw2fbqryiy7zccrw-bash-interactive-5.1-p16-dev
  /nix/store/db1al0s5758bmhsfgk9qnkbaw83qhfsm-clang-11.1.0
  /nix/store/fiq6pi9dnaj0sg5ml12rv5wrrcxlanka-cctools-binutils-darwin-949.0.1
  /nix/store/gy8dmn0sy367miw2rdsz5j8rijjg046l-gettext-0.21
  /nix/store/h384plhyimqv40qpbg96h0adiyzpf64n-binutils-2.38
  /nix/store/ilbdcjkq4iazk0wnwp0227cxsib4ywm7-compiler-rt-libc-11.1.0-dev
  /nix/store/k556h75p13wyhsili07r364696vjmg6d-libxml2-2.9.14
  /nix/store/kzzyndrgbyqq4s0s8564pfbjlrir4lrn-signing-utils
  /nix/store/ldh583pnd0jgawlyqx7cx5zx580rcrsc-clang-wrapper-11.1.0
  /nix/store/lk6jh3qkbisq2m7b6j1ip630jwz4wjld-hook
  /nix/store/mikgchyw0xl9926xvmkhhbl7bapdp658-llvm-11.1.0-lib
  /nix/store/mjv13xhzgav4r0nvmndcpfi5fy375l09-bash-interactive-5.1-p16-man
  /nix/store/mlyfy28xh1njpgph0s1jp9790fs0s1rc-sigtool-0.1.2
  /nix/store/n7dz3bj7rmhd48a8h8gpxq1whwf743hn-cctools-binutils-darwin-wrapper-949.0.1
  /nix/store/nnihhk0mmmlh8jwy91jpx08m6r2kz4hs-gnugrep-3.7
  /nix/store/pdasdf88aqw2wrqxmx06gjvhrk4dbmx8-xz-5.2.5-bin
  /nix/store/pk9ks2mpjj4zba84mfpdbl80n0hxfc3x-gnused-4.8
  /nix/store/s648n433d7r5j8iwmgx23r4dvy4wbs1d-ed-1.18
  /nix/store/sgs6hiirk85zf1d98z8an4hxgpnmi64z-compiler-rt-libc-11.1.0
  /nix/store/vyvf6icmbh0ri8d8bj7p6g7fs0lbnbz9-stdenv-darwin
  /nix/store/x5giiwcn3l4zdjdfnvfrd42abd61ja18-post-link-sign-hook
  /nix/store/z6cv9mprrhl61hq0ql1czmbkipxy6naf-gzip-1.12
  /nix/store/zhxa844n85s06rrijg6ys7za3sq7cp0b-diffutils-3.8
  /nix/store/zs0n8db4gsyf9q7igrzap5417bjj04y1-gnutar-1.34

I am running on M1 Mac, macOS 12.2.1.

I tried searching for the reasons, but could not find a thread about this.

I also noticed that if I add e.g. clang_13, nix maintains the link to clang_11. Ideally, these packages do not get installed at all to keep the environment dependencies as limited as possible.

Would anyone be able to give any clues and reasons about this behaviour?

Many thanks in advance!

mkShell is a wrapper around stdenv.mkDerivation. All of the packages you’re seeing are being inherited from stdenv.

For a more minimal shell, you can use mkShellNoCC which lacks the c compilers. For an even more minimal shell you can look at https://github.com/numtide/devshell.

I also noticed that if I add e.g. clang_13, nix maintains the link to clang_11. Ideally, these packages do not get installed at all to keep the environment dependencies as limited as possible.

You will want to use clang13Stdenv.mkDerivation if you’re going to be replacing the C toolchain. You need wrapped versions of the c tools to ensure that it’s able to find the correct libraries, otherwise it will be hard for you to compile and link.

4 Likes

I see that this was even your baby nixpkgs-128065

Thanks for showing me the direction. This worked for me.

1 Like