Tom Alexander e65504b5f3
Add a role for mounting the nix store over 9pfs.
This is useful for virtual machines since we can have a persistent /nix/store on the host machine.
2025-05-10 20:47:45 -04:00

78 lines
2.1 KiB
Nix

{
config,
lib,
pkgs,
...
}:
{
imports = [ ];
options.me = {
_9pfs_nix_store.enable = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = "Whether we want to mount /nix/store over 9pfs (useful in virtual machines to share a directory from the host as a persistent nix store.";
};
_9pfs_nix_store.is_iso = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = "Whether this build is for an ISO. It changes how we mount the nix store.";
};
};
config = lib.mkIf config.me._9pfs_nix_store.enable (
lib.mkMerge [
(lib.mkIf config.me._9pfs_nix_store.is_iso {
# fileSystems = {
# "/nix/store" = lib.mkForce {
# fsType = "overlay";
# device = "overlay";
# options = [
# "lowerdir=/nix/.ro-store"
# "upperdir=/store"
# "workdir=/work"
# ];
# depends = [
# "/nix/.ro-store"
# "/store"
# "/work"
# ];
# };
# "/store" = lib.mkForce {
# fsType = "9p";
# device = "nixstore";
# options = [
# "trans=virtio"
# "version=9p2000.L"
# "x-systemd.requires=modprobe@9pnet_virtio.service"
# "msize=16384" # Maximum packet size. Increasing this should improve performance at the cost of increased memory usage.
# "cache=loose"
# ];
# };
# };
})
(lib.mkIf (!config.me._9pfs_nix_store.is_iso) {
fileSystems = {
"/nix/store" = lib.mkForce {
fsType = "9p";
device = "nixstore";
neededForBoot = true;
options = [
"trans=virtio"
"version=9p2000.L"
"x-systemd.requires=modprobe@9pnet_virtio.service"
"msize=16384" # Maximum packet size. Increasing this should improve performance at the cost of increased memory usage.
"cache=loose"
];
};
};
})
]
);
}