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

feat: add devenv.flakeArgs to avoid --no-pure-eval #1418

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/devenv-devShell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pkgs.writeScriptBin "devenv" ''

case $command in
up)
procfilescript=$(nix build '.#${shellPrefix (config._module.args.name or "default")}devenv-up' --no-link --print-out-paths --no-pure-eval)
procfilescript=$(nix build '.#${shellPrefix (config._module.args.name or "default")}devenv-up' --no-link --print-out-paths ${lib.escapeShellArgs config.devenv.flakeArgs})
if [ "$(cat $procfilescript|tail -n +2)" = "" ]; then
echo "No 'processes' option defined: https://devenv.sh/processes/"
exit 1
Expand Down
12 changes: 12 additions & 0 deletions src/modules/top-level.nix
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ in
default = builtins.getEnv "PWD";
};

flakeArgs = lib.mkOption {
type = types.listOf types.str;
internal = true;
default = [ "--override-input" "devenv-root" "path:.devenv/state/pwd" ];
};

dotfile = lib.mkOption {
type = types.str;
internal = true;
Expand Down Expand Up @@ -272,6 +278,12 @@ in
fi

mkdir -p "$DEVENV_STATE"

# The pwd file might not exist if the DEVENV_ROOT and DEVENV_STATE are determined from `--no-pure-eval` instead of `--override-input`, for example, when running `nix develop --no-pure-eval --command devenv up`, so we need to create it here
if [ "$DEVENV_ROOT" != "$(< "$DEVENV_STATE/pwd")" ]; then
printf %s "$DEVENV_ROOT" > "$DEVENV_STATE/pwd"
fi

if [ ! -L "$DEVENV_DOTFILE/profile" ] || [ "$(${pkgs.coreutils}/bin/readlink $DEVENV_DOTFILE/profile)" != "${profile}" ]
then
ln -snf ${profile} "$DEVENV_DOTFILE/profile"
Expand Down
10 changes: 7 additions & 3 deletions templates/flake-parts/.envrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ fi
nix_direnv_watch_file flake.nix
nix_direnv_watch_file flake.lock

DEVENV_ROOT_FILE="$(mktemp)"
printf %s "$PWD" > "$DEVENV_ROOT_FILE"
if ! use flake . --override-input devenv-root "file+file://$DEVENV_ROOT_FILE"
mkdir -p .devenv/state/
if [ "$PWD" != "$(<.devenv/state/pwd)" ]
then
printf %s "$PWD" > .devenv/state/pwd
fi

if ! use flake . --override-input devenv-root path:.devenv/state/pwd
then
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi