diff options
author | Philip Taron | 2024-08-30 15:55:39 -0700 |
---|---|---|
committer | GitHub | 2024-08-30 15:55:39 -0700 |
commit | 4710721d417a3f30872cedf0d88af046b08d04a5 (patch) | |
tree | ac8e46dc1bca76cd9bc8b75a16f9c02f05c29460 /nixos | |
parent | 4fedd7f928e7747bcd790d235d24f803d5148e07 (diff) | |
parent | c653608dcd3126230b8e352f6d4a6c21863b3a04 (diff) |
nixos: Support fileSystems.<name>.depends with fstab-generator (#233707)
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/tasks/filesystems.nix | 15 | ||||
-rw-r--r-- | nixos/modules/tasks/filesystems/overlayfs.nix | 41 | ||||
-rw-r--r-- | nixos/tests/filesystems-overlayfs.nix | 1 |
3 files changed, 41 insertions, 16 deletions
diff --git a/nixos/modules/tasks/filesystems.nix b/nixos/modules/tasks/filesystems.nix index cd0ba98ef968..5c95cd3d451e 100644 --- a/nixos/modules/tasks/filesystems.nix +++ b/nixos/modules/tasks/filesystems.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, utils, ... }: +{ config, lib, pkgs, utils, ... }@moduleArgs: with lib; with utils; @@ -136,10 +136,21 @@ let }; - config.options = mkMerge [ + config.options = let + inInitrd = utils.fsNeededForBoot config; + in mkMerge [ (mkIf config.autoResize [ "x-systemd.growfs" ]) (mkIf config.autoFormat [ "x-systemd.makefs" ]) (mkIf (utils.fsNeededForBoot config) [ "x-initrd.mount" ]) + (mkIf + # With scripted stage 1, depends is implemented by sorting 'config.system.build.fileSystems' + (lib.length config.depends > 0 && (inInitrd -> moduleArgs.config.boot.initrd.systemd.enable)) + ( + map ( + x: "x-systemd.requires-mounts-for=${optionalString inInitrd "/sysroot"}${x}" + ) config.depends + ) + ) ]; }; diff --git a/nixos/modules/tasks/filesystems/overlayfs.nix b/nixos/modules/tasks/filesystems/overlayfs.nix index 2d876c92a1fd..3f1f0bc15b63 100644 --- a/nixos/modules/tasks/filesystems/overlayfs.nix +++ b/nixos/modules/tasks/filesystems/overlayfs.nix @@ -82,6 +82,10 @@ let config = lib.mkIf (config.overlay.lowerdir != null) { fsType = "overlay"; device = lib.mkDefault "overlay"; + depends = map (x: "${x}") (config.overlay.lowerdir ++ lib.optionals (config.overlay.upperdir != null) [ + config.overlay.upperdir + config.overlay.workdir + ]); options = let @@ -96,7 +100,7 @@ let ] ++ lib.optionals (config.overlay.upperdir != null) [ "upperdir=${upperdir}" "workdir=${workdir}" - ] ++ (map (s: "x-systemd.requires-mounts-for=${s}") lowerdir); + ]; }; }; @@ -123,18 +127,29 @@ in boot.initrd.availableKernelModules = lib.mkIf (initrdFileSystems != { }) [ "overlay" ]; - assertions = lib.concatLists (lib.mapAttrsToList - (_name: fs: [ - { - assertion = (fs.overlay.upperdir == null) == (fs.overlay.workdir == null); - message = "You cannot define a `lowerdir` without a `workdir` and vice versa for mount point: ${fs.mountPoint}"; - } - { - assertion = (fs.overlay.lowerdir != null && fs.overlay.upperdir == null) -> (lib.length fs.overlay.lowerdir) >= 2; - message = "A read-only overlay (without an `upperdir`) requires at least 2 `lowerdir`s: ${fs.mountPoint}"; - } - ]) - config.fileSystems); + assertions = + lib.concatLists ( + lib.mapAttrsToList (_name: fs: [ + { + assertion = (fs.overlay.upperdir == null) == (fs.overlay.workdir == null); + message = "You cannot define a `lowerdir` without a `workdir` and vice versa for mount point: ${fs.mountPoint}"; + } + { + assertion = + (fs.overlay.lowerdir != null && fs.overlay.upperdir == null) + -> (lib.length fs.overlay.lowerdir) >= 2; + message = "A read-only overlay (without an `upperdir`) requires at least 2 `lowerdir`s: ${fs.mountPoint}"; + } + ]) overlayFileSystems + ) + ++ lib.mapAttrsToList (_: fs: { + assertion = fs.overlay.upperdir == null -> config.boot.initrd.systemd.enable; + message = '' + Stage 1 overlay file system ${fs.mountPoint} has no upperdir, + which is not supported with scripted initrd. Please enable + 'boot.initrd.systemd.enable'. + ''; + }) initrdFileSystems; boot.initrd.systemd.services = lib.mkMerge (lib.mapAttrsToList preMountService initrdFileSystems); systemd.services = lib.mkMerge (lib.mapAttrsToList preMountService userspaceFileSystems); diff --git a/nixos/tests/filesystems-overlayfs.nix b/nixos/tests/filesystems-overlayfs.nix index d7cbf640abe4..faac9078a520 100644 --- a/nixos/tests/filesystems-overlayfs.nix +++ b/nixos/tests/filesystems-overlayfs.nix @@ -26,7 +26,6 @@ in nodes.machine = { config, pkgs, ... }: { boot.initrd.systemd.enable = true; - boot.initrd.availableKernelModules = [ "overlay" ]; virtualisation.fileSystems = { "/initrd-overlay" = { |