How to build alpine image with bootstrap tools with volume /nix/store to mount over

I have a Gitlab CI runner which uses an image build like:


alpineImage = (
    pkgs.dockerTools.buildLayeredImage {
      fromImage = alpineBase;
      name = "local/alpine";
      tag = "latest";

      contents = [
        pkgs.nix
        pkgs.cacert
        pkgs.coreutils
        pkgs.findutils
        pkgs.git
        pkgs.openssh
        pkgs.bash

        pkgs.just

        pkgs.cachix
        preBuildScript
      ];

      config = {
        Volumes = {
          "/nix/store" = { };
          "/nix/var/nix/db" = { };
          "/nix/var/nix/daemon-socket" = { };
        };
        Labels = noPruneLabels;
      };
      maxLayers = 125;
    }
  );

This image is the default image where the /nix/store path gets mounted over from a nix-daemon when Gitlab runs the image here

The contents = which are installed in /nix/store obviously get overwritten when the /nix/store path is mounted.

I am searching a good way to have these tools in contents available (maybe not linking into /nix/store) such that mounting a volume to /nix/store does not make them disappear.

  • Is there a way to influence the NIX_STORE_DIR path when the alpineImage gets build? probably not, such that the paths do not end up in /nix/store but maybe /nix-bootstrap?

  • I am not sure if I can mount with overlay, so influencing Gitlabs docker run ?

  • I tried to copy all store paths to some other path /nix-bootstrap with nix copy --all --to /nix-bootstrap and trying to relink all binaries in /bin/* (like e.g. /bin/just) to this path, but the /nix-bootstrap/store stays empty (?, weird). Is there already a cmd/tooling for such things?

Any help very welcome!

1 Like