nixos: derived partition GUIDs
This commit is contained in:
parent
d18c6122be
commit
5ebe441c52
|
@ -14,7 +14,7 @@
|
|||
let VFS = Sigil.VFS
|
||||
|
||||
in ${./rom-vfs.dhall}
|
||||
${../partition-type}
|
||||
"${config.block.partitions.store.guid}"
|
||||
Sigil.Init.Resources::{ caps = 256, ram = Sigil.units.MiB 16 }
|
||||
( VFS.vfs
|
||||
[ VFS.leafAttrs
|
||||
|
|
|
@ -4,7 +4,7 @@ let Init = Sigil.Init
|
|||
|
||||
let Child = Init.Child
|
||||
|
||||
in λ(partitionType : Text) →
|
||||
in λ(gptGuid : Text) →
|
||||
λ(resources : Init.Resources.Type) →
|
||||
λ(vfsConfig : Sigil.Prelude.XML.Type) →
|
||||
λ(binary : Text) →
|
||||
|
@ -24,7 +24,7 @@ in λ(partitionType : Text) →
|
|||
}
|
||||
, routes =
|
||||
[ { service = Init.Service::{ name = "Block" }
|
||||
, route = Init.Route.child "drivers" (Some partitionType)
|
||||
, route = Init.Route.child "drivers" (Some gptGuid)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,18 +1,45 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
with lib; {
|
||||
|
||||
options.fileSystems = lib.mkOption {
|
||||
type = types.attrsOf (types.submodule ({ name, config, ... }: {
|
||||
options.block = {
|
||||
|
||||
device = lib.mkOption { type = types.int; };
|
||||
|
||||
driver = lib.mkOption { type = types.enum [ "ahci" "usb" ]; };
|
||||
|
||||
partition = lib.mkOption { type = types.ints.positive; };
|
||||
options = {
|
||||
|
||||
block.partitions = let
|
||||
mkPartitionOption = { description, gptType }: {
|
||||
image = lib.mkOption {
|
||||
type = types.path;
|
||||
inherit description;
|
||||
};
|
||||
gptType = lib.mkOption {
|
||||
type = types.str;
|
||||
default = gptType;
|
||||
};
|
||||
guid = lib.mkOption { type = types.str; };
|
||||
};
|
||||
}));
|
||||
in {
|
||||
esp = mkPartitionOption {
|
||||
description = "EFI system partition";
|
||||
gptType = "c12a7328-f81f-11d2-ba4b-00a0c93ec93b";
|
||||
};
|
||||
store = mkPartitionOption {
|
||||
description = "ERIS store partition";
|
||||
gptType = lib.uuidFrom "ERIS ISO9660";
|
||||
};
|
||||
};
|
||||
|
||||
fileSystems = lib.mkOption {
|
||||
type = types.attrsOf (types.submodule ({ name, config, ... }: {
|
||||
options.block = {
|
||||
|
||||
device = lib.mkOption { type = types.int; };
|
||||
|
||||
driver = lib.mkOption { type = types.enum [ "ahci" "usb" ]; };
|
||||
|
||||
partition = lib.mkOption { type = types.ints.positive; };
|
||||
|
||||
};
|
||||
}));
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
config = {
|
||||
|
@ -22,6 +49,11 @@ with lib; {
|
|||
message = "The only supported fsType is EXT2";
|
||||
}];
|
||||
|
||||
block.partitions.esp = rec {
|
||||
image = import ./lib/make-esp-fs.nix { inherit config pkgs; };
|
||||
guid = lib.uuidFrom (toString image);
|
||||
};
|
||||
|
||||
hardware.genode.ahci.enable =
|
||||
any (fs: fs.block.driver == "ahci") (attrValues config.fileSystems);
|
||||
|
||||
|
|
|
@ -186,18 +186,6 @@ in {
|
|||
description = "Attr set of initial ROM modules";
|
||||
};
|
||||
|
||||
storeFsUuid = mkOption {
|
||||
type = types.str;
|
||||
default = import ./store-fs-uuid;
|
||||
description = "Custom partition type of the nix-store file-system.";
|
||||
};
|
||||
|
||||
storePartUuid = mkOption {
|
||||
type = types.str;
|
||||
default = import ./partition-type;
|
||||
description = "Custom partition type of the nix-store file-system.";
|
||||
};
|
||||
|
||||
storeBackend = mkOption {
|
||||
type = types.enum [ "fs" "memory" ]; # "parent"?
|
||||
default = "memory";
|
||||
|
@ -304,22 +292,17 @@ in {
|
|||
xmllint --noout $out
|
||||
'';
|
||||
|
||||
system.build.storeFsImage =
|
||||
pkgs.callPackage "${modulesPath}/../lib/make-iso9660-image.nix" {
|
||||
contents = builtins.trace (builtins.toJSON erisContents) erisContents;
|
||||
block.partitions.store = rec {
|
||||
image = pkgs.callPackage "${modulesPath}/../lib/make-iso9660-image.nix" {
|
||||
contents = erisContents;
|
||||
compressImage = true;
|
||||
volumeID = "SIGIL";
|
||||
volumeID = "sigil-store";
|
||||
} + "/iso/cd.iso.zst";
|
||||
guid = lib.uuidFrom (toString image);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
virtualisation.diskImage = let
|
||||
espImage = import ./lib/make-esp-fs.nix { inherit config pkgs; };
|
||||
inherit (config.system.build) storeFsImage;
|
||||
bootDriveImage = import ./lib/make-bootable-image.nix {
|
||||
inherit config pkgs espImage;
|
||||
storeFsImage = "${config.system.build.storeFsImage}/iso/cd.iso.zst";
|
||||
};
|
||||
in lib.mkIf (config.genode.boot.storeBackend == "fs") bootDriveImage;
|
||||
virtualisation.diskImage =
|
||||
import ./lib/make-bootable-image.nix { inherit config lib pkgs; };
|
||||
|
||||
virtualisation.useBootLoader = config.genode.boot.storeBackend == "fs";
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# Builds a compressed EFI System Partition image
|
||||
{ config, pkgs, espImage, storeFsImage }:
|
||||
{ config, lib, pkgs }:
|
||||
|
||||
with config.block.partitions;
|
||||
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "boot.qcow2";
|
||||
|
@ -10,61 +12,38 @@ pkgs.stdenv.mkDerivation {
|
|||
zstd
|
||||
];
|
||||
|
||||
inherit espImage;
|
||||
disklabel = lib.uuidFrom config.system.nixos.label;
|
||||
|
||||
buildCommand = ''
|
||||
img=./temp.raw
|
||||
blockSize=512
|
||||
sectorSize=$(( $blockSize * 1 ))
|
||||
imgBytes=0
|
||||
|
||||
espSectorOffset=2048
|
||||
esbByteOffset=$(( $espSectorOffset * $sectorSize ))
|
||||
|
||||
# Pad the front of the image
|
||||
echo "Pad front of image with " $esbByteOffset " bytes"
|
||||
truncate --size=$esbByteOffset $img
|
||||
truncate --size=1M $img
|
||||
|
||||
# Concatentenate the ESP
|
||||
echo "Concatenate ESP $espImage"
|
||||
zstdcat $espImage >> $img
|
||||
espByteOffset=$(stat --printf='%s' $img)
|
||||
zstdcat ${esp.image} >> $img
|
||||
truncate --size=%1M $img
|
||||
|
||||
imgBytes=$(stat --format=%s $img)
|
||||
echo "Image is $(( $imgBytes >> 20 )) MiB with ESP partition"
|
||||
|
||||
nixSectorOffset=$(( ($imgBytes + $sectorSize - 1) / $sectorSize ))
|
||||
nixByteOffset=$(( $nixSectorOffset * $sectorSize ))
|
||||
|
||||
# Pad the ESP
|
||||
echo "Pad end of ESP with " $(( $nixByteOffset - $imgBytes )) " bytes"
|
||||
truncate --size=$nixByteOffset $img
|
||||
|
||||
# Concatenate the nix partition
|
||||
echo "Concatenate store ${storeFsImage}"
|
||||
zstdcat ${storeFsImage} >> $img
|
||||
|
||||
imgBytes=$(stat --format=%s $img)
|
||||
echo "Image is $(( $imgBytes >> 20 )) MiB with store partition"
|
||||
|
||||
endSectorOffset=$(( ($(stat --format=%s $img) + $sectorSize + 1) / $sectorSize ))
|
||||
endByteOffset=$(( $endSectorOffset * $sectorSize ))
|
||||
# Concatenate the store
|
||||
storeByteOffset=$(stat --printf='%s' $img)
|
||||
zstdcat ${store.image} >> $img
|
||||
truncate --size=%1M $img
|
||||
|
||||
# Pad the end of the image
|
||||
echo "Pad end of store with $(( $endByteOffset - $imgBytes )) bytes"
|
||||
truncate --size=$endByteOffset $img
|
||||
truncate --size=+1M $img
|
||||
|
||||
imgBytes=$(stat --format=%s $img)
|
||||
echo "Image is $(( $imgBytes >> 20 )) MiB with final padding"
|
||||
|
||||
efiUuid=C12A7328-F81F-11D2-BA4B-00A0C93EC93B
|
||||
|
||||
# Create the partition table
|
||||
sectorSize=512
|
||||
sfdisk $img <<EOF
|
||||
label: gpt
|
||||
label-id: 44444444-4444-4444-8888-888888888888
|
||||
start=$nixSectorOffset, type=${config.genode.boot.storePartUuid}
|
||||
start=$espSectorOffset, type=$efiUuid
|
||||
label-id: $disklabel
|
||||
start=$(( $storeByteOffset / $sectorSize )), uuid=${store.guid}, type=${store.gptType}
|
||||
start=$(( $espByteOffset / $sectorSize )), uuid=${esp.guid}, type=${esp.gptType}
|
||||
EOF
|
||||
sfdisk --reorder $img
|
||||
|
||||
qemu-img convert -f raw -O qcow2 $img $out
|
||||
'';
|
||||
|
|
Loading…
Reference in New Issue