I want to raise attention about this blogpost from @fzakaria : A minimal nix-shell | Farid Zakaria’s Blog, which talks about a smaller stdenv for mkShell.
Currently, mkShell uses stdenv, which pulls a C compiler resulting in a closure size of ~300M. Even stdenvNoCC still pulls other utilities, like sed or awk, which results in a ~50M closure size.
Should nixpkgs include an even smaller stdenv? I’ve got many projects for which I just need a couple of CLI tools, but I need to pay the price of pulling sed, awk and friends every time.
By using pkgsMusl’s bash and coreutils, I was able to get down to 6.5M size.
let
pkgs = import <nixpkgs> {};
stdenvMinimal = pkgs.stdenvNoCC.override {
cc = null;
preHook = "";
allowedRequisites = null;
initialPath = [pkgs.pkgsCross.musl64.busybox];
shell = "${pkgs.pkgsCross.musl64.bash}/bin/bash";
extraNativeBuildInputs = [];
};
in
pkgs.mkShell.override {stdenv = stdenvMinimal;} {
name = "shell-minimal";
}
$ nix path-info -Sh $(nix-build -A inputDerivation ./shell-minimal.nix)
/nix/store/l8rsmzpds1z4qbq60p9v8snkv9rd3zh0-shell-minimal 6.5M
$ nix path-info -Sh $(nix-build -A inputDerivation ./shell-nocc.nix)
/nix/store/xrp31fx9lkkm1j5rmyw7qn515s0gnkdb-shell-nocc 64.4M
$ nix path-info -Sh $(nix-build -A inputDerivation ./shell-stdenv.nix)
/nix/store/wvbkpq1ws8jdgbmc4npfas69cklc28ij-shell-standard 316.9M
The source for the 3 shells: GitHub - viperML/shell-size