Merge pull request #70 from nix-community/tmpfs

This commit is contained in:
Lassulus 2022-12-04 13:21:42 +01:00 committed by GitHub
commit c2bf0b6314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 140 additions and 5 deletions

48
example/tmpfs.nix Normal file
View File

@ -0,0 +1,48 @@
{ disks ? [ "/dev/vdb" ], ... }: {
disk = {
vdb = {
device = builtins.elemAt disks 0;
type = "disk";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
name = "root";
type = "partition";
start = "100MiB";
end = "100%";
part-type = "primary";
bootable = true;
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
}
];
};
};
};
nodev = {
"/tmp" = {
fsType = "tmpfs";
mountOptions = [
"size=200M"
];
};
};
}

10
tests/tmpfs.nix Normal file
View File

@ -0,0 +1,10 @@
{ pkgs ? (import <nixpkgs> { })
, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
}:
makeDiskoTest {
disko-config = ../example/tmpfs.nix;
extraTestScript = ''
machine.succeed("mountpoint /");
machine.succeed("mountpoint /tmp");
'';
}

View File

@ -119,6 +119,7 @@ rec {
meta :: types.devices -> AttrSet meta :: types.devices -> AttrSet
*/ */
meta = devices: diskoLib.deepMergeMap (dev: dev._meta) (flatten (map attrValues (attrValues devices))); meta = devices: diskoLib.deepMergeMap (dev: dev._meta) (flatten (map attrValues (attrValues devices)));
/* Takes a disko device specification and returns a string which formats the disks /* Takes a disko device specification and returns a string which formats the disks
create :: types.devices -> str create :: types.devices -> str
@ -215,7 +216,7 @@ rec {
}; };
}; };
/* topLevel type of the disko config, takes attrsets of disks mdadms zpools and lvm vgs. /* topLevel type of the disko config, takes attrsets of disks, mdadms, zpools, nodevs, and lvm vgs.
*/ */
devices = types.submodule { devices = types.submodule {
options = { options = {
@ -235,9 +236,82 @@ rec {
type = types.attrsOf lvm_vg; type = types.attrsOf lvm_vg;
default = {}; default = {};
}; };
nodev = mkOption {
type = types.attrsOf nodev;
default = {};
};
}; };
}; };
nodev = types.submodule ({ config, ... }: {
options = {
type = mkOption {
type = types.enum [ "nodev" ];
default = "nodev";
internal = true;
};
fsType = mkOption {
type = types.str;
};
device = mkOption {
type = types.str;
default = "none";
};
mountpoint = mkOption {
type = optionTypes.absolute-pathname;
default = config._module.args.name;
};
mountOptions = mkOption {
type = types.listOf types.str;
default = [];
};
_meta = mkOption {
internal = true;
readOnly = true;
type = diskoLib.jsonType;
default = {
};
};
_create = mkOption {
internal = true;
readOnly = true;
type = types.str;
default = "";
};
_mount = mkOption {
internal = true;
readOnly = true;
type = diskoLib.jsonType;
default = {
fs.${config.mountpoint} = ''
if ! findmnt ${config.fsType} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
mount -t ${config.fsType} ${config.device} "/mnt${config.mountpoint}" \
${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
-o X-mount.mkdir
fi
'';
};
};
_config = mkOption {
internal = true;
readOnly = true;
default = [{
fileSystems.${config.mountpoint} = {
device = config.device;
fsType = config.fsType;
options = config.mountOptions;
};
}];
};
_pkgs= mkOption {
internal = true;
readOnly = true;
type = types.functionTo (types.listOf types.package);
default = pkgs: [];
};
};
});
btrfs = types.submodule ({ config, ... }: { btrfs = types.submodule ({ config, ... }: {
options = { options = {
type = mkOption { type = mkOption {
@ -286,7 +360,7 @@ rec {
fs.${config.mountpoint} = '' fs.${config.mountpoint} = ''
if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
mount ${dev} "/mnt${config.mountpoint}" \ mount ${dev} "/mnt${config.mountpoint}" \
${concatStringsSep " " config.mountOptions} \ ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
-o X-mount.mkdir -o X-mount.mkdir
fi fi
''; '';
@ -360,7 +434,7 @@ rec {
fs.${config.mountpoint} = '' fs.${config.mountpoint} = ''
if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
mount ${dev} "/mnt${config.mountpoint}" \ mount ${dev} "/mnt${config.mountpoint}" \
${toString config.mountOptions} \ ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
-o X-mount.mkdir -o X-mount.mkdir
fi fi
''; '';
@ -834,6 +908,7 @@ rec {
}; };
type = mkOption { type = mkOption {
type = types.enum [ "zpool" ]; type = types.enum [ "zpool" ];
default = "zpool";
internal = true; internal = true;
}; };
mode = mkOption { mode = mkOption {
@ -895,7 +970,7 @@ rec {
if ! findmnt ${config.name} "/mnt${config.mountpoint}" > /dev/null 2>&1; then if ! findmnt ${config.name} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
mount ${config.name} "/mnt${config.mountpoint}" \ mount ${config.name} "/mnt${config.mountpoint}" \
${optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \ ${optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \
${toString config.mountOptions} \ ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
-o X-mount.mkdir \ -o X-mount.mkdir \
-t zfs -t zfs
fi fi
@ -993,7 +1068,7 @@ rec {
if ! findmnt ${zpool}/${config.name} "/mnt${config.mountpoint}" > /dev/null 2>&1; then if ! findmnt ${zpool}/${config.name} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
mount ${zpool}/${config.name} "/mnt${config.mountpoint}" \ mount ${zpool}/${config.name} "/mnt${config.mountpoint}" \
-o X-mount.mkdir \ -o X-mount.mkdir \
${toString config.mountOptions} \ ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
${optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \ ${optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \
-t zfs -t zfs
fi fi
@ -1212,6 +1287,8 @@ rec {
}; };
type = mkOption { type = mkOption {
type = types.enum [ "disk" ]; type = types.enum [ "disk" ];
default = "disk";
internal = true;
}; };
device = mkOption { device = mkOption {
type = optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile type = optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile