Skip to content
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

Nix feature #228

Merged
merged 14 commits into from
Nov 1, 2022
Merged

Nix feature #228

merged 14 commits into from
Nov 1, 2022

Conversation

Chuxel
Copy link
Member

@Chuxel Chuxel commented Oct 18, 2022

This PR adds a dev container feature for Nix. It supports using base images from Debian/Ubuntu, the RHEL tree, and Alpine.

I refactored some utilities into a utils.sh file to make the main script more readable.

The feature can just install nix, or install nix and a set of packages, a Flake, or a derivation. This is limited to things in the base image (or remote URIs in the case of Flakes) due to the lack of lifecycle hook support (devcontainers/spec#60). We can update once that is available.

Given Nix is picky about privs, the script supports doing both a single user and multi-user install. NOTES.md includes info on what each does and downsides by scenario.

Given the breadth of the capabilities, there's also a battery of tests which were unblocked by recent tweaks to the devcontainer CLI's testing setup.

@Chuxel Chuxel requested a review from a team as a code owner October 18, 2022 18:40
@Chuxel
Copy link
Member Author

Chuxel commented Oct 18, 2022

//cc @lostintangent @ghuntley given previous interest

Copy link
Member

@samruddhikhandale samruddhikhandale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. Thank you! 👏

Left some comments.

test/nix/scenarios.json Show resolved Hide resolved
test/nix/scenarios.json Show resolved Hide resolved
src/nix/devcontainer-feature.json Show resolved Hide resolved
src/nix/devcontainer-feature.json Show resolved Hide resolved
src/nix/install.sh Show resolved Hide resolved
src/nix/install.sh Show resolved Hide resolved
src/nix/install.sh Outdated Show resolved Hide resolved
src/nix/install.sh Show resolved Hide resolved
@Chuxel
Copy link
Member Author

Chuxel commented Oct 29, 2022

Dropped the derivation property in favor of flake given you currently can't use a .nix file from the source tree (could be added later once we have postCreateCommand support in features). Also noticed other features seem to be using comma separation for lists so adjusted to match.

@Chuxel
Copy link
Member Author

Chuxel commented Oct 31, 2022

Test failures in CI were expected since (as covered by NOTES.md), single-user does not work without doing a chown post-create on Linux when the host's UID updates. So added the chown to the test with a warning.

@Chuxel
Copy link
Member Author

Chuxel commented Nov 1, 2022

@samruddhikhandale Also I think I accidently deleted a comment you made when trying to delete a comment I made. 😅
image
Pretty sure it was one of the comments on the env vars at the top, but LMK if not. I addressed the other comments and it will now handle using a Flake or installing packages if nix is already installed.

Copy link
Member

@samruddhikhandale samruddhikhandale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome. Thank you! 👏 👏

🚀 🚀

@dsyer
Copy link

dsyer commented Nov 11, 2022

Can someone help with some more detailed instructions on how to use this? I tried adding the feature and getting a lot of errors. Different errors, no obvious pattern. This one is common:

[2022-11-11T11:59:37.210Z] Start: Run: tar --no-same-owner -x -f -
[2022-11-11T11:59:37.228Z] Stop (18 ms): Run: tar --no-same-owner -x -f -
[2022-11-11T11:59:37.237Z] * Processing feature: ghcr.io/devcontainers/features/nix
[2022-11-11T11:59:37.744Z] * Processing feature: ghcr.io/devcontainers/features/docker-in-docker
[2022-11-11T11:59:38.329Z] * Fetching feature: nix_1_oci
[2022-11-11T12:01:48.847Z] error: Error: connect ETIMEDOUT 185.199.111.154:443
[2022-11-11T12:01:48.847Z] (!) ERR: Failed to fetch feature: Failed to download package for ghcr.io/devcontainers/features/nix 
[2022-11-11T12:01:48.849Z] Error: Failed to download package for ghcr.io/devcontainers/features/nix
[2022-11-11T12:01:48.850Z]     at vw (/home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js:155:6485)
[2022-11-11T12:01:48.850Z]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2022-11-11T12:01:48.850Z]     at async yS (/home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js:186:6943)
[2022-11-11T12:01:48.851Z]     at async na (/home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js:186:2444)
[2022-11-11T12:01:48.851Z]     at async oo (/home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js:186:12686)
[2022-11-11T12:01:48.852Z]     at async sa (/home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js:186:11651)
[2022-11-11T12:01:48.852Z]     at async bu (/home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js:254:2847)
[2022-11-11T12:01:48.852Z]     at async Jw (/home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js:254:1779)
[2022-11-11T12:01:48.853Z]     at async JS (/home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js:260:2006)
[2022-11-11T12:01:48.853Z]     at async co (/home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js:260:3110)
[2022-11-11T12:01:48.857Z] Stop (131867 ms): Run: /nix/store/nrdmbm43k7xyc9nvg741zcqpi7i72rvn-vscode-1.70.2/lib/vscode/code /home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/dsyer/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --workspace-folder /home/dsyer/dev/scratch/hello-as --workspace-mount-consistency cached --id-label devcontainer.local_folder=/home/dsyer/dev/scratch/hello-as --log-level debug --log-format json --config /home/dsyer/dev/scratch/hello-as/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-11-11T12:01:48.858Z] Exit code 1
[2022-11-11T12:01:48.871Z] Command failed: /nix/store/nrdmbm43k7xyc9nvg741zcqpi7i72rvn-vscode-1.70.2/lib/vscode/code /home/dsyer/.vscode/extensions/ms-vscode-remote.remote-containers-0.247.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/dsyer/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --workspace-folder /home/dsyer/dev/scratch/hello-as --workspace-mount-consistency cached --id-label devcontainer.local_folder=/home/dsyer/dev/scratch/hello-as --log-level debug --log-format json --config /home/dsyer/dev/scratch/hello-as/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-11-11T12:01:48.871Z] Exit code 1

@Chuxel
Copy link
Member Author

Chuxel commented Nov 11, 2022

@dsyer Would you mind raising an issue with your specifics? In particular the base image you are using, OS, architecture, etc. Possible there's a scenario where things are not working as expected. That particular error though sounds like its actually having a hard time downloading the feature itself which could be connectivity related. #275 is very specific to the universal image, for example.

@dsyer
Copy link

dsyer commented Nov 12, 2022

That's it really, for the specifics. The JSON is just the default if you add ubuntu and nix. My network connectivity is generally good here locally. Maybe there was a DNS glitch out there somewhere? 185.199.111.154 looks like Github (not gcr.io).

@Chuxel
Copy link
Member Author

Chuxel commented Nov 12, 2022

@dsyer Raised devcontainers/cli#281 for you. Folks won't reply to a merged PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants