devcontainers / features

A collection of Dev Container Features managed by Dev Container spec maintainers. See https://github.com/devcontainers/feature-starter to publish your own
https://containers.dev/features
MIT License
869 stars 346 forks source link

Nix feature does not support complex package expressions #375

Open worldofgeese opened 1 year ago

worldofgeese commented 1 year ago

GIven

      "ghcr.io/devcontainers/features/nix:1": {
        "multiUser": "false",
        "packages": "pdm, kompose, (google-cloud-sdk.withExtraComponents [google-cloud-sdk.components.gke-gcloud-auth-plugin])"

Building the Dev Container image will fail with the following error:

#0 65.22 copying Nix to /nix/store...
#0 65.84 installing 'nix-2.12.0'
#0 65.86 building '/nix/store/0dg0zjj2j6hijn193x1215yssrg7n1xs-user-environment.drv'...
#0 106.5 unpacking channels...
#0 116.3 
#0 116.3 Installation finished!  To ensure that the necessary environment
#0 116.3 variables are set, please add the line
#0 116.3 
#0 116.3   . /home/vscode/.nix-profile/etc/profile.d/nix.sh
#0 116.3 
#0 116.3 to your shell profile (e.g. ~/.profile).
#0 116.4 (*) Executing post-installation steps...
#0 116.4 Installing packages "pdm  kompose  (google-cloud-sdk.withExtraComponents [google-cloud-sdk.components.gke-gcloud-auth-plugin])" in profile...
#0 131.1 error: Parenthesis is not closed.
#0 131.2 ERROR: Feature "Nix Package Manager" (ghcr.io/devcontainers/features/nix) failed to install! Look at the documentation at https://github.com/devcontainers/features/tree/main/src/nix for help troubleshooting this error.
------
[2023-01-04T15:57:49.359Z] ERROR: failed to solve: executor failed running [/bin/sh -c cd /tmp/build-features/nix_2 && chmod +x ./devcontainer-features-install.sh && ./devcontainer-features-install.sh]: exit code: 1
[2023-01-04T15:57:49.365Z] Stop (267178 ms): Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-taohansen/container-features/0.25.2-1672847593217/Dockerfile-with-features -t vsc-flask-cockroachdb-devcontainer-fddaab1caaa8f542301775876a0f87bd --target dev_containers_target_stage --build-context dev_containers_feature_content_source=/tmp/devcontainercli-taohansen/container-features/0.25.2-1672847593217 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /home/taohansen/flask-cockroachdb-devcontainer
[2023-01-04T15:57:49.367Z] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-taohansen/container-features/0.25.2-1672847593217/Dockerfile-with-features -t vsc-flask-cockroachdb-devcontainer-fddaab1caaa8f542301775876a0f87bd --target dev_containers_target_stage --build-context dev_containers_feature_content_source=/tmp/devcontainercli-taohansen/container-features/0.25.2-1672847593217 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /home/taohansen/flask-cockroachdb-devcontainer
[2023-01-04T15:57:49.367Z]     at Doe (/home/taohansen/.vscode-remote-containers/dist/dev-containers-cli-0.266.1/dist/spec-node/devContainersSpecCLI.js:1894:1669)
[2023-01-04T15:57:49.367Z]     at runMicrotasks (<anonymous>)
[2023-01-04T15:57:49.368Z]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2023-01-04T15:57:49.368Z]     at async EF (/home/taohansen/.vscode-remote-containers/dist/dev-containers-cli-0.266.1/dist/spec-node/devContainersSpecCLI.js:1893:1978)
[2023-01-04T15:57:49.368Z]     at async uT (/home/taohansen/.vscode-remote-containers/dist/dev-containers-cli-0.266.1/dist/spec-node/devContainersSpecCLI.js:1893:901)
[2023-01-04T15:57:49.368Z]     at async Poe (/home/taohansen/.vscode-remote-containers/dist/dev-containers-cli-0.266.1/dist/spec-node/devContainersSpecCLI.js:1899:2128)
[2023-01-04T15:57:49.369Z]     at async Zf (/home/taohansen/.vscode-remote-containers/dist/dev-containers-cli-0.266.1/dist/spec-node/devContainersSpecCLI.js:1899:3278)
[2023-01-04T15:57:49.369Z]     at async aue (/home/taohansen/.vscode-remote-containers/dist/dev-containers-cli-0.266.1/dist/spec-node/devContainersSpecCLI.js:2020:15276)
[2023-01-04T15:57:49.369Z]     at async oue (/home/taohansen/.vscode-remote-containers/dist/dev-containers-cli-0.266.1/dist/spec-node/devContainersSpecCLI.js:2020:15030)
[2023-01-04T15:57:49.372Z] Stop (277278 ms): Run in Host: /home/taohansen/.vscode-remote-containers/bin/e8a3071ea4344d9d48ef8a4df2c097372b0c5161/node /home/taohansen/.vscode-remote-containers/dist/dev-containers-cli-0.266.1/dist/spec-node/devContainersSpecCLI.js up --workspace-folder /home/taohansen/flask-cockroachdb-devcontainer --workspace-mount-consistency cached --id-label devcontainer.local_folder=\\wsl.localhost\Ubuntu\home\taohansen\flask-cockroachdb-devcontainer --log-level debug --log-format json --config /home/taohansen/flask-cockroachdb-devcontainer/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2023-01-04T15:57:49.373Z] Exit code 1
[2023-01-04T15:57:49.382Z] Command failed: /home/taohansen/.vscode-remote-containers/bin/e8a3071ea4344d9d48ef8a4df2c097372b0c5161/node /home/taohansen/.vscode-remote-containers/dist/dev-containers-cli-0.266.1/dist/spec-node/devContainersSpecCLI.js up --workspace-folder /home/taohansen/flask-cockroachdb-devcontainer --workspace-mount-consistency cached --id-label devcontainer.local_folder=\\wsl.localhost\Ubuntu\home\taohansen\flask-cockroachdb-devcontainer --log-level debug --log-format json --config /home/taohansen/flask-cockroachdb-devcontainer/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2023-01-04T15:57:49.382Z] Exit code 1
[2023-01-04T15:57:53.878Z] Start: Run: wsl -d Ubuntu -e wslpath -u \\wsl.localhost\Ubuntu\home\taohansen\flask-cockroachdb-devcontainer
[2023-01-04T15:57:54.160Z] Stop (282 ms): Run: wsl -d Ubuntu -e wslpath -u \\wsl.localhost\Ubuntu\home\taohansen\flask-cockroachdb-devcontainer

Of course, the package expression here is enclosed so this appears to be a bug in how the Nix feature handles any package declaration more complex than simple package names.

samruddhikhandale commented 1 year ago

Hi @worldofgeese 👋

Currently, the nix packages are installed with nix-env --install * (see here). I don't think that command accepts a complex package name, unless I'm mistaken. (nix-env doc --> https://nixos.org/manual/nix/stable/command-ref/nix-env.html#operation---install)

(google-cloud-sdk.withExtraComponents [google-cloud-sdk.components.gke-gcloud-auth-plugin])

💡 Probably, we could update the Nix Feature and if the option is embedded into a complex expression, we'd add the following commands. However, wondering how to automate google-cloud-sdk ref to gcloud

nix-env -i google-cloud-sdk glcloud components install gke-gcloud-auth-plugin

In the meanwhile, you'd be able to currently resolve this with 👇

{
...
     "features": {
            "nix": {
                "packages": "pdm,kompose,google-cloud-sdk"
            }
        },
        "postCreateCommand": "gcloud components install gke-gcloud-auth-plugin"
    }