devbox icon indicating copy to clipboard operation
devbox copied to clipboard

devbox run command --env-file .env does not load env vars from .env file

Open PhilT opened this issue 1 year ago • 3 comments

What happened?

Running a script does not load the env vars when using --env-file.

Steps to reproduce

  1. devbox init
  2. echo PERSON=Phil > .env
  3. devbox run myscript --env-file .env
Info: Ensuring packages are installed.
✓ Computed the Devbox environment.
Hello,

Command

run, shell

devbox.json

{
  "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.13.6/.schema/devbox.schema.json",
  "packages": [],
  "shell": {
    "init_hook": [
      "echo 'Welcome to devbox!' > /dev/null"
    ],
    "scripts": {
      "myscript": [ "echo Hello, $PERSON" ],
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
  }
}

Devbox version

0.13.6, 0.16.0

Nix version

nix (Nix) 2.24.10, nix (Nix) 2.31.2

What system does this bug occur on?

Linux (x86-64)

Debug logs

DEVBOX_DEBUG=1 devbox run myscript --env-file .env time=2024-12-20T20:42:58.507Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:125 msg="searching for config file (including parent directories)" path=. time=2024-12-20T20:42:58.507Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:146 msg="trying config file" path=devbox.json time=2024-12-20T20:42:58.508Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:133 msg="config file found" path=/data/code/sandbox/devbox.json dur=519.679µs time=2024-12-20T20:42:58.508Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:125 msg="searching for config file (including parent directories)" path=. time=2024-12-20T20:42:58.508Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:146 msg="trying config file" path=devbox.json time=2024-12-20T20:42:58.508Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:133 msg="config file found" path=/data/code/sandbox/devbox.json dur=176.872µs time=2024-12-20T20:42:58.528Z level=DEBUG source=go.jetpack.io/devbox/internal/nix/nix.go:342 msg="nix --version --debug output" out="nix (Nix) 2.24.10\nSystem type: x86_64-linux\nAdditional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux\nFeatures: gc, signed-caches\nSystem configuration file: /etc/nix/nix.conf\nUser configuration files: /home/phil/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/phil/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/phil/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/phil/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf\nStore directory: /nix/store\nState directory: /nix/var/nix\nData directory: /nix/store/42lxam32cqq9sn2zdz4ym6ls2dzmfn19-nix-2.24.10/share\n" time=2024-12-20T20:42:58.528Z level=DEBUG source=go.jetpack.io/devbox/internal/nix/command.go:60 msg="nix command starting" cmd.args="nix --extra-experimental-features ca-derivations --option experimental-features 'nix-command flakes fetch-closure' eval --impure --raw --expr builtins.currentSystem" cmd.path=/run/current-system/sw/bin/nix time=2024-12-20T20:42:58.546Z level=DEBUG source=go.jetpack.io/devbox/internal/nix/command.go:67 msg="nix command exited" cmd.args="nix --extra-experimental-features ca-derivations --option experimental-features 'nix-command flakes fetch-closure' eval --impure --raw --expr builtins.currentSystem" cmd.path=/run/current-system/sw/bin/nix cmd.pid=307553 cmd.code=0 cmd.dur=18.596075ms time=2024-12-20T20:42:58.547Z level=DEBUG source=go.jetpack.io/devbox/internal/boxcli/run.go:104 msg="run script" script=myscript args="[--env-file .env]" time=2024-12-20T20:42:58.547Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:125 msg="searching for config file (including parent directories)" path=. time=2024-12-20T20:42:58.547Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:146 msg="trying config file" path=devbox.json time=2024-12-20T20:42:58.547Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:133 msg="config file found" path=/data/code/sandbox/devbox.json dur=149.617µs time=2024-12-20T20:42:58.547Z level=DEBUG source=go.jetpack.io/devbox/internal/devbox/devbox.go:706 msg="current environment PATH" path=/nix/store/rsl5pj2xkhbrpfw60w8asz6ln27lv5fc-kitty-0.37.0/bin:/nix/store/ym0d0c1hpxinxvr2qrfg1d1b9wnz6i71-imagemagick-7.1.1-40/bin:/nix/store/inpspwqhgpld2zdk89hra7xjh3nxll2x-ncurses-6.4.20221231-dev/bin:/run/wrappers/bin:/home/phil/.nix-profile/bin:/nix/profile/bin:/home/phil/.local/state/nix/profile/bin:/etc/profiles/per-user/phil/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin time=2024-12-20T20:42:58.548Z level=DEBUG source=go.jetpack.io/devbox/internal/devbox/devbox.go:721 msg="nix environment PATH" path=/nix/store/znqwpxy9jlxcgi2ms2hga0ch87bbbr9g-patchelf-0.15.0/bin:/nix/store/zlzz2z48s7ry0hkl55xiqp5a73b4mzrg-gcc-wrapper-12.3.0/bin:/nix/store/0b9bsznqs6pdg42dxcwvrlmarjn2p6a1-gcc-12.3.0/bin:/nix/store/nvh3jgs8pqghnsfzbv28004xkigiw8gc-glibc-2.38-23-bin/bin:/nix/store/vwkvhj69z4qqgmpa2lwm97kabf12p26r-coreutils-9.3/bin:/nix/store/h8d2j0prdf7pnpgyrgkxrrbfwnmxbq6y-binutils-wrapper-2.40/bin:/nix/store/p58l5qmzifl20qmjs3xfpl01f0mqlza2-binutils-2.40/bin:/nix/store/vwkvhj69z4qqgmpa2lwm97kabf12p26r-coreutils-9.3/bin:/nix/store/qyzfglbrqb5ck0dgljplin2bvc4995w7-findutils-4.9.0/bin:/nix/store/x6y2i213maj6ibcn0qzgg7graif5qcvi-diffutils-3.10/bin:/nix/store/g5p3ky90xa05ggg5szyb0pbbl2vp7n03-gnused-4.9/bin:/nix/store/p2r51wfg9m3ga7pp7avslpfhfa7w5y83-gnugrep-3.11/bin:/nix/store/cmn958i8qym0qvmvydl23fh3bm3fbhl7-gawk-5.2.2/bin:/nix/store/f5qy259g9b4qh0hwz22z5j5bq3m53cpv-gnutar-1.35/bin:/nix/store/kmr52zpw7wazxywqvzgpdx0vnn9prd3v-gzip-1.13/bin:/nix/store/w1mar48lwkavwy64mvj567lwaqnm2l11-bzip2-1.0.8-bin/bin:/nix/store/9dh2csn531by6b1vr9jv85v4k17xwkid-gnumake-4.4.1/bin:/nix/store/lf0wpjrj8yx4gsmw2s3xfl58ixmqk8qa-bash-5.2-p15/bin:/nix/store/pinwlz7294p37d2sbkdpjildzxii42vv-patch-2.7.6/bin:/nix/store/skrzk0g88jf9rg28labqsyxv7gg357q1-xz-5.4.4-bin/bin:/nix/store/h5pshzq92r2xcv6w1p10cmkar4nyv0xp-file-5.45/bin time=2024-12-20T20:42:58.548Z level=DEBUG source=go.jetpack.io/devbox/internal/devbox/devbox.go:755 msg="PATH after plugins and config" path=/data/code/sandbox/.devbox/nix/profile/default/bin:/nix/store/znqwpxy9jlxcgi2ms2hga0ch87bbbr9g-patchelf-0.15.0/bin:/nix/store/zlzz2z48s7ry0hkl55xiqp5a73b4mzrg-gcc-wrapper-12.3.0/bin:/nix/store/0b9bsznqs6pdg42dxcwvrlmarjn2p6a1-gcc-12.3.0/bin:/nix/store/nvh3jgs8pqghnsfzbv28004xkigiw8gc-glibc-2.38-23-bin/bin:/nix/store/vwkvhj69z4qqgmpa2lwm97kabf12p26r-coreutils-9.3/bin:/nix/store/h8d2j0prdf7pnpgyrgkxrrbfwnmxbq6y-binutils-wrapper-2.40/bin:/nix/store/p58l5qmzifl20qmjs3xfpl01f0mqlza2-binutils-2.40/bin:/nix/store/qyzfglbrqb5ck0dgljplin2bvc4995w7-findutils-4.9.0/bin:/nix/store/x6y2i213maj6ibcn0qzgg7graif5qcvi-diffutils-3.10/bin:/nix/store/g5p3ky90xa05ggg5szyb0pbbl2vp7n03-gnused-4.9/bin:/nix/store/p2r51wfg9m3ga7pp7avslpfhfa7w5y83-gnugrep-3.11/bin:/nix/store/cmn958i8qym0qvmvydl23fh3bm3fbhl7-gawk-5.2.2/bin:/nix/store/f5qy259g9b4qh0hwz22z5j5bq3m53cpv-gnutar-1.35/bin:/nix/store/kmr52zpw7wazxywqvzgpdx0vnn9prd3v-gzip-1.13/bin:/nix/store/w1mar48lwkavwy64mvj567lwaqnm2l11-bzip2-1.0.8-bin/bin:/nix/store/9dh2csn531by6b1vr9jv85v4k17xwkid-gnumake-4.4.1/bin:/nix/store/lf0wpjrj8yx4gsmw2s3xfl58ixmqk8qa-bash-5.2-p15/bin:/nix/store/pinwlz7294p37d2sbkdpjildzxii42vv-patch-2.7.6/bin:/nix/store/skrzk0g88jf9rg28labqsyxv7gg357q1-xz-5.4.4-bin/bin:/nix/store/h5pshzq92r2xcv6w1p10cmkar4nyv0xp-file-5.45/bin time=2024-12-20T20:42:58.548Z level=DEBUG source=go.jetpack.io/devbox/internal/devbox/devbox.go:779 msg="PATH after filtering buildInputs" inputs=[] path=/data/code/sandbox/.devbox/nix/profile/default/bin:/nix/store/znqwpxy9jlxcgi2ms2hga0ch87bbbr9g-patchelf-0.15.0/bin:/nix/store/zlzz2z48s7ry0hkl55xiqp5a73b4mzrg-gcc-wrapper-12.3.0/bin:/nix/store/0b9bsznqs6pdg42dxcwvrlmarjn2p6a1-gcc-12.3.0/bin:/nix/store/nvh3jgs8pqghnsfzbv28004xkigiw8gc-glibc-2.38-23-bin/bin:/nix/store/vwkvhj69z4qqgmpa2lwm97kabf12p26r-coreutils-9.3/bin:/nix/store/h8d2j0prdf7pnpgyrgkxrrbfwnmxbq6y-binutils-wrapper-2.40/bin:/nix/store/p58l5qmzifl20qmjs3xfpl01f0mqlza2-binutils-2.40/bin:/nix/store/qyzfglbrqb5ck0dgljplin2bvc4995w7-findutils-4.9.0/bin:/nix/store/x6y2i213maj6ibcn0qzgg7graif5qcvi-diffutils-3.10/bin:/nix/store/g5p3ky90xa05ggg5szyb0pbbl2vp7n03-gnused-4.9/bin:/nix/store/p2r51wfg9m3ga7pp7avslpfhfa7w5y83-gnugrep-3.11/bin:/nix/store/cmn958i8qym0qvmvydl23fh3bm3fbhl7-gawk-5.2.2/bin:/nix/store/f5qy259g9b4qh0hwz22z5j5bq3m53cpv-gnutar-1.35/bin:/nix/store/kmr52zpw7wazxywqvzgpdx0vnn9prd3v-gzip-1.13/bin:/nix/store/w1mar48lwkavwy64mvj567lwaqnm2l11-bzip2-1.0.8-bin/bin:/nix/store/9dh2csn531by6b1vr9jv85v4k17xwkid-gnumake-4.4.1/bin:/nix/store/lf0wpjrj8yx4gsmw2s3xfl58ixmqk8qa-bash-5.2-p15/bin:/nix/store/pinwlz7294p37d2sbkdpjildzxii42vv-patch-2.7.6/bin:/nix/store/skrzk0g88jf9rg28labqsyxv7gg357q1-xz-5.4.4-bin/bin:/nix/store/h5pshzq92r2xcv6w1p10cmkar4nyv0xp-file-5.45/bin time=2024-12-20T20:42:58.548Z level=DEBUG source=go.jetpack.io/devbox/internal/devbox/devbox.go:798 msg="new path stack is" path_stack=DEVBOX_NIX_ENV_PATH_45b8163d95e0c55602b2b2a21f097a0866e809d5dff71654dc0fd173a4cee731:DEVBOX_INIT_PATH time=2024-12-20T20:42:58.548Z level=DEBUG source=go.jetpack.io/devbox/internal/devbox/devbox.go:800 msg="computed environment PATH" path=/data/code/sandbox/.devbox/nix/profile/default/bin:/nix/store/znqwpxy9jlxcgi2ms2hga0ch87bbbr9g-patchelf-0.15.0/bin:/nix/store/zlzz2z48s7ry0hkl55xiqp5a73b4mzrg-gcc-wrapper-12.3.0/bin:/nix/store/0b9bsznqs6pdg42dxcwvrlmarjn2p6a1-gcc-12.3.0/bin:/nix/store/nvh3jgs8pqghnsfzbv28004xkigiw8gc-glibc-2.38-23-bin/bin:/nix/store/vwkvhj69z4qqgmpa2lwm97kabf12p26r-coreutils-9.3/bin:/nix/store/h8d2j0prdf7pnpgyrgkxrrbfwnmxbq6y-binutils-wrapper-2.40/bin:/nix/store/p58l5qmzifl20qmjs3xfpl01f0mqlza2-binutils-2.40/bin:/nix/store/qyzfglbrqb5ck0dgljplin2bvc4995w7-findutils-4.9.0/bin:/nix/store/x6y2i213maj6ibcn0qzgg7graif5qcvi-diffutils-3.10/bin:/nix/store/g5p3ky90xa05ggg5szyb0pbbl2vp7n03-gnused-4.9/bin:/nix/store/p2r51wfg9m3ga7pp7avslpfhfa7w5y83-gnugrep-3.11/bin:/nix/store/cmn958i8qym0qvmvydl23fh3bm3fbhl7-gawk-5.2.2/bin:/nix/store/f5qy259g9b4qh0hwz22z5j5bq3m53cpv-gnutar-1.35/bin:/nix/store/kmr52zpw7wazxywqvzgpdx0vnn9prd3v-gzip-1.13/bin:/nix/store/w1mar48lwkavwy64mvj567lwaqnm2l11-bzip2-1.0.8-bin/bin:/nix/store/9dh2csn531by6b1vr9jv85v4k17xwkid-gnumake-4.4.1/bin:/nix/store/lf0wpjrj8yx4gsmw2s3xfl58ixmqk8qa-bash-5.2-p15/bin:/nix/store/pinwlz7294p37d2sbkdpjildzxii42vv-patch-2.7.6/bin:/nix/store/skrzk0g88jf9rg28labqsyxv7gg357q1-xz-5.4.4-bin/bin:/nix/store/h5pshzq92r2xcv6w1p10cmkar4nyv0xp-file-5.45/bin:/data/code/sandbox/.devbox/virtenv/runx/bin:/nix/store/rsl5pj2xkhbrpfw60w8asz6ln27lv5fc-kitty-0.37.0/bin:/nix/store/ym0d0c1hpxinxvr2qrfg1d1b9wnz6i71-imagemagick-7.1.1-40/bin:/nix/store/inpspwqhgpld2zdk89hra7xjh3nxll2x-ncurses-6.4.20221231-dev/bin:/run/wrappers/bin:/home/phil/.nix-profile/bin:/nix/profile/bin:/home/phil/.local/state/nix/profile/bin:/etc/profiles/per-user/phil/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin time=2024-12-20T20:42:58.548Z level=DEBUG source=go.jetpack.io/devbox/internal/nix/run.go:36 msg="executing script" cmd="[/run/current-system/sw/bin/sh -c "/data/code/sandbox/.devbox/gen/scripts/myscript.sh" "--env-file" ".env"]" Hello, time=2024-12-20T20:42:58.552Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:125 msg="searching for config file (including parent directories)" path=. time=2024-12-20T20:42:58.552Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:146 msg="trying config file" path=devbox.json time=2024-12-20T20:42:58.552Z level=DEBUG source=go.jetpack.io/devbox/internal/devconfig/config.go:133 msg="config file found" path=/data/code/sandbox/devbox.json dur=124.994µs

PhilT avatar Dec 20 '24 20:12 PhilT