From daf5fe8e9bfbd17c569a7896bf48649e9eb94f80 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 3 Dec 2022 14:12:33 +0100 Subject: fix all mountOptions --- types.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types.nix b/types.nix index 87a34a9..bf9dc30 100644 --- a/types.nix +++ b/types.nix @@ -286,7 +286,7 @@ rec { fs.${config.mountpoint} = '' if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then mount ${dev} "/mnt${config.mountpoint}" \ - ${concatStringsSep " " config.mountOptions} \ + ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ -o X-mount.mkdir fi ''; @@ -360,7 +360,7 @@ rec { fs.${config.mountpoint} = '' if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then mount ${dev} "/mnt${config.mountpoint}" \ - ${toString config.mountOptions} \ + ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ -o X-mount.mkdir fi ''; @@ -895,7 +895,7 @@ rec { if ! findmnt ${config.name} "/mnt${config.mountpoint}" > /dev/null 2>&1; then mount ${config.name} "/mnt${config.mountpoint}" \ ${optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \ - ${toString config.mountOptions} \ + ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ -o X-mount.mkdir \ -t zfs fi @@ -993,7 +993,7 @@ rec { if ! findmnt ${zpool}/${config.name} "/mnt${config.mountpoint}" > /dev/null 2>&1; then mount ${zpool}/${config.name} "/mnt${config.mountpoint}" \ -o X-mount.mkdir \ - ${toString config.mountOptions} \ + ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ ${optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \ -t zfs fi -- cgit v1.2.3 From bfa2318ca5dc6b2471c5025b9adbd2fd35c3adea Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 3 Dec 2022 14:12:57 +0100 Subject: types: add default types for topLevel children --- types.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/types.nix b/types.nix index bf9dc30..377f546 100644 --- a/types.nix +++ b/types.nix @@ -834,6 +834,7 @@ rec { }; type = mkOption { type = types.enum [ "zpool" ]; + default = "zpool"; internal = true; }; mode = mkOption { @@ -1212,6 +1213,8 @@ rec { }; type = mkOption { type = types.enum [ "disk" ]; + default = "disk"; + internal = true; }; device = mkOption { type = optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile -- cgit v1.2.3 From ff7fa8760096e3f00a2515b35a1432237f104280 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 3 Dec 2022 12:08:19 +0100 Subject: add nodev support (for tmpfs, ramfs, nfs) --- example/tmpfs.nix | 48 +++++++++++++++++++++++++++++++++++ tests/tmpfs.nix | 10 ++++++++ types.nix | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 example/tmpfs.nix create mode 100644 tests/tmpfs.nix diff --git a/example/tmpfs.nix b/example/tmpfs.nix new file mode 100644 index 0000000..fb45f8a --- /dev/null +++ b/example/tmpfs.nix @@ -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" + ]; + }; + }; +} + diff --git a/tests/tmpfs.nix b/tests/tmpfs.nix new file mode 100644 index 0000000..10da055 --- /dev/null +++ b/tests/tmpfs.nix @@ -0,0 +1,10 @@ +{ pkgs ? (import { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/tmpfs.nix; + extraTestScript = '' + machine.succeed("mountpoint /"); + machine.succeed("mountpoint /tmp"); + ''; +} diff --git a/types.nix b/types.nix index 377f546..fa24607 100644 --- a/types.nix +++ b/types.nix @@ -119,6 +119,7 @@ rec { meta :: types.devices -> AttrSet */ 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 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 { options = { @@ -235,9 +236,82 @@ rec { type = types.attrsOf lvm_vg; 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, ... }: { options = { type = mkOption { -- cgit v1.2.3