Skip to content

Commit

Permalink
Nix devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
javdl committed Jan 2, 2025
1 parent dacedc2 commit e49dce8
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2022 X-Truder <jaka@x-truder.net>
# SPDX-FileCopyrightText: 2022 Félix Robles <felix@sequentech.io>
#
# SPDX-License-Identifier: MIT

# Reuse a base image made for devcontainers.
FROM ghcr.io/xtruder/nix-devcontainer:v1

# cache /nix
VOLUME /nix
47 changes: 47 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/docker-existing-dockerfile
{
"name": "strand-project",
"dockerComposeFile": "docker-compose.yml",
"service": "dev",
"workspaceFolder": "/workspace",
"forwardPorts": [3000],

"userEnvProbe": "loginShell",
"updateRemoteUserUID": false,

// build development environment on creation
"onCreateCommand": "nix develop --command bash -c 'nix build -vvv -L && cargo build --all-features && echo Environment Built' || true",
"updateContentCommand": "nix develop --command bash -c 'nix build -vvv -L && cargo build --all-features && echo Environment Built' || true",

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
// run commands on save
// https://marketplace.visualstudio.com/items?itemName=fsevenm.run-it-on
"fsevenm.run-it-on",

// Docker for Visual Studio Code
"ms-azuretools.vscode-docker",

// select nix environment
"arrterian.nix-env-selector",

// Nix language support
"jnoortheen.nix-ide",

// Rust language support
"rust-lang.rust-analyzer",

// Markdown support and previsualization
"yzhang.markdown-all-in-one",

// Toml support
"tamasfe.even-better-toml",

// Debugging
"vadimcn.vscode-lldb",

// Allows to use Alt+Q (or Option+Q in mac) to rewrap lines
"stkb.rewrap"
]
}
22 changes: 22 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2022 Felix Robles <felix@sequentech.io>
# SPDX-License-Identifier: AGPL-3.0-only
version: '3'
services:
dev:
build:
context: ../
dockerfile: .devcontainer/Dockerfile
args:
PRELOAD_EXTENSIONS: arrterian.nix-env-selector
USER_UID: ${USER_UID:-1000}
USER_GID: ${USER_GID:-1000}
command: sleep infinity
volumes:
- ..:/workspace:cached
- nix:/nix
security_opt:
- label:disable
network_mode: "bridge"

volumes:
nix:
34 changes: 34 additions & 0 deletions .devcontainer/etc/bash.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-FileCopyrightText: 2022 X-Truder <jaka@x-truder.net>
# SPDX-FileCopyrightText: 2022 Félix Robles <felix@sequentech.io>
#
# SPDX-License-Identifier: MIT

# System-wide .bashrc file for interactive bash(1) shells.

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

[[ $ENVRC_RUN != yes ]] && source /etc/envrc

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, overwrite the one in /etc/profile)
# but only if not SUDOing and have SUDO_PS1 set; then assume smart user.
if ! [ -n "${SUDO_USER}" -a -n "${SUDO_PS1}" ]; then
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

# load direnv hook if not running as root
if ! [ $(id -u) = 0 ]; then
eval "$(direnv hook bash)"
fi
4 changes: 4 additions & 0 deletions .devcontainer/etc/devcontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#!/bin/bash

[[ $ENVRC_RUN != yes ]] && source /etc/envrc
4 changes: 4 additions & 0 deletions .devcontainer/etc/devcontainer.sh.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SPDX-FileCopyrightText: 2022 X-Truder <jaka@x-truder.net>
SPDX-FileCopyrightText: 2022 Felix Robles <felix@sequentech.io>

SPDX-License-Identifier: MIT
18 changes: 18 additions & 0 deletions .devcontainer/etc/direnv.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2022 X-Truder <jaka@x-truder.net>
# SPDX-FileCopyrightText: 2022 Félix Robles <felix@sequentech.io>
#
# SPDX-License-Identifier: MIT

# direnv global config

[global]

# increase warn timeout to 30 minutes, as it can take
# long time to load all nix dependencies
warn_timeout = "30m"

bash_path = "/bin/bash"

# whitelist all paths, since we are running in container
[whitelist]
prefix = [ "/" ]
19 changes: 19 additions & 0 deletions .devcontainer/etc/envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2022 X-Truder <jaka@x-truder.net>
# SPDX-FileCopyrightText: 2022 Félix Robles <felix@sequentech.io>
#
# SPDX-License-Identifier: MIT
USER=$(whoami)

# load nix into environment
if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ] ; then
. $HOME/.nix-profile/etc/profile.d/nix.sh
fi

# add $HOME/.nix-profile/share to XDG_DATA_DIRS, so completions for packages
# installed with nix work
if [ -e $HOME/.nix-profile ] ; then
XDG_DATA_DIRS="$XDG_DATA_DIRS:$HOME/.nix-profile/share"
fi
XDG_DATA_DIRS="$XDG_DATA_DIRS:/usr/share"

ENVRC_RUN=yes
6 changes: 6 additions & 0 deletions .devcontainer/etc/nix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: 2022 X-Truder <jaka@x-truder.net>
# SPDX-FileCopyrightText: 2022 Félix Robles <felix@sequentech.io>
#
# SPDX-License-Identifier: MIT
sandbox = false
experimental-features = nix-command flakes
1 change: 1 addition & 0 deletions .direnv/flake-profile
1 change: 1 addition & 0 deletions .direnv/flake-profile-1-link
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/*.crswap": true,
"**/.retool_types/**": true,
"**/*tsconfig.json": true,
".cache": true,
Expand Down
1 change: 1 addition & 0 deletions result

0 comments on commit e49dce8

Please sign in to comment.