I started playing around with Nim and the first impression is quite nice. Getting started on NixOS was very smooth.
For my first project I’m aiming with building via a Nix-Flake, but execution should be on a ephemeral Nix-Less Ubuntu-Image, where I load the binary at runtime, so I’m looking for a small closure size.
While I understand that I can only get rid of GLIBC with probably a Zig/musl backend and a matching build of OpenSSL etc., I’m wondering why nim-unwrapped
is part of the closure.
See e.g. this minimal (flake) example:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?rev=dfef2e61107dc19c211ead99a5a61374ad8317f4";
utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
utils,
}:
utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
nimPackages = pkgs.nimPackages;
in rec {
packages.demo = nimPackages.buildNimPackage rec {
pname = "demo";
version = "0.1.0";
src = ./.;
unpackPhase = ''
echo 'echo "Hello World"' > demo.nim
echo 'bin = @["demo"]' > demo.nimble
echo 'equires "nim >= 1.6.10"' >> demo.nimble
'';
nimBinOnly = true;
nimRelease = true;
nimDefines = [];
buildInputs = with nimPackages; [];
propagatedBuildInputs = [];
};
apps.demo = {
type = "app";
program = "${packages.demo}/bin/demo";
};
devShell = with pkgs;
mkShell {
buildInputs = [nim nimble-unwrapped];
};
});
}
> nix path-info -rsSh .#demo | sort -nk3
/nix/store/34xlpp3j3vy7ksn09zh44f1c04w77khf-libunistring-1.0 1.7M 1.7M
/nix/store/5mh5019jigj0k14rdnjam1xwk5avn1id-libidn2-2.3.2 254.1K 2.0M
/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163 28.9M 30.8M
/nix/store/1dgws25664p544znpc6f1nh9xmjf4ykc-pcre-8.45 506.5K 31.3M
/nix/store/fzb7khbic8vpcr3m69v6y8qp6jqspdgw-openssl-1.1.1s 4.0M 34.8M
/nix/store/n0nzzxszqqvi64br0sra58jg74zldcn1-nim-unwrapped-1.6.8 31.5M 66.9M
/nix/store/c3gvf94ym6fdfbip6w29f3f348gvrbxb-demo-0.1.0 82.3K 67.0M
That is quite a hefty package.
Doing a bit of grepping I found two references to /nix/store/n0nzzxszqqvi64br0sra58jg74zldcn1-nim-unwrapped-1.6.8/nim/lib/system.nim
in the resulting binary, which is probably the reason for Nix to include nim-unwrapped
. If I’m not mistaken, the runtime should be compiled in and no reference should be left.
So, help me understand and in the end maybe fix the issue!