From fb1acc279c6bb9217b888da1f44374ea9e9c4064 Mon Sep 17 00:00:00 2001 From: Brian Egge Date: Mon, 11 Nov 2024 14:35:41 +0000 Subject: [PATCH] Setup vscode dev container --- .devcontainer/Dockerfile | 19 +++++++++++++++ .devcontainer/devcontainer.json | 42 +++++++++++++++++++++++++++++++++ .devcontainer/nix.conf | 1 + .devcontainer/profile.sh | 16 +++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/nix.conf create mode 100755 .devcontainer/profile.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..608478c9 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,19 @@ +FROM mcr.microsoft.com/vscode/devcontainers/base:jammy + +# These dependencies are required by Nix. +RUN apt update -y +RUN apt -y install --no-install-recommends curl xz-utils + +# Install Nix +ARG NIX_INSTALL_SCRIPT=https://github.com/nix-community/nix-unstable-installer/releases/download/nix-2.23.0pre20240603_da92ad7/install +RUN curl -L ${NIX_INSTALL_SCRIPT} | sudo -u vscode NIX_INSTALLER_NO_MODIFY_PROFILE=1 sh + +# Configuration for Nix from the repository shared amongst developers. +RUN mkdir -p /etc/nix +COPY .devcontainer/nix.conf /etc/nix/nix.conf +# COPY nix.conf /etc/nix/nix.conf + +# This loads the development environment when the container is started. +COPY .devcontainer/profile.sh /etc/profile.d/devcontainer.sh + +# COPY /home/vscode/.nix-profile/etc/profile.d/nix.sh /etc/profile.d/devcontainer.sh \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..b3803f4a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,42 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "Ubuntu", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "build": { + "dockerfile": "Dockerfile", + "context": "..", + "args": { + // Options + "NODE_VERSION": "none" + } + }, + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "uname -a", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" + "runArgs": ["--userns=keep-id"], + "containerUser": "vscode", + "updateRemoteUserUID": true, + "containerEnv": { + "HOME": "/home/vscode" + }, + "customizations": { + "vscode": { + "extensions": [ + "github.vscode-github-actions", + "GitHub.vscode-pull-request-github" + ] + } + } +} diff --git a/.devcontainer/nix.conf b/.devcontainer/nix.conf new file mode 100644 index 00000000..c7cd834f --- /dev/null +++ b/.devcontainer/nix.conf @@ -0,0 +1 @@ +experimental-features = nix-command flakes ca-references \ No newline at end of file diff --git a/.devcontainer/profile.sh b/.devcontainer/profile.sh new file mode 100755 index 00000000..33da3be9 --- /dev/null +++ b/.devcontainer/profile.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +PROJECT_DIR=${PROJECT_DIR:-/workspace} + +# Make Nix available as it's not installed system-wide. +if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ] ; then + . $HOME/.nix-profile/etc/profile.d/nix.sh +fi + +# Only load the development environment if this is a login shell so calling a +# shell later on doesn't reload the environment again. +if shopt -q login_shell; then + pushd "${PROJECT_DIR}" + eval "$(nix print-dev-env --profile "${PROJECT_DIR}/.devcontainer/.profile")" + popd +fi \ No newline at end of file