mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
Merge pull request #5047 from symphorien/fix-nix-channel
nix-channel: use nix-env -i --remove-all to upgrade
This commit is contained in:
commit
23ea1e46cc
2 changed files with 31 additions and 29 deletions
|
@ -88,15 +88,6 @@ static void update(const StringSet & channelNames)
|
||||||
for (const auto & channel : channels) {
|
for (const auto & channel : channels) {
|
||||||
auto name = channel.first;
|
auto name = channel.first;
|
||||||
auto url = channel.second;
|
auto url = channel.second;
|
||||||
if (!(channelNames.empty() || channelNames.count(name)))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// We want to download the url to a file to see if it's a tarball while also checking if we
|
|
||||||
// got redirected in the process, so that we can grab the various parts of a nix channel
|
|
||||||
// definition from a consistent location if the redirect changes mid-download.
|
|
||||||
auto result = fetchers::downloadFile(store, url, std::string(baseNameOf(url)), false);
|
|
||||||
auto filename = store->toRealPath(result.storePath);
|
|
||||||
url = result.effectiveUrl;
|
|
||||||
|
|
||||||
// If the URL contains a version number, append it to the name
|
// If the URL contains a version number, append it to the name
|
||||||
// attribute (so that "nix-env -q" on the channels profile
|
// attribute (so that "nix-env -q" on the channels profile
|
||||||
|
@ -109,30 +100,43 @@ static void update(const StringSet & channelNames)
|
||||||
|
|
||||||
std::string extraAttrs;
|
std::string extraAttrs;
|
||||||
|
|
||||||
bool unpacked = false;
|
if (!(channelNames.empty() || channelNames.count(name))) {
|
||||||
if (std::regex_search(filename, std::regex("\\.tar\\.(gz|bz2|xz)$"))) {
|
// no need to update this channel, reuse the existing store path
|
||||||
runProgram(settings.nixBinDir + "/nix-build", false, { "--no-out-link", "--expr", "import " + unpackChannelPath +
|
Path symlink = profile + "/" + name;
|
||||||
"{ name = \"" + cname + "\"; channelName = \"" + name + "\"; src = builtins.storePath \"" + filename + "\"; }" });
|
Path storepath = dirOf(readLink(symlink));
|
||||||
unpacked = true;
|
exprs.push_back("f: rec { name = \"" + cname + "\"; type = \"derivation\"; outputs = [\"out\"]; system = \"builtin\"; outPath = builtins.storePath \"" + storepath + "\"; out = { inherit outPath; };}");
|
||||||
}
|
} else {
|
||||||
|
// We want to download the url to a file to see if it's a tarball while also checking if we
|
||||||
|
// got redirected in the process, so that we can grab the various parts of a nix channel
|
||||||
|
// definition from a consistent location if the redirect changes mid-download.
|
||||||
|
auto result = fetchers::downloadFile(store, url, std::string(baseNameOf(url)), false);
|
||||||
|
auto filename = store->toRealPath(result.storePath);
|
||||||
|
url = result.effectiveUrl;
|
||||||
|
|
||||||
if (!unpacked) {
|
bool unpacked = false;
|
||||||
// Download the channel tarball.
|
if (std::regex_search(filename, std::regex("\\.tar\\.(gz|bz2|xz)$"))) {
|
||||||
try {
|
runProgram(settings.nixBinDir + "/nix-build", false, { "--no-out-link", "--expr", "import " + unpackChannelPath +
|
||||||
filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.xz", "nixexprs.tar.xz", false).storePath);
|
"{ name = \"" + cname + "\"; channelName = \"" + name + "\"; src = builtins.storePath \"" + filename + "\"; }" });
|
||||||
} catch (FileTransferError & e) {
|
unpacked = true;
|
||||||
filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.bz2", "nixexprs.tar.bz2", false).storePath);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Regardless of where it came from, add the expression representing this channel to accumulated expression
|
if (!unpacked) {
|
||||||
exprs.push_back("f: f { name = \"" + cname + "\"; channelName = \"" + name + "\"; src = builtins.storePath \"" + filename + "\"; " + extraAttrs + " }");
|
// Download the channel tarball.
|
||||||
|
try {
|
||||||
|
filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.xz", "nixexprs.tar.xz", false).storePath);
|
||||||
|
} catch (FileTransferError & e) {
|
||||||
|
filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.bz2", "nixexprs.tar.bz2", false).storePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Regardless of where it came from, add the expression representing this channel to accumulated expression
|
||||||
|
exprs.push_back("f: f { name = \"" + cname + "\"; channelName = \"" + name + "\"; src = builtins.storePath \"" + filename + "\"; " + extraAttrs + " }");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unpack the channel tarballs into the Nix store and install them
|
// Unpack the channel tarballs into the Nix store and install them
|
||||||
// into the channels profile.
|
// into the channels profile.
|
||||||
std::cerr << "unpacking channels...\n";
|
std::cerr << "unpacking channels...\n";
|
||||||
Strings envArgs{ "--profile", profile, "--file", unpackChannelPath, "--install", "--from-expression" };
|
Strings envArgs{ "--profile", profile, "--file", unpackChannelPath, "--install", "--remove-all", "--from-expression" };
|
||||||
for (auto & expr : exprs)
|
for (auto & expr : exprs)
|
||||||
envArgs.push_back(std::move(expr));
|
envArgs.push_back(std::move(expr));
|
||||||
envArgs.push_back("--quiet");
|
envArgs.push_back("--quiet");
|
||||||
|
|
|
@ -35,16 +35,14 @@ grep -q 'item.*attrPath="foo".*name="dependencies-top"' $TEST_ROOT/meta.xml
|
||||||
nix-env -i dependencies-top
|
nix-env -i dependencies-top
|
||||||
[ -e $TEST_HOME/.nix-profile/foobar ]
|
[ -e $TEST_HOME/.nix-profile/foobar ]
|
||||||
|
|
||||||
clearProfiles
|
|
||||||
rm -f $TEST_HOME/.nix-channels
|
|
||||||
|
|
||||||
# Test updating from a tarball
|
# Test updating from a tarball
|
||||||
nix-channel --add file://$TEST_ROOT/foo/nixexprs.tar.bz2 foo
|
nix-channel --add file://$TEST_ROOT/foo/nixexprs.tar.bz2 bar
|
||||||
nix-channel --update
|
nix-channel --update
|
||||||
|
|
||||||
# Do a query.
|
# Do a query.
|
||||||
nix-env -qa \* --meta --xml --out-path > $TEST_ROOT/meta.xml
|
nix-env -qa \* --meta --xml --out-path > $TEST_ROOT/meta.xml
|
||||||
grep -q 'meta.*description.*Random test package' $TEST_ROOT/meta.xml
|
grep -q 'meta.*description.*Random test package' $TEST_ROOT/meta.xml
|
||||||
|
grep -q 'item.*attrPath="bar".*name="dependencies-top"' $TEST_ROOT/meta.xml
|
||||||
grep -q 'item.*attrPath="foo".*name="dependencies-top"' $TEST_ROOT/meta.xml
|
grep -q 'item.*attrPath="foo".*name="dependencies-top"' $TEST_ROOT/meta.xml
|
||||||
|
|
||||||
# Do an install.
|
# Do an install.
|
||||||
|
|
Loading…
Reference in a new issue