From 0b7ce534a8f662d31fc4cd494a216e08551b5509 Mon Sep 17 00:00:00 2001 From: Thierry Laurion Date: Fri, 3 May 2024 14:13:39 -0400 Subject: [PATCH] WiP: revert garbage collector within nix environment. Doesn;t help and makes the docker image bigger TODO: push v0.1.2 with those changes pointing circleci to use it Signed-off-by: Thierry Laurion --- NIX_REPRO_NOTES | 13 +++++++------ flake.nix | 34 ++++++++-------------------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/NIX_REPRO_NOTES b/NIX_REPRO_NOTES index 7b7b9b0c..af127a8e 100644 --- a/NIX_REPRO_NOTES +++ b/NIX_REPRO_NOTES @@ -59,11 +59,12 @@ docker push tlaurion/heads-dev-env:v0.0.3 ------------------- -#To create the docker image, I was not able to set gcroot dynamically, so here are the manual steps so nix is not wiped per garbage collector -mkdir -p /nix/var/nix/gcroots/per-user/$(whoami) -ln -sfn $(readlink -f $HOME/.nix-profile) /nix/var/nix/gcroots/per-user/$(whoami)/profile +#To create the docker image, using garbage collector didn't help and made the size of the image grow bigger?! not using it reverting to what worked +# produced image without garbage collector was 990 Mb image, with it (and stripping which is already done by nix builder...) its 1006Mb. Over my head +sh <(curl -L https://nixos.org/nix/install) --no-daemon + . /home/user/.nix-profile/etc/profile.d/nix.sh -#And then build derivates and cal garbarrge collection (not yet successfull since docker build fails now) +#And then build derivates nix build .#dockerImage && docker load < result && docker run --network host --rm -ti -v $(pwd):$(pwd) -w $(pwd) linuxboot/heads:dev-env #Use it @@ -72,6 +73,6 @@ docker run -e DISPLAY=$DISPLAY --network host --rm -ti -v $(pwd):$(pwd) -w $(pwd #push it docker login -docker tag linuxboot/heads:dev-env tlaurion/heads-dev-env:v0.0.9 -docker push tlaurion/heads-dev-env:v0.0.9 +docker tag linuxboot/heads:dev-env tlaurion/heads-dev-env:v0.1.2 +docker push tlaurion/heads-dev-env:v0.1.2 diff --git a/flake.nix b/flake.nix index 8f110f67..325193a0 100644 --- a/flake.nix +++ b/flake.nix @@ -85,25 +85,10 @@ sudo # ( °-° ) upx ]; - - # Stripping binaries to reduce size, while ensuring functionality is not affected. - stripBinaries = map (pkg: if pkg?isDerivation then pkg.overrideAttrs (oldAttrs: { - postInstall = oldAttrs.postInstall or "" + '' - strip $out/bin/* || true - ''; - }) else pkg) deps; - in { # The development shell includes all the dependencies. devShell = pkgs.mkShellNoCC { - buildInputs = stripBinaries ++ [ pkgs.nix ]; # Include the Nix package to provide nix-collect-garbage. - shellHook = '' - # Create a garbage collection root for the Nix profile - mkdir -p /nix/var/nix/gcroots/per-user/$(whoami) - echo $(readlink -f $HOME/.nix-profile) > /nix/var/nix/gcroots/per-user/$(whoami)/profile - # Perform garbage collection to clean up any unnecessary files. - nix-collect-garbage -d - ''; + buildInputs = deps; }; # myDevShell outputs environment variables necessary for development. @@ -123,20 +108,17 @@ # Docker image configuration for the Heads project. packages.dockerImage = pkgs.dockerTools.buildLayeredImage { - name = "linuxboot/heads"; # Image name. - tag = "dev-env"; # Image tag. - config.Entrypoint = ["bash" "-c" ''source /devenv.sh; if (( $# == 0 )); then exec bash; else exec "$0" "$@"; fi'']; # Entrypoint configuration. - - # Contents of the Docker image, including stripped binaries for size optimization. - contents = stripBinaries ++ [ + name = "linuxboot/heads"; + tag = "dev-env"; + config.Entrypoint = ["bash" "-c" ''source /devenv.sh; if (( $# == 0 )); then exec bash; else exec "$0" "$@"; fi'']; + contents = + deps + ++ [ pkgs.dockerTools.binSh pkgs.dockerTools.caCertificates pkgs.dockerTools.usrBinEnv ]; - - enableFakechroot = true; # Enable fakechroot for compatibility. - - # Fake root commands to set up the environment inside the Docker image. + enableFakechroot = true; fakeRootCommands = #bash ''