Created
January 3, 2013 04:48
-
-
Save aszlig/4440849 to your computer and use it in GitHub Desktop.
Charon test network for btrfs kernel development.
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
{ | |
network.description = "Btrfs test"; | |
network.enableRollback = true; | |
btrfs = { pkgs, config, ... }: { | |
deployment = { | |
targetEnv = "virtualbox"; | |
virtualbox.headless = true; | |
virtualbox.memorySize = 1024; | |
}; | |
nixpkgs.config = { | |
packageOverrides = p: { | |
btrfsProgs = pkgs.lib.overrideDerivation p.btrfsProgs (o: { | |
prePatch = '' | |
sed -i -e 's/^progs *= */&btrfs-corrupt-block /' Makefile | |
''; | |
patches = pkgs.lib.singleton ../btrfs-progs/current.patch; | |
}); | |
}; | |
}; | |
boot = let | |
part = "/dev/disk/by-label/nixos"; | |
in { | |
loader.grub.version = 2; | |
initrd.postDeviceCommands = '' | |
if [ "x$(tail -c+65601 "${part}" | head -c8)" != "x_BHRfS_M" ]; then | |
${pkgs.btrfsProgs}/bin/btrfs-convert "${part}" | |
mkdir /corrupt_me | |
mount "${part}" /corrupt_me | |
dd if=/dev/zero of=/corrupt_me/corrupt bs=512 count=10 | |
echo 'hello btrfs!' >> /corrupt_me/corrupt | |
laddr="$("${pkgs.e2fsprogs}/sbin/filefrag" \ | |
-vs /corrupt_me/corrupt | | |
sed -rn -e 's/^.*blocksize *([0-9]+).*$/\1 * /p' \ | |
-e 's/^( +[0-9]+){2} *([0-9]+).*$/\2/p' | | |
tr -d '\n' | xargs expr)" | |
umount /corrupt_me | |
"${pkgs.btrfsProgs}/bin/btrfs-corrupt-block" \ | |
-b 5133 -l "$laddr" "${part}" | |
export just_converted_to_btrfs=yes | |
fi | |
''; | |
postBootCommands = with pkgs; '' | |
if [ "x$just_converted_to_btrfs" = xyes ]; then | |
PATH="${gnused}/bin:${gnugrep}/bin:${findutils}/bin:$PATH" \ | |
${grub2}/sbin/grub-install --modules=btrfs --recheck \ | |
"${config.boot.loader.grub.device}" | |
fi | |
''; | |
kernelPackages = with pkgs; let | |
workPatch = { | |
name = "btrfs-workingdir.patch"; | |
patch = ../linux/current.patch; | |
}; | |
version = "3.8.0-rc1"; | |
src = fetchgit { | |
url = builtins.getEnv "HOME" + "/linux"; | |
rev = "ad4b3fb7ff9940bcdb1e4cd62bd189d10fa636ba"; | |
sha256 = "12h8v4ay6ykjvs933vnqrrq3gsyd4hs62rajjs78fbb7xvgzd901"; | |
}; | |
configfile = let | |
getCfgLine = builtins.getAttr "configLine"; | |
minCfgLines = map getCfgLine config.system.requiredKernelConfig; | |
cfgLines = minCfgLines ++ map (c: "CONFIG_${c}=y") [ | |
"SMP" "SCHED_SMT" "NUMA" "PM" "ACPI" "EXPERIMENTAL" "NO_HZ" | |
"I2C" "I2C_PIIX4" "I2C_HELPER_AUTO" "AGP" "AGP_INTEL" | |
"PCI" "PCIEPORTBUS" "PCI_MMCONFIG" "IRQ_DOMAIN" | |
"INET" "PACKET" "NETDEVICES" "NET_CORE" "MII" "VIRTIO_NET" | |
"ETHERNET" "NET_VENDOR_INTEL" "E1000E" "NET_VENDOR_AMD" "PCNET32" | |
"BLK_DEV_SD" "BLK_DEV_SR" "CHR_DEV_SG" | |
"ATA" "SATA_AHCI" "ATA_ACPI" "SATA_PMP" | |
"RTC_CLASS" "RTC_DRV_CMOS" "PROC_FS" "PROC_EVENTS" "SYSFS" | |
"VIRTIO_CONSOLE" "VIRTIO_BLK" "VIRTIO_PCI" | |
"BTRFS_FS" | |
]; | |
cfg = builtins.toFile "config" (lib.concatStringsSep "\n" cfgLines); | |
in stdenv.mkDerivation { | |
name = "minimal.kconf"; | |
inherit src; | |
buildCommand = '' | |
make -C "$src" alldefconfig \ | |
"KBUILD_OUTPUT=$(pwd)" \ | |
"KCONFIG_ALLCONFIG=${cfg}" | |
cp .config "$out" | |
''; | |
}; | |
linux = linuxManualConfig { | |
kernelPatches = lib.singleton workPatch; | |
inherit src version configfile; | |
allowImportFromDerivation = true; | |
}; | |
kpkg = linuxPackagesFor linux kpkg; | |
in kpkg; | |
}; | |
fileSystems."/".fsType = "btrfs"; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment