From ac55a180db9cd975b370d459cc200c0145cd2fdb Mon Sep 17 00:00:00 2001 From: zimbatm Date: Wed, 29 Jun 2022 17:00:08 +0200 Subject: [PATCH] nix-unstable-static: ship with complementary user script --- images/nix-unstable-static/README.md | 8 ++++++ images/nix-unstable-static/docker-nix-user.sh | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 images/nix-unstable-static/docker-nix-user.sh diff --git a/images/nix-unstable-static/README.md b/images/nix-unstable-static/README.md index 0fdb44e..66aa957 100644 --- a/images/nix-unstable-static/README.md +++ b/images/nix-unstable-static/README.md @@ -6,3 +6,11 @@ into /bin. The main use-case is to be able to run nix in the container, but share the `/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 [ ...]` + diff --git a/images/nix-unstable-static/docker-nix-user.sh b/images/nix-unstable-static/docker-nix-user.sh new file mode 100755 index 0000000..5b187cd --- /dev/null +++ b/images/nix-unstable-static/docker-nix-user.sh @@ -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 [ ...] +# +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" "$@"