nix-unstable-static: ship with complementary user script

This commit is contained in:
zimbatm 2022-06-29 17:00:08 +02:00
parent bb3cbda9f3
commit ac55a180db
No known key found for this signature in database
GPG key ID: 71BAF6D40C1D63D7
2 changed files with 36 additions and 0 deletions

View file

@ -6,3 +6,11 @@ into /bin.
The main use-case is to be able to run nix in the container, but share the The main use-case is to be able to run nix in the container, but share the
`/nix/store` with the host. `/nix/store` with the host.
## Using the container with the host store
This folder ships with a complementary script that you can use to run the
image as the current user and the host /nix/store.
Usage: `docker-nix-user.sh [<command> ...<args>]`

View file

@ -0,0 +1,28 @@
#!/usr/bin/env bash
#
# Run nixpkgs/nix-unstable-static as the current user and the host /nix/store.
#
# Usage: docker-nix-user.sh [<command> ...<args>]
#
set -euo pipefail
image=nixpkgs/nix-unstable-static
options=(
-ti
# Remove the container on exit
--rm
-e NIX_PATH="nixpkgs=channel:nixos-22.05"
# Used by /run_as_user.sh
-e user_id="$(id -u)"
-e user_name="$(id -nu)"
-e group_id="$(id -g)"
-e group_name="$(id -ng)"
# Use the host store
-v /nix:/nix
# Mount the code into the container
-v "$PWD:/workspace"
-w /workspace
--entrypoint /run_as_user.sh
)
exec docker run "${options[@]}" "$image" "$@"