From ba85e37f0edfee4166bcdd60d71eeeb29751581b Mon Sep 17 00:00:00 2001 From: nohzafk <149959021+nohzafk@users.noreply.github.com> Date: Mon, 1 Jan 2024 21:39:37 +0800 Subject: [PATCH] add test and fix problem --- src/nix/post-install-steps.sh | 4 ++-- test/nix/packages-use-attr-path.sh | 35 ++++++++++++++++++++++++++++++ test/nix/scenarios.json | 13 ++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100755 test/nix/packages-use-attr-path.sh diff --git a/src/nix/post-install-steps.sh b/src/nix/post-install-steps.sh index 2b4452280..6b1cba472 100755 --- a/src/nix/post-install-steps.sh +++ b/src/nix/post-install-steps.sh @@ -20,10 +20,10 @@ if [ ! -z "${PACKAGES}" ] && [ "${PACKAGES}" != "none" ]; then if [ "${USEATTRPATH}" = "true" ]; then PACKAGES=$(add_nixpkgs_prefix "$PACKAGES") echo "Installing packages \"${PACKAGES}\" in profile..." - nix-env -iA "${PACKAGES}" + nix-env -iA ${PACKAGES} else echo "Installing packages \"${PACKAGES}\" in profile..." - nix-env --install "${PACKAGES}" + nix-env --install ${PACKAGES} fi fi diff --git a/test/nix/packages-use-attr-path.sh b/test/nix/packages-use-attr-path.sh new file mode 100755 index 000000000..7f34a96ea --- /dev/null +++ b/test/nix/packages-use-attr-path.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +uid="$(id -u)" +echo "Current user UID is ${uid}." +if [ "${uid}" != "1000" ]; then + echo "Current user UID was adjusted." +fi +set +e +vscode_uid="$(id -u vscode)" +set -e +if [ "${vscode_uid}" != "" ]; then + echo "User vscode UID is ${vscode_uid}." + if [ "${vscode_uid}" != "1000" ]; then + echo "User vscode UID was adjusted." + fi +fi +nix_uid="$(stat /nix -c "%u")" +echo "/nix UID is ${nix_uid}." + +cat /etc/os-release + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. +check "nix-env" type nix-env +check "vim_installed" type vim +check "node_installed" type node +check "yarn_installed" type yarn + +# Report result +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults &2>1 diff --git a/test/nix/scenarios.json b/test/nix/scenarios.json index c287f58c7..e976955af 100644 --- a/test/nix/scenarios.json +++ b/test/nix/scenarios.json @@ -81,6 +81,17 @@ } } }, + "packages-use-attr-path": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "remoteUser": "vscode", + "features": { + "nix": { + "packages": "nodePackages.nodejs,nixpkgs.vim,nixpkgs.yarn", + "useAttrPath": true + } + } + }, + "flake": { "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "remoteUser": "vscode", @@ -99,4 +110,4 @@ } } } -} \ No newline at end of file +}