Skip to content

Commit a8cf2d3

Browse files
committed
Restore squashfs support with a dubious kludge
1 parent e4f516e commit a8cf2d3

File tree

3 files changed

+77
-35
lines changed

3 files changed

+77
-35
lines changed

checks/mount-grep.nix

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ pkgs: {
1212
imports = [ ../modules/qemu-vm-isolation.nix ];
1313
virtualisation.qemu.isolation.nixStoreFilesystemType = "erofs";
1414
};
15+
privateSquash = _: {
16+
imports = [ ../modules/qemu-vm-isolation.nix ];
17+
virtualisation.qemu.isolation.nixStoreFilesystemType = "squashfs";
18+
};
1519
useNixStoreImage = {
1620
virtualisation = {
1721
sharedDirectories = pkgs.lib.mkForce { };
@@ -22,13 +26,13 @@ pkgs: {
2226

2327
testScript = ''
2428
start_all()
25-
for machine in [shared, private, privateErofs, useNixStoreImage]:
29+
for machine in [shared, private, privateErofs, privateSquash, useNixStoreImage]:
2630
machine.wait_for_unit("multi-user.target")
2731
2832
shared.succeed("[[ $(mount | grep -c virt) -gt 0 ]]")
2933
shared.succeed("[[ -e ${pkgs.pv} ]]")
3034
31-
for machine in [private, privateErofs, useNixStoreImage]:
35+
for machine in [private, privateErofs, privateSquash, useNixStoreImage]:
3236
machine.succeed("[[ $(mount | grep -c virt) -eq 0 ]]")
3337
machine.fail("[[ -e ${pkgs.pv} ]]")
3438
'';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This dubious kludge results from
2+
# https://github.com/NixOS/nixpkgs/pull/236656 requiring filesystems to have labels and
3+
# https://github.com/plougher/squashfs-tools/issues/59 squashfs not supporting labels.
4+
diff --git a/libblkid/src/superblocks/squashfs.c b/libblkid/src/superblocks/squashfs.c
5+
index 4db842493..ed7465882 100644
6+
--- a/libblkid/src/superblocks/squashfs.c
7+
+++ b/libblkid/src/superblocks/squashfs.c
8+
@@ -45,6 +45,11 @@ static int probe_squashfs(blkid_probe pr, const struct blkid_idmag *mag)
9+
10+
blkid_probe_sprintf_version(pr, "%u.%u", vermaj, vermin);
11+
12+
+ {
13+
+ char label_kludge[] = "nix-store";
14+
+ blkid_probe_set_label(pr, label_kludge, sizeof(label_kludge));
15+
+ }
16+
+
17+
return 0;
18+
}
19+

modules/qemu-vm-isolation.nix

+52-33
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,45 @@ let
1616
hostPkgs.closureInfo { rootPaths = config.virtualisation.additionalPaths; };
1717

1818
nixStoreImages = {
19-
ext4 = import (modulesPath + "/../lib/make-disk-image.nix") {
20-
inherit pkgs config lib;
21-
additionalPaths = [ storeContents ];
22-
onlyNixStore = true;
23-
label = "nix-store";
24-
partitionTableType = "none";
25-
installBootLoader = false;
26-
diskSize = "auto";
27-
additionalSpace = "0M";
28-
copyChannel = false;
29-
};
30-
erofs = hostPkgs.runCommand "nix-store-image" { } ''
31-
mkdir $out
32-
cd ${builtins.storeDir}
33-
${hostPkgs.erofs-utils}/bin/mkfs.erofs \
34-
--force-uid=0 \
35-
--force-gid=0 \
36-
-L nix-store \
37-
-U eb176051-bd15-49b7-9e6b-462e0b467019 \
38-
-T 0 \
39-
--exclude-regex="$(
40-
<${storeContents}/store-paths \
41-
sed -e 's^.*/^^g' \
42-
| cut -c -10 \
43-
| ${hostPkgs.python3}/bin/python -c ${
44-
escapeShellArg (builtins.readFile
45-
(modulesPath + "/virtualisation/includes-to-excludes.py"))
46-
} )" \
47-
$out/nixos.img \
48-
.
49-
'';
19+
ext4 = "${
20+
import (modulesPath + "/../lib/make-disk-image.nix") {
21+
inherit pkgs config lib;
22+
additionalPaths = [ storeContents ];
23+
onlyNixStore = true;
24+
label = "nix-store";
25+
partitionTableType = "none";
26+
installBootLoader = false;
27+
diskSize = "auto";
28+
additionalSpace = "0M";
29+
copyChannel = false;
30+
}
31+
}/nixos.img";
32+
erofs = "${
33+
hostPkgs.runCommand "nix-store-image" { } ''
34+
mkdir $out
35+
cd ${builtins.storeDir}
36+
${hostPkgs.erofs-utils}/bin/mkfs.erofs \
37+
--force-uid=0 \
38+
--force-gid=0 \
39+
-L nix-store \
40+
-U eb176051-bd15-49b7-9e6b-462e0b467019 \
41+
-T 0 \
42+
--exclude-regex="$(
43+
<${storeContents}/store-paths \
44+
sed -e 's^.*/^^g' \
45+
| cut -c -10 \
46+
| ${hostPkgs.python3}/bin/python -c ${
47+
escapeShellArg (builtins.readFile
48+
(modulesPath + "/virtualisation/includes-to-excludes.py"))
49+
} )" \
50+
$out/nix-store.img \
51+
.
52+
''
53+
}/nix-store.img";
54+
squashfs =
55+
"${hostPkgs.callPackage (modulesPath + "/../lib/make-squashfs.nix") {
56+
storeContents = config.virtualisation.additionalPaths;
57+
}}";
5058
};
5159

5260
in {
@@ -56,8 +64,11 @@ in {
5664
What filesystem to use for the guest's Nix store.
5765
5866
erofs is more compact than ext4, but less mature.
67+
68+
squashfs support currently requires a dubious kludge that results in these
69+
VMs not being able to mount any other squashfs volumes besides the nix store.
5970
'';
60-
type = lib.types.enum [ "ext4" "erofs" ];
71+
type = lib.types.enum [ "ext4" "erofs" "squashfs" ];
6172
default = "ext4";
6273
};
6374
};
@@ -66,6 +77,14 @@ in {
6677
boot.initrd.kernelModules =
6778
optional (cfg.nixStoreFilesystemType == "erofs") "erofs";
6879

80+
nixpkgs.overlays = optional (cfg.nixStoreFilesystemType == "squashfs")
81+
(final: prev: {
82+
util-linux = prev.util-linux.overrideAttrs (old: {
83+
patches = (old.patches or [ ])
84+
++ [ ./libblkid-squashfs-nix-store-kludge.patch ];
85+
});
86+
});
87+
6988
fileSystems = mkVMOverride {
7089
"${storeMountPath}" = {
7190
fsType = cfg.nixStoreFilesystemType;
@@ -83,7 +102,7 @@ in {
83102
sharedDirectories = mkForce { };
84103

85104
qemu.drives = [{
86-
file = "${config.system.build.nixStoreImage}/nixos.img";
105+
file = config.system.build.nixStoreImage;
87106
driveExtraOpts = {
88107
format = "raw";
89108
read-only = "on";

0 commit comments

Comments
 (0)