From 85a49898375d424b845d1a11314bca475555993b Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 7 Dec 2024 19:28:42 +0100 Subject: [PATCH] Create mount script in `fileSystems` module --- lib/modules/fileSystems.nix | 29 ++++++++++++++++++++++++++-- lib/modules/fileSystems/disks.nix | 32 +++---------------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/lib/modules/fileSystems.nix b/lib/modules/fileSystems.nix index 353fd658..ab2e0c84 100644 --- a/lib/modules/fileSystems.nix +++ b/lib/modules/fileSystems.nix @@ -41,8 +41,13 @@ in options = { valhalla = { - fileSystems = { + rootDir = mkOption { + type = types.str; + description = "The root of the installation directory to mount disks into."; + default = "/mnt"; + }; + mounts = mkOption { type = types.attrsOf mountType; description = "The devices to mount."; @@ -63,6 +68,25 @@ in script = let devices = (builtins.attrValues cfg.diskSetup.devices); + mountScript = lib.strings.concatLines ( + (builtins.concatMap + ( + _: [ + "partprobe 2> /dev/null || true" + "udevadm trigger" + (builtins.concatStringsSep " " ( + [ "sudo" "mount" "--mkdir" ] ++ + (lib.optionals (_.fsType == "ntfs") [ "-t" "ntfs3" ]) ++ + [ + (builtins.concatStringsSep " " (builtins.map (_: "-o ${_}") _.options)) + (_.device) + (lib.strings.normalizePath "/${cfg.diskSetup.rootDir}/${_.mountPoint}") + ] + )) + ] + ) + (builtins.attrValues cfg.mounts)) + ); in '' #!/bin/bash @@ -80,7 +104,8 @@ in '' ])} ${cfg.diskSetup.scripts.partition} - ${cfg.diskSetup.scripts.mount} + ${mountScript} + ${cfg.diskSetup.scripts.swap} ''; }; }; diff --git a/lib/modules/fileSystems/disks.nix b/lib/modules/fileSystems/disks.nix index 22b31a01..82bf9f51 100644 --- a/lib/modules/fileSystems/disks.nix +++ b/lib/modules/fileSystems/disks.nix @@ -298,12 +298,6 @@ in options = { valhalla = { fileSystems = { - rootDir = mkOption { - type = types.str; - description = "The root of the installation directory to mount disks into."; - default = "/mnt"; - }; - diskSetup = { devices = mkOption { type = types.attrsOf (mkDeviceType); @@ -322,9 +316,9 @@ in description = "The script for partitioning the disks."; }; - mount = mkOption { + swap = mkOption { type = types.str; - description = "The script for mounting the partitioned disks."; + description = "The script for enabling swap devices."; }; }; }; @@ -356,8 +350,6 @@ in diskSetup = { scripts = let - inherit (cfg) rootDir; - inherit (lib.strings) normalizePath; partPath = part: "/dev/disk/by-label/${part.label}"; disks = ((builtins.attrValues cfg.diskSetup.devices)); partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks); @@ -365,25 +357,7 @@ in { init = lib.strings.concatLines (builtins.map (_: _.scripts.init) disks); partition = lib.strings.concatLines (builtins.map (_: _.scripts.partition) disks); - mount = lib.strings.concatLines ( - (builtins.concatMap - ( - _: [ - probeScript - (builtins.concatStringsSep " " ( - [ "sudo" "mount" "--mkdir" ] ++ - (lib.optionals (_.format == "ntfs") [ "-t" "ntfs3" ]) ++ - [ - (builtins.concatStringsSep " " (builtins.map (_: "-o ${_}") _.mountOptions)) - (partPath _) - (normalizePath "/${rootDir}/${_.mountPoint}") - ] - )) - ] - ) - (lib.lists.sortOn - (_: normalizePath "/${_.mountPoint}") - (builtins.filter (_: _.mountPoint != null) partitions))) ++ + swap = lib.strings.concatLines ( (builtins.map ( _: ''