2012-01-03 01:16:29 +01:00
|
|
|
|
with import <nix/config.nix>;
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
|
|
builder = builtins.toFile "nar.sh"
|
|
|
|
|
''
|
|
|
|
|
export PATH=${nixBinDir}:${coreutils}
|
|
|
|
|
|
2013-07-01 21:02:36 +02:00
|
|
|
|
if [ $compressionType = xz ]; then
|
|
|
|
|
ext=.xz
|
2013-09-02 13:32:51 +02:00
|
|
|
|
compressor="| ${xz} -7"
|
2013-07-01 21:02:36 +02:00
|
|
|
|
elif [ $compressionType = bzip2 ]; then
|
|
|
|
|
ext=.bz2
|
|
|
|
|
compressor="| ${bzip2}"
|
2012-07-02 00:46:38 +02:00
|
|
|
|
else
|
2013-07-01 21:02:36 +02:00
|
|
|
|
ext=
|
|
|
|
|
compressor=
|
2012-07-02 00:46:38 +02:00
|
|
|
|
fi
|
|
|
|
|
|
2012-01-03 01:16:29 +01:00
|
|
|
|
echo "packing ‘$storePath’..."
|
|
|
|
|
mkdir $out
|
2013-07-01 21:02:36 +02:00
|
|
|
|
dst=$out/tmp.nar$ext
|
2012-01-03 01:16:29 +01:00
|
|
|
|
|
|
|
|
|
set -o pipefail
|
2013-07-01 21:02:36 +02:00
|
|
|
|
eval "nix-store --dump \"$storePath\" $compressor > $dst"
|
2012-01-03 01:16:29 +01:00
|
|
|
|
|
2012-06-29 20:26:31 +02:00
|
|
|
|
hash=$(nix-hash --flat --type $hashAlgo --base32 $dst)
|
|
|
|
|
echo -n $hash > $out/nar-compressed-hash
|
2012-01-03 01:16:29 +01:00
|
|
|
|
|
2013-07-01 21:02:36 +02:00
|
|
|
|
mv $dst $out/$hash.nar$ext
|
2012-01-03 01:16:29 +01:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
2012-07-02 00:46:38 +02:00
|
|
|
|
{ storePath, hashAlgo, compressionType }:
|
2012-01-03 01:16:29 +01:00
|
|
|
|
|
|
|
|
|
derivation {
|
|
|
|
|
name = "nar";
|
2012-04-14 18:48:11 +02:00
|
|
|
|
system = builtins.currentSystem;
|
2012-01-03 01:16:29 +01:00
|
|
|
|
builder = shell;
|
|
|
|
|
args = [ "-e" builder ];
|
2012-07-02 00:46:38 +02:00
|
|
|
|
inherit storePath hashAlgo compressionType;
|
2012-05-10 04:14:36 +02:00
|
|
|
|
|
|
|
|
|
# Don't build in a chroot because Nix's dependencies may not be there.
|
|
|
|
|
__noChroot = true;
|
2013-08-14 21:35:13 +02:00
|
|
|
|
|
|
|
|
|
# Remote machines may not have ${nixBinDir} or ${coreutils} in the same prefixes
|
|
|
|
|
preferLocalBuild = true;
|
2012-01-03 01:16:29 +01:00
|
|
|
|
}
|