about summary refs log tree commit diff
path: root/corepkgs/nar.nix
diff options
context:
space:
mode:
Diffstat (limited to 'corepkgs/nar.nix')
-rw-r--r--corepkgs/nar.nix30
1 files changed, 30 insertions, 0 deletions
diff --git a/corepkgs/nar.nix b/corepkgs/nar.nix
new file mode 100644
index 000000000000..70a4af2f9ddb
--- /dev/null
+++ b/corepkgs/nar.nix
@@ -0,0 +1,30 @@
+with import <nix/config.nix>;
+
+let
+
+  builder = builtins.toFile "nar.sh"
+    ''
+      export PATH=${nixBinDir}:${coreutils}
+
+      echo "packing ‘$storePath’..."
+      mkdir $out
+      dst=$out/tmp.nar.bz2
+
+      set -o pipefail
+      nix-store --dump "$storePath" | ${bzip2} > $dst
+
+      nix-hash --flat --type $hashAlgo --base32 $dst > $out/narbz2-hash
+
+      mv $out/tmp.nar.bz2 $out/$(cat $out/narbz2-hash).nar.bz2
+    '';
+
+in
+
+{ system, storePath, hashAlgo }:
+
+derivation {
+  name = "nar";
+  builder = shell;
+  args = [ "-e" builder ];
+  inherit system storePath hashAlgo;
+}