Persist nix store

This commit is contained in:
Chris Daßler 2024-10-20 18:03:13 +02:00
parent 732bbef79f
commit 70ee088919
3 changed files with 29 additions and 1 deletions

View File

@ -30,5 +30,15 @@ RUN curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/
# Now use devbox as global package manager
RUN echo 'eval "$(devbox global shellenv --preserve-path-stack -r)" && hash -r' >> ~/.bashrc
# Backup of the nix-store
RUN cp -a /nix/store /nix-store-backup
# Add start script
COPY scripts/start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/start.sh
# Set start script as entrypoint
ENTRYPOINT ["/usr/local/bin/start.sh"]
WORKDIR /workspace
CMD ["sh"]

View File

@ -16,6 +16,12 @@ services:
- ../devbox.lock:/root/.local/share/devbox/global/default/devbox.lock
# mount workspace
- ../src:/workspace
# persist nix-store
- nix-store:/nix
# vscode needs a running container, so we make its shell interactive
stdin_open: true # docker run -i
tty: true # docker run -t
tty: true # docker run -t
volumes:
nix-store:
external: true

View File

@ -0,0 +1,12 @@
#!/bin/sh
# Checks if /nix/store is empty
if [ -z "$(ls -A /nix/store)" ]; then
echo "Nix store volume is empty. Copying pre-filled store from image."
cp -a /nix-store-backup/. /nix/store/
else
echo "Nix store volume is not empty. Skipping copy."
fi
# Start the normal container process
exec "$@"