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 <insurgo@riseup.net>
This commit is contained in:
Thierry Laurion 2024-05-03 14:13:39 -04:00
parent 3d0991f6c1
commit 0b7ce534a8
No known key found for this signature in database
GPG Key ID: 9A53E1BB3FF00461
2 changed files with 15 additions and 32 deletions

View File

@ -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

View File

@ -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
''