summary refs log tree commit diff
path: root/pkgs/build-support/vm/default.nix
diff options
context:
space:
mode:
authorRob Vermaas <rob.vermaas@gmail.com>2011-01-19 09:06:12 +0000
committerRob Vermaas <rob.vermaas@gmail.com>2011-01-19 09:06:12 +0000
commitba233767187878759d779da281c9baf8bc86272d (patch)
tree1131de9ff1b6518eea0f5322eaa31564fae10b24 /pkgs/build-support/vm/default.nix
parenta4877e2d33c9a137b2f536327823c642b78c1343 (diff)
downloadnixpkgs-ba233767187878759d779da281c9baf8bc86272d.tar
nixpkgs-ba233767187878759d779da281c9baf8bc86272d.tar.gz
nixpkgs-ba233767187878759d779da281c9baf8bc86272d.tar.bz2
nixpkgs-ba233767187878759d779da281c9baf8bc86272d.tar.lz
nixpkgs-ba233767187878759d779da281c9baf8bc86272d.tar.xz
nixpkgs-ba233767187878759d779da281c9baf8bc86272d.tar.zst
nixpkgs-ba233767187878759d779da281c9baf8bc86272d.zip
added vm function to extract some filesystem
svn path=/nixpkgs/trunk/; revision=25622
Diffstat (limited to 'pkgs/build-support/vm/default.nix')
-rw-r--r--pkgs/build-support/vm/default.nix43
1 files changed, 43 insertions, 0 deletions
diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix
index 4e63d8082c3..3d8d756e977 100644
--- a/pkgs/build-support/vm/default.nix
+++ b/pkgs/build-support/vm/default.nix
@@ -342,6 +342,49 @@ rec {
     QEMU_OPTS = "-m ${toString (if attrs ? memSize then attrs.memSize else 256)}";
   });
 
+  extractFs = {file, fs ? null} :
+    with pkgs; runInLinuxVM (
+    stdenv.mkDerivation {
+      name = "extract-file";
+      buildInputs = [utillinuxng];
+      buildCommand = ''
+        ln -s ${linux}/lib /lib
+        ${module_init_tools}/sbin/modprobe loop
+        ${module_init_tools}/sbin/modprobe ext4
+        ${module_init_tools}/sbin/modprobe iso9660
+        mknod /dev/loop0 b 7 0
+
+        ensureDir $out
+        ensureDir tmp
+        mount -o loop ${lib.optionalString (fs != null) "-t ${fs} "}${file} tmp
+        cp -R tmp/* $out/
+      '';
+    });
+
+  extractMTDfs = {file, fs ? null} :
+    with pkgs; runInLinuxVM (
+    stdenv.mkDerivation {
+      name = "extract-file-mtd";
+      buildInputs = [utillinuxng mtdutils];
+      buildCommand = ''
+        ln -s ${linux}/lib /lib
+        ${module_init_tools}/sbin/modprobe mtd
+        ${module_init_tools}/sbin/modprobe mtdram total_size=65536
+        ${module_init_tools}/sbin/modprobe mtdchar
+        ${module_init_tools}/sbin/modprobe mtdblock
+        ${module_init_tools}/sbin/modprobe jffs2
+        mknod /dev/mtd0 c 90 0
+        mknod /dev/mtdblock0 b 31 0
+
+        ensureDir $out
+        ensureDir tmp
+
+        dd if=${file} of=/dev/mtd0
+        mount ${lib.optionalString (fs != null) "-t ${fs} "}/dev/mtdblock0 tmp
+
+        cp -R tmp/* $out/
+      '';
+    });
 
   qemuCommandGeneric = ''
     ${kvm}/bin/qemu-system-x86_64 \