Skip to content

Commit

Permalink
Fix nix print-dev-env with drv paths
Browse files Browse the repository at this point in the history
Fixes #8309

This regression was because both `CmdDevelop` and `CmdPrintDevEnv` were
switched to be `InstallableValueCommand` subclasses, but only
`CmdDevelop` should have been.
  • Loading branch information
Ericson2314 committed May 9, 2023
1 parent 4539ab5 commit 55e3715
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/libcmd/command-installable-value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace nix {
* An InstallableCommand where the single positional argument must be an
* InstallableValue in particular.
*/
struct InstallableValueCommand : InstallableCommand
struct InstallableValueCommand : virtual InstallableCommand
{
/**
* Entry point to this command
Expand Down
10 changes: 5 additions & 5 deletions src/nix/develop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static StorePath getDerivationEnvironment(ref<Store> store, ref<Store> evalStore
throw Error("get-env.sh failed to produce an environment");
}

struct Common : InstallableValueCommand, MixProfile
struct Common : virtual InstallableCommand, MixProfile
{
std::set<std::string> ignoreVars{
"BASHOPTS",
Expand Down Expand Up @@ -374,7 +374,7 @@ struct Common : InstallableValueCommand, MixProfile
return res;
}

StorePath getShellOutPath(ref<Store> store, ref<InstallableValue> installable)
StorePath getShellOutPath(ref<Store> store, ref<Installable> installable)
{
auto path = installable->getStorePath();
if (path && hasSuffix(path->to_string(), "-env"))
Expand All @@ -393,7 +393,7 @@ struct Common : InstallableValueCommand, MixProfile
}

std::pair<BuildEnvironment, std::string>
getBuildEnvironment(ref<Store> store, ref<InstallableValue> installable)
getBuildEnvironment(ref<Store> store, ref<Installable> installable)
{
auto shellOutPath = getShellOutPath(store, installable);

Expand All @@ -407,7 +407,7 @@ struct Common : InstallableValueCommand, MixProfile
}
};

struct CmdDevelop : Common, MixEnvironment
struct CmdDevelop : virtual InstallableValueCommand, Common, MixEnvironment
{
std::vector<std::string> command;
std::optional<std::string> phase;
Expand Down Expand Up @@ -605,7 +605,7 @@ struct CmdPrintDevEnv : Common, MixJSON

Category category() override { return catUtility; }

void run(ref<Store> store, ref<InstallableValue> installable) override
void run(ref<Store> store, ref<Installable> installable) override
{
auto buildEnvironment = getBuildEnvironment(store, installable).first;

Expand Down
8 changes: 8 additions & 0 deletions tests/nix-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ nix develop -f "$shellDotNix" shellDrv -c echo foo |& grepQuiet foo
nix print-dev-env -f "$shellDotNix" shellDrv > $TEST_ROOT/dev-env.sh
nix print-dev-env -f "$shellDotNix" shellDrv --json > $TEST_ROOT/dev-env.json

# Test with raw drv

nix print-dev-env $(nix-instantiate "$shellDotNix" -A shellDrv.out) > $TEST_ROOT/dev-env2.sh
nix print-dev-env $(nix-instantiate "$shellDotNix" -A shellDrv.out) --json > $TEST_ROOT/dev-env2.json

diff $TEST_ROOT/dev-env{,2}.sh
diff $TEST_ROOT/dev-env{,2}.json

# Ensure `nix print-dev-env --json` contains variable assignments.
[[ $(jq -r .variables.arr1.value[2] $TEST_ROOT/dev-env.json) = '3 4' ]]

Expand Down

0 comments on commit 55e3715

Please sign in to comment.