nix dev-shell: Use 'provides.devShell' by default
Thus $ nix dev-shell will now build the 'provides.devShell' attribute from the flake in the current directory. If it doesn't exist, it falls back to 'provides.defaultPackage'.
This commit is contained in:
parent
7dcf5b011a
commit
2919c496ea
5 changed files with 51 additions and 13 deletions
|
@ -17,5 +17,10 @@
|
|||
packages.nix = hydraJobs.build.x86_64-linux;
|
||||
|
||||
defaultPackage = packages.nix;
|
||||
|
||||
devShell = import ./shell.nix {
|
||||
nixpkgs = deps.nixpkgs;
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{ useClang ? false }:
|
||||
{ useClang ? false
|
||||
, nixpkgs ? builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz
|
||||
}:
|
||||
|
||||
with import (builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz) {};
|
||||
with import nixpkgs { system = builtins.currentSystem or "x86_64-linux"; };
|
||||
|
||||
with import ./release-common.nix { inherit pkgs; };
|
||||
|
||||
|
|
|
@ -88,6 +88,11 @@ struct SourceExprCommand : virtual Args, StoreCommand, MixEvalArgs
|
|||
std::shared_ptr<Installable> parseInstallable(
|
||||
ref<Store> store, const std::string & installable);
|
||||
|
||||
virtual Strings getDefaultFlakeAttrPaths()
|
||||
{
|
||||
return {"defaultPackage"};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<EvalState> evalState;
|
||||
|
|
|
@ -142,13 +142,18 @@ struct InstallableAttrPath : InstallableValue
|
|||
struct InstallableFlake : InstallableValue
|
||||
{
|
||||
FlakeRef flakeRef;
|
||||
std::string attrPath;
|
||||
Strings attrPaths;
|
||||
bool searchPackages = false;
|
||||
|
||||
InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef, const std::string & attrPath)
|
||||
: InstallableValue(cmd), flakeRef(flakeRef), attrPath(attrPath)
|
||||
InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef, Strings attrPaths)
|
||||
: InstallableValue(cmd), flakeRef(flakeRef), attrPaths(std::move(attrPaths))
|
||||
{ }
|
||||
|
||||
std::string what() override { return flakeRef.to_string() + ":" + attrPath; }
|
||||
InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef, std::string attrPath)
|
||||
: InstallableValue(cmd), flakeRef(flakeRef), attrPaths{attrPath}, searchPackages(true)
|
||||
{ }
|
||||
|
||||
std::string what() override { return flakeRef.to_string() + ":" + *attrPaths.begin(); }
|
||||
|
||||
Value * toValue(EvalState & state) override
|
||||
{
|
||||
|
@ -166,18 +171,31 @@ struct InstallableFlake : InstallableValue
|
|||
|
||||
auto emptyArgs = state.allocBindings(0);
|
||||
|
||||
if (auto aPackages = *vProvides->attrs->get(state.symbols.create("packages"))) {
|
||||
// As a convenience, look for the attribute in
|
||||
// 'provides.packages'.
|
||||
if (searchPackages) {
|
||||
if (auto aPackages = *vProvides->attrs->get(state.symbols.create("packages"))) {
|
||||
try {
|
||||
auto * v = findAlongAttrPath(state, *attrPaths.begin(), *emptyArgs, *aPackages->value);
|
||||
state.forceValue(*v);
|
||||
return v;
|
||||
} catch (AttrPathNotFound & e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, look for it in 'provides'.
|
||||
for (auto & attrPath : attrPaths) {
|
||||
try {
|
||||
auto * v = findAlongAttrPath(state, attrPath, *emptyArgs, *aPackages->value);
|
||||
auto * v = findAlongAttrPath(state, attrPath, *emptyArgs, *vProvides);
|
||||
state.forceValue(*v);
|
||||
return v;
|
||||
} catch (AttrPathNotFound & e) {
|
||||
}
|
||||
}
|
||||
|
||||
auto * v = findAlongAttrPath(state, attrPath, *emptyArgs, *vProvides);
|
||||
state.forceValue(*v);
|
||||
return v;
|
||||
throw Error("flake '%s' does not provide attribute %s",
|
||||
flakeRef, concatStringsSep(", ", quoteStrings(attrPaths)));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -216,7 +234,8 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
|
|||
else if (hasPrefix(s, "nixpkgs.")) {
|
||||
bool static warned;
|
||||
warnOnce(warned, "the syntax 'nixpkgs.<attr>' is deprecated; use 'nixpkgs:<attr>' instead");
|
||||
result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef("nixpkgs"), std::string(s, 8)));
|
||||
result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef("nixpkgs"),
|
||||
Strings{"packages." + std::string(s, 8)}));
|
||||
}
|
||||
|
||||
else if ((colon = s.rfind(':')) != std::string::npos) {
|
||||
|
@ -233,7 +252,8 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
|
|||
if (storePath != "")
|
||||
result.push_back(std::make_shared<InstallableStorePath>(storePath));
|
||||
else
|
||||
result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef(s, true), "defaultPackage"));
|
||||
result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef(s, true),
|
||||
getDefaultFlakeAttrPaths()));
|
||||
}
|
||||
|
||||
else
|
||||
|
|
|
@ -125,6 +125,7 @@ struct Common : InstallableCommand
|
|||
"BASHOPTS",
|
||||
"EUID",
|
||||
"NIX_BUILD_TOP",
|
||||
"NIX_ENFORCE_PURITY",
|
||||
"PPID",
|
||||
"PWD",
|
||||
"SHELLOPTS",
|
||||
|
@ -156,6 +157,11 @@ struct Common : InstallableCommand
|
|||
for (auto & i : {"TMP", "TMPDIR", "TEMP", "TEMPDIR"})
|
||||
out << fmt("export %s=\"$NIX_BUILD_TOP\"\n", i);
|
||||
}
|
||||
|
||||
Strings getDefaultFlakeAttrPaths() override
|
||||
{
|
||||
return {"devShell", "defaultPackage"};
|
||||
}
|
||||
};
|
||||
|
||||
std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix = "nix")
|
||||
|
|
Loading…
Reference in a new issue