-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make <nix/unpack-channel.nix> a builtin builder
This was the last function using a shell script, so this allows us to get rid of tar, coreutils, bash etc.
- Loading branch information
Showing
9 changed files
with
55 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,12 @@ | ||
with import <nix/config.nix>; | ||
|
||
let | ||
|
||
builder = builtins.toFile "unpack-channel.sh" | ||
'' | ||
mkdir $out | ||
cd $out | ||
xzpat="\.xz\$" | ||
gzpat="\.gz\$" | ||
if [[ "$src" =~ $xzpat ]]; then | ||
${xz} -d < $src | ${tar} xf - ${tarFlags} | ||
elif [[ "$src" =~ $gzpat ]]; then | ||
${gzip} -d < $src | ${tar} xf - ${tarFlags} | ||
else | ||
${bzip2} -d < $src | ${tar} xf - ${tarFlags} | ||
fi | ||
if [ * != $channelName ]; then | ||
mv * $out/$channelName | ||
fi | ||
''; | ||
|
||
in | ||
|
||
{ name, channelName, src }: | ||
|
||
derivation { | ||
system = builtins.currentSystem; | ||
builder = shell; | ||
args = [ "-e" builder ]; | ||
inherit name channelName src; | ||
builder = "builtin:unpack-channel"; | ||
|
||
system = "builtin"; | ||
|
||
PATH = "${nixBinDir}:${coreutils}"; | ||
inherit name channelName src; | ||
|
||
# No point in doing this remotely. | ||
preferLocalBuild = true; | ||
|
||
inherit chrootDeps; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "rust.hh" | ||
#include "builtins.hh" | ||
#include "compression.hh" | ||
|
||
namespace nix { | ||
|
||
void builtinUnpackChannel(const BasicDerivation & drv) | ||
{ | ||
auto getAttr = [&](const string & name) { | ||
auto i = drv.env.find(name); | ||
if (i == drv.env.end()) throw Error("attribute '%s' missing", name); | ||
return i->second; | ||
}; | ||
|
||
Path out = getAttr("out"); | ||
auto channelName = getAttr("channelName"); | ||
auto src = getAttr("src"); | ||
|
||
createDirs(out); | ||
|
||
auto source = sinkToSource([&](Sink & sink) { | ||
auto decompressor = | ||
hasSuffix(src, ".bz2") ? makeDecompressionSink("bzip2", sink) : | ||
hasSuffix(src, ".xz") ? makeDecompressionSink("xz", sink) : | ||
makeDecompressionSink("none", sink); | ||
readFile(src, *decompressor); | ||
decompressor->finish(); | ||
}); | ||
|
||
unpack_tarfile(*source, out); | ||
|
||
auto entries = readDirectory(out); | ||
if (entries.size() != 1) | ||
throw Error("channel tarball '%s' contains more than one file", src); | ||
if (rename((out + "/" + entries[0].name).c_str(), (out + "/" + channelName).c_str()) == -1) | ||
throw SysError("renaming channel directory"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters