2023-02-03 17:21:47 +01:00
|
|
|
#include "installable-derived-path.hh"
|
|
|
|
#include "derivations.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
std::string InstallableDerivedPath::what() const
|
|
|
|
{
|
|
|
|
return derivedPath.to_string(*store);
|
|
|
|
}
|
|
|
|
|
|
|
|
DerivedPathsWithInfo InstallableDerivedPath::toDerivedPaths()
|
|
|
|
{
|
|
|
|
return {{.path = derivedPath, .info = {} }};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<StorePath> InstallableDerivedPath::getStorePath()
|
|
|
|
{
|
|
|
|
return std::visit(overloaded {
|
|
|
|
[&](const DerivedPath::Built & bfd) {
|
|
|
|
return bfd.drvPath;
|
|
|
|
},
|
|
|
|
[&](const DerivedPath::Opaque & bo) {
|
|
|
|
return bo.path;
|
|
|
|
},
|
|
|
|
}, derivedPath.raw());
|
|
|
|
}
|
|
|
|
|
|
|
|
InstallableDerivedPath InstallableDerivedPath::parse(
|
|
|
|
ref<Store> store,
|
|
|
|
std::string_view prefix,
|
|
|
|
ExtendedOutputsSpec extendedOutputsSpec)
|
|
|
|
{
|
|
|
|
auto derivedPath = std::visit(overloaded {
|
Get rid of `.drv` special-casing for store path installables
The release notes document the change in behavior, I don't include it
here so there is no risk to it getting out of sync.
> Motivation
>> Plumbing CLI should be simple
Store derivation installations are intended as "plumbing": very simple
utilities for advanced users and scripts, and not what regular users
interact with. (Similarly, regular Git users will use branch and tag
names not explicit hashes for most things.)
The plumbing CLI should prize simplicity over convenience; that is its
raison d'etre. If the user provides a path, we should treat it the same
way not caring what sort of path it is.
>> Scripting
This is especially important for the scripting use-case. when arbitrary
paths are sent to e.g. `nix copy` and the script author wants consistent
behavior regardless of what those store paths are. Otherwise the script
author needs to be careful to filter out `.drv` ones, and then run `nix
copy` again with those paths and `--derivation`. That is not good!
>> Surprisingly low impact
Only two lines in the tests need changing, showing that the impact of
this is pretty light.
Many command, like `nix log` will continue to work with just the
derivation passed as before. This because we used to:
- Special case the drv path and replace it with it's outputs (what this
gets rid of).
- Turn those output path *back* into the original drv path.
Now we just skip that entire round trip!
> Context
Issue #7261 lays out a broader vision for getting rid of `--derivation`,
and has this as one of its dependencies. But we can do this with or
without that.
`Installable::toDerivations` is changed to handle the case of a
`DerivedPath::Opaque` ending in `.drv`, which is new: it simply doesn't
need to do any extra work in that case. On this basis, commands like
`nix {show-derivation,log} /nix/store/...-foo.drv` still work as before,
as described above.
When testing older daemons, the post-build-hook will be run against the
old CLI, so we need the old version of the post-build-hook to support
that use-case.
Co-authored-by: Travis A. Everett <travis.a.everett@gmail.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2022-12-16 04:44:14 +01:00
|
|
|
// If the user did not use ^, we treat the output more
|
|
|
|
// liberally: we accept a symlink chain or an actual
|
|
|
|
// store path.
|
2023-02-03 17:21:47 +01:00
|
|
|
[&](const ExtendedOutputsSpec::Default &) -> DerivedPath {
|
|
|
|
auto storePath = store->followLinksToStorePath(prefix);
|
Get rid of `.drv` special-casing for store path installables
The release notes document the change in behavior, I don't include it
here so there is no risk to it getting out of sync.
> Motivation
>> Plumbing CLI should be simple
Store derivation installations are intended as "plumbing": very simple
utilities for advanced users and scripts, and not what regular users
interact with. (Similarly, regular Git users will use branch and tag
names not explicit hashes for most things.)
The plumbing CLI should prize simplicity over convenience; that is its
raison d'etre. If the user provides a path, we should treat it the same
way not caring what sort of path it is.
>> Scripting
This is especially important for the scripting use-case. when arbitrary
paths are sent to e.g. `nix copy` and the script author wants consistent
behavior regardless of what those store paths are. Otherwise the script
author needs to be careful to filter out `.drv` ones, and then run `nix
copy` again with those paths and `--derivation`. That is not good!
>> Surprisingly low impact
Only two lines in the tests need changing, showing that the impact of
this is pretty light.
Many command, like `nix log` will continue to work with just the
derivation passed as before. This because we used to:
- Special case the drv path and replace it with it's outputs (what this
gets rid of).
- Turn those output path *back* into the original drv path.
Now we just skip that entire round trip!
> Context
Issue #7261 lays out a broader vision for getting rid of `--derivation`,
and has this as one of its dependencies. But we can do this with or
without that.
`Installable::toDerivations` is changed to handle the case of a
`DerivedPath::Opaque` ending in `.drv`, which is new: it simply doesn't
need to do any extra work in that case. On this basis, commands like
`nix {show-derivation,log} /nix/store/...-foo.drv` still work as before,
as described above.
When testing older daemons, the post-build-hook will be run against the
old CLI, so we need the old version of the post-build-hook to support
that use-case.
Co-authored-by: Travis A. Everett <travis.a.everett@gmail.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2022-12-16 04:44:14 +01:00
|
|
|
// Remove this prior to stabilizing the new CLI.
|
|
|
|
if (storePath.isDerivation()) {
|
|
|
|
auto oldDerivedPath = DerivedPath::Built {
|
|
|
|
.drvPath = storePath,
|
|
|
|
.outputs = OutputsSpec::All { },
|
2023-02-03 17:21:47 +01:00
|
|
|
};
|
Get rid of `.drv` special-casing for store path installables
The release notes document the change in behavior, I don't include it
here so there is no risk to it getting out of sync.
> Motivation
>> Plumbing CLI should be simple
Store derivation installations are intended as "plumbing": very simple
utilities for advanced users and scripts, and not what regular users
interact with. (Similarly, regular Git users will use branch and tag
names not explicit hashes for most things.)
The plumbing CLI should prize simplicity over convenience; that is its
raison d'etre. If the user provides a path, we should treat it the same
way not caring what sort of path it is.
>> Scripting
This is especially important for the scripting use-case. when arbitrary
paths are sent to e.g. `nix copy` and the script author wants consistent
behavior regardless of what those store paths are. Otherwise the script
author needs to be careful to filter out `.drv` ones, and then run `nix
copy` again with those paths and `--derivation`. That is not good!
>> Surprisingly low impact
Only two lines in the tests need changing, showing that the impact of
this is pretty light.
Many command, like `nix log` will continue to work with just the
derivation passed as before. This because we used to:
- Special case the drv path and replace it with it's outputs (what this
gets rid of).
- Turn those output path *back* into the original drv path.
Now we just skip that entire round trip!
> Context
Issue #7261 lays out a broader vision for getting rid of `--derivation`,
and has this as one of its dependencies. But we can do this with or
without that.
`Installable::toDerivations` is changed to handle the case of a
`DerivedPath::Opaque` ending in `.drv`, which is new: it simply doesn't
need to do any extra work in that case. On this basis, commands like
`nix {show-derivation,log} /nix/store/...-foo.drv` still work as before,
as described above.
When testing older daemons, the post-build-hook will be run against the
old CLI, so we need the old version of the post-build-hook to support
that use-case.
Co-authored-by: Travis A. Everett <travis.a.everett@gmail.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2022-12-16 04:44:14 +01:00
|
|
|
warn(
|
|
|
|
"The interpretation of store paths arguments ending in `.drv` recently changed. If this command is now failing try again with '%s'",
|
|
|
|
oldDerivedPath.to_string(*store));
|
|
|
|
};
|
|
|
|
return DerivedPath::Opaque {
|
|
|
|
.path = std::move(storePath),
|
|
|
|
};
|
2023-02-03 17:21:47 +01:00
|
|
|
},
|
|
|
|
// If the user did use ^, we just do exactly what is written.
|
|
|
|
[&](const ExtendedOutputsSpec::Explicit & outputSpec) -> DerivedPath {
|
|
|
|
return DerivedPath::Built {
|
|
|
|
.drvPath = store->parseStorePath(prefix),
|
|
|
|
.outputs = outputSpec,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
}, extendedOutputsSpec.raw());
|
|
|
|
return InstallableDerivedPath {
|
|
|
|
store,
|
|
|
|
std::move(derivedPath),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|