-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a working devcontainer configuration.
This config will automatically pick up and install the devShell dependencies from `flake.nix` when the container is created or started. If you are editing the flake.nix in the meantime, you'll need to open a terminal and run `update-content.sh`. You may need to reload the remote vscode window in order for this to take effect, but I tested that it works with the golang extension.
- Loading branch information
1 parent
9111cbf
commit 1fd9cf2
Showing
10 changed files
with
159 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Latest debian, with curl, should contain all necessary dependencies | ||
# https://github.com/devcontainers/images/tree/main/src/base-debian | ||
# FROM mcr.microsoft.com/devcontainers/base:debian | ||
# https://github.com/docker-library/buildpack-deps/blob/98a5ab81d47a106c458cdf90733df0ee8beea06c/debian/buster/curl/Dockerfile | ||
FROM buildpack-deps:curl | ||
|
||
# Update and install necessary system packages | ||
RUN apt-get update \ | ||
&& apt-get install -y \ | ||
sudo \ | ||
xz-utils \ | ||
tar \ | ||
curl \ | ||
procps \ | ||
zsh | ||
|
||
# Create a non-root user | ||
# from https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_creating-a-nonroot-user | ||
# alternatively, could use this feature to do it automagically at boot time | ||
# https://github.com/devcontainers/features/blob/main/src/common-utils/main.sh#L371 | ||
ARG USERNAME=vscode | ||
ARG USER_UID=1000 | ||
ARG USER_GID=$USER_UID | ||
# Create the user with sudo privileges | ||
RUN groupadd --gid $USER_GID $USERNAME \ | ||
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME --shell /bin/zsh \ | ||
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ | ||
&& chmod 0440 /etc/sudoers.d/$USERNAME | ||
|
||
# Install nix with flakes and the unified-command enabled | ||
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix > /nix-installer && chmod +x /nix-installer | ||
RUN /nix-installer install linux --init none --no-confirm | ||
|
||
# Add user to trusted users | ||
RUN echo "extra-trusted-users = $USERNAME" | sudo tee -a /etc/nix/nix.conf >/dev/null | ||
# Allow the user to use the nix daemon without sudo | ||
RUN usermod -a -G nixbld $USERNAME | ||
|
||
# Initialize nix | ||
COPY nixinstall.sh /tmp/nixinstall.sh | ||
RUN chmod +x /tmp/nixinstall.sh && /tmp/nixinstall.sh && rm /tmp/nixinstall.sh | ||
|
||
# Add the entrypoint | ||
COPY entrypoint.sh /tmp/entrypoint.sh | ||
RUN install --mode 755 /tmp/entrypoint.sh /usr/local/bin/entrypoint.sh && rm /tmp/entrypoint.sh | ||
|
||
COPY update-content.sh /tmp/update-content.sh | ||
RUN install --mode 755 /tmp/update-content.sh /usr/local/bin/update-content.sh && rm /tmp/update-content.sh | ||
|
||
# Make this bash wrapper the default source for all scripts | ||
COPY sh.sh /tmp/sh.sh | ||
RUN rm /bin/sh && install --mode 755 /tmp/sh.sh /bin/sh && rm /tmp/sh.sh | ||
|
||
# Enable direnv on all directories by default | ||
USER $USERNAME | ||
RUN mkdir -p /home/$USERNAME/.config/direnv/ | ||
COPY direnv.toml /home/$USERNAME/.config/direnv/direnv.toml | ||
# setup direnv and starship bash and zsh | ||
RUN touch ~/.zshrc ~/.bashrc | ||
RUN echo 'eval "$(direnv hook zsh)"' >> /home/$USERNAME/.zshenv | ||
RUN echo 'eval "$(starship init zsh)"' >> /home/$USERNAME/.zshenv | ||
RUN echo 'eval "$(direnv hook bash)"' >> /home/$USERNAME/.bash_aliases | ||
RUN echo 'eval "$(starship init bash)"' >> /home/$USERNAME/.bash_aliases | ||
|
||
# By default, starting the container will run forever. This is necessary for | ||
# some reason that I don't understand. | ||
ENTRYPOINT [ "entrypoint.sh" ] | ||
CMD ["sleep", "infinity"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "default-nix", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
}, | ||
"overrideCommand": false, | ||
"remoteUser": "vscode", | ||
"updateContentCommand": "update-content.sh nix-search-cli", | ||
"postStartCommand": "update-content.sh nix-search-cli", | ||
"customizations": { | ||
"vscode": { | ||
"settings": { | ||
"terminal.integrated.defaultProfile.linux": "zsh", | ||
"terminal.integrated.profiles.linux": { | ||
"zsh": { | ||
"path": "/bin/zsh", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[global] | ||
warn_timeout = "10m" | ||
|
||
[whitelist] | ||
prefix = [ "/" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env zsh | ||
start_nix_daemon() { | ||
x=$(pgrep nix-daemon) | ||
if [[ -z "$x" ]]; then | ||
echo "started new daemon" | ||
sudo -i --background --non-interactive zsh -c 'nix-daemon >& /tmp/nix-daemon.log' | ||
else | ||
echo "nix-daemon running PID=$x" | ||
fi | ||
} | ||
start_nix_daemon | ||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#/usr/bin/env zsh | ||
# start the nix daemon | ||
start_nix_daemon() { | ||
x=$(pgrep nix-daemon) | ||
if [ -z "$x" ]; then | ||
echo "started new daemon" | ||
sudo -i --background --non-interactive zsh -c 'nix-daemon >& /tmp/nix-daemon.log' | ||
else | ||
echo "nix-daemon running PID=$x" | ||
fi | ||
} | ||
|
||
start_nix_daemon | ||
# pin nixpkgs | ||
echo "downloading and pinnng nixpkgs" | ||
sudo -i nix registry add nixpkgs github:NixOS/nixpkgs | ||
sudo -i nix registry pin nixpkgs | ||
echo "installing base set of packages" | ||
# install some packages | ||
sudo -i nix-env -iA nixpkgs.direnv nixpkgs.starship nixpkgs.git | ||
echo "done" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
start_nix_daemon() { | ||
x=$(pgrep nix-daemon) | ||
if [[ -z "$x" ]]; then | ||
sudo -i --background --non-interactive zsh -c 'nix-daemon >& /tmp/nix-daemon.log' | ||
fi | ||
} | ||
|
||
start_nix_daemon | ||
BASH_ENV=~/.bash_aliases bash "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env zsh | ||
WORKSPACE_ROOT=/workspaces/$1 | ||
echo 'export WORKSPACE_ROOT='$WORKSPACE_ROOT > ~/.bash_aliases | ||
cd $WORKSPACE_ROOT | ||
nix print-dev-env . >> ~/.bash_aliases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters