-
Notifications
You must be signed in to change notification settings - Fork 443
feat(nix): contribute nix devcontainer feature #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
# Nix | ||
|
||
Installs the Nix package manager. | ||
|
||
## Example Usage | ||
|
||
```json | ||
"features": { | ||
"ghcr.io/devcontainers/features/nix:1": { | ||
"version": "latest" | ||
} | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
| Options Id | Description | Type | Default Value | | ||
|-----|-----|-----|-----| | ||
| version | Select or enter a Nix version to install | string | latest | | ||
|
||
--- | ||
|
||
_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/devcontainers/features/blob/main/src/node/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"id": "nix", | ||
"version": "1.0.0", | ||
"name": "Nix", | ||
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/nix", | ||
"description": "Installs Nix which is a tool that takes a unique approach to package management and system configuration", | ||
"options": { | ||
"version": { | ||
"type": "string", | ||
"enum": [ | ||
"latest" | ||
], | ||
"default": "latest", | ||
"description": "Currently unused." | ||
} | ||
}, | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"bbenoist.Nix" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this is the most popular Nix extension on the VS Code marketplace, it looks like it hasn't been updated since 2015 and the maintainer hasn't responded to several issues recently: https://github.com/bbenoist/vscode-nix. I don't think we should recommend an extension that isn't actively maintained. |
||
] | ||
} | ||
}, | ||
"containerEnv": { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
#------------------------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. | ||
#------------------------------------------------------------------------------------------------------------- | ||
# | ||
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/sshd.md | ||
# Maintainer: The VS Code and Codespaces Teams | ||
# | ||
|
||
set -e | ||
|
||
if [ "$(id -u)" -ne 0 ]; then | ||
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' | ||
exit 1 | ||
fi | ||
|
||
|
||
sh <(curl -L https://nixos.org/nix/install) --daemon | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not very familiar with Nix. Do you know if it works well in daemon mode in docker containers? Do we need to add anything to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah an enterpoint would be needed. This I think would also require the container run as root - which isn't a problem for services like Codespaces, GitPod, or when using Docker Desktop, but is a consideration otherwise. Most of the exploration I did for https://github.com/Chuxel/feature-library/blob/main/src/nix/install.sh was trying to figure out a way to use single user unless the UID/GID changed. I think I have a working model - it sets things up so you can run in either daemon or non-daemon mode (which the nix install script itself couldn't do, but the steps it takes are documented for both scenarios). We could opt to start from here as a baseline if preferrable. It also verifies the download using their GPG key, has support for referencing a list of packages, a flake, or a derivation. It also should theoretically work on debian, redhat, and alpine based distros - the main difference is native packages that should be installed and I tweaked the utility functions to do that to detect and install the right one. Something we could do in other cases as well. |
||
|
||
mkdir -p $HOME/.config/nix $HOME/.config/nixpkgs | ||
echo 'sandbox = false' >> $HOME/.config/nix/nix.conf | ||
echo '{ allowUnfree = true; }' >> $HOME/.config/nixpkgs/config.nix | ||
echo '. $HOME/.nix-profile/etc/profile.d/nix.sh' >> $HOME/.bashrc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the user uses any other shell than bash then this would break. Not sure how to resolve - opening PR up for access to review hivemind knowledge.
Comment on lines
+21
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expect that we'll want these setup in the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Optional: Import test library | ||
source dev-container-features-test-lib | ||
|
||
# Definition specific tests | ||
check "version" nix --version | ||
|
||
# Report result | ||
reportResults |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to have an option for a set of Nix packages to include in the installation? That way the package downloads can be done during an image prebuild to save time later on when users create their dev environment from the image.