Created
May 29, 2017 07:40
-
-
Save lheckemann/4bbdea1195561be93eb2538200eceff1 to your computer and use it in GitHub Desktop.
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
let | |
pkgs = import <nixpkgs> {}; | |
isoWritableModule = { config, pkgs, lib, ... }: | |
{ | |
config = { | |
fileSystems."/0-rw" = { | |
fsType = "ext4"; | |
neededForBoot = true; | |
device = "/dev/disk/by-label/NIXOS_RW"; | |
}; | |
fileSystems."/nix/.rw-store" = lib.mkForce { | |
options = [ "bind" ]; | |
neededForBoot = true; | |
device = "/0-rw/nix-store"; | |
}; | |
fileSystems."/home" = { | |
options = [ "bind" ]; | |
neededForBoot = true; | |
device = "/0-rw/home"; | |
}; | |
}; | |
}; | |
config = (import <nixpkgs/nixos/lib/eval-config.nix> { | |
inherit (pkgs) system; | |
modules = [ | |
./additional-config.nix | |
isoWritableModule | |
<nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix> | |
]; | |
}).config; | |
isoImage = config.system.build.isoImage; | |
in | |
with pkgs; stdenv.mkDerivation { | |
name = "isoWritable.iso"; | |
buildInputs = [ e2fsprogs utillinux ]; | |
buildCommand = '' | |
cp ${config.system.build.isoImage}/iso/*.iso $out | |
chmod u+w $out | |
dd if=/dev/zero of=$out bs=1M count=1024 oflag=append conv=notrunc | |
sfdisk --append $out <<EOF | |
part3 : type=83 | |
EOF | |
offset_sectors=$(sfdisk -l -q -o start $out | tail -n 1) | |
offset=$((512 * $offset_sectors)) | |
dd if=$out of=rw-fs bs=$offset skip=1 | |
mkfs.ext4 -L NIXOS_RW rw-fs | |
debugfs -w rw-fs -f /dev/stdin <<EOF | |
mkdir nix-store | |
mkdir home | |
EOF | |
dd if=rw-fs of=$out conv=notrunc bs=$offset seek=1 | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment