diff --git a/lib/default.nix b/lib/default.nix index 7566411..4bc7561 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -480,7 +480,8 @@ let postUnmountHook = diskoLib.mkHook "shell commands to run after unmount"; }; config._module.args = { - inherit diskoLib rootMountPoint; + inherit diskoLib; + globals = { inherit rootMountPoint; }; }; } ]; @@ -1168,7 +1169,7 @@ let lib.listToAttrs (map (option: lib.nameValuePair option type.options.${option}) options); typesSerializerLib = { - rootMountPoint = ""; + globals.rootMountPoint = ""; options = null; config = { _module = { diff --git a/lib/types/bcachefs_filesystem.nix b/lib/types/bcachefs_filesystem.nix index 6f1d689..59c17a4 100644 --- a/lib/types/bcachefs_filesystem.nix +++ b/lib/types/bcachefs_filesystem.nix @@ -4,7 +4,7 @@ lib, options, parent, - rootMountPoint, + globals, ... }: { @@ -226,10 +226,10 @@ subvolume: lib.optionalAttrs (subvolume.mountpoint != null) { ${subvolume.mountpoint} = '' - if ! findmnt "${rootMountPoint}${subvolume.mountpoint}" >&2 2>&1; then + if ! findmnt "${globals.rootMountPoint}${subvolume.mountpoint}" >&2 2>&1; then # @todo Figure out why the "X-mount.mkdir" option here doesn't seem to work, # necessitating running `mkdir` here. - mkdir -p "${rootMountPoint}${subvolume.mountpoint}"; + mkdir -p "${globals.rootMountPoint}${subvolume.mountpoint}"; ${lib.optionalString (config.passwordFile != null) '' if ! bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}"; then test -d "/sys/fs/bcachefs/${config.uuid}"; @@ -249,7 +249,7 @@ ) }" \ "/dev/disk/by-uuid/${config.uuid}" \ - "${rootMountPoint}${subvolume.mountpoint}"; + "${globals.rootMountPoint}${subvolume.mountpoint}"; fi; ''; } @@ -260,10 +260,10 @@ subvolumeMounts // lib.optionalAttrs (config.mountpoint != null) { ${config.mountpoint} = '' - if ! findmnt "${rootMountPoint}${config.mountpoint}" >&2 2>&1; then + if ! findmnt "${globals.rootMountPoint}${config.mountpoint}" >&2 2>&1; then # @todo Figure out why the "X-mount.mkdir" option here doesn't seem to work, # necessitating running `mkdir` here. - mkdir -p "${rootMountPoint}${config.mountpoint}"; + mkdir -p "${globals.rootMountPoint}${config.mountpoint}"; ${lib.optionalString (config.passwordFile != null) '' if ! bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}"; then test -d "/sys/fs/bcachefs/${config.uuid}"; @@ -273,7 +273,7 @@ -t bcachefs \ -o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \ "/dev/disk/by-uuid/${config.uuid}" \ - "${rootMountPoint}${config.mountpoint}"; + "${globals.rootMountPoint}${config.mountpoint}"; fi; ''; }; @@ -287,8 +287,8 @@ _: subvolume: lib.optionalAttrs (subvolume.mountpoint != null) { ${subvolume.mountpoint} = '' - if findmnt "UUID=${config.uuid}" "${rootMountPoint}${subvolume.mountpoint}" >&2 2>&1; then - umount "${rootMountPoint}${subvolume.mountpoint}"; + if findmnt "UUID=${config.uuid}" "${globals.rootMountPoint}${subvolume.mountpoint}" >&2 2>&1; then + umount "${globals.rootMountPoint}${subvolume.mountpoint}"; fi; ''; } @@ -299,8 +299,8 @@ subvolumeMounts // lib.optionalAttrs (config.mountpoint != null) { ${config.mountpoint} = '' - if findmnt "UUID=${config.uuid}" "${rootMountPoint}${config.mountpoint}" >&2 2>&1; then - umount "${rootMountPoint}${config.mountpoint}"; + if findmnt "UUID=${config.uuid}" "${globals.rootMountPoint}${config.mountpoint}" >&2 2>&1; then + umount "${globals.rootMountPoint}${config.mountpoint}"; fi; ''; }; diff --git a/lib/types/btrfs.nix b/lib/types/btrfs.nix index e1e228b..d03946e 100644 --- a/lib/types/btrfs.nix +++ b/lib/types/btrfs.nix @@ -3,7 +3,7 @@ options, diskoLib, lib, - rootMountPoint, + globals, parent, device, ... @@ -197,8 +197,8 @@ in (subvol.mountpoint != null) { ${subvol.mountpoint} = '' - if ! findmnt "${config.device}" "${rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then - mount "${config.device}" "${rootMountPoint}${subvol.mountpoint}" \ + if ! findmnt "${config.device}" "${globals.rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then + mount "${config.device}" "${globals.rootMountPoint}${subvol.mountpoint}" \ ${ lib.concatMapStringsSep " " (opt: "-o ${opt}") (subvol.mountOptions ++ [ "subvol=${subvol.name}" ]) } \ @@ -213,8 +213,8 @@ in subvolMounts // lib.optionalAttrs (config.mountpoint != null) { ${config.mountpoint} = '' - if ! findmnt "${config.device}" "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then - mount "${config.device}" "${rootMountPoint}${config.mountpoint}" \ + if ! findmnt "${config.device}" "${globals.rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then + mount "${config.device}" "${globals.rootMountPoint}${config.mountpoint}" \ ${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ -o X-mount.mkdir fi @@ -230,8 +230,8 @@ in _: subvol: lib.optionalAttrs (subvol.mountpoint != null) { ${subvol.mountpoint} = '' - if findmnt "${config.device}" "${rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then - umount "${rootMountPoint}${subvol.mountpoint}" + if findmnt "${config.device}" "${globals.rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then + umount "${globals.rootMountPoint}${subvol.mountpoint}" fi ''; } @@ -242,8 +242,8 @@ in subvolMounts // lib.optionalAttrs (config.mountpoint != null) { ${config.mountpoint} = '' - if findmnt "${config.device}" "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then - umount "${rootMountPoint}${config.mountpoint}" + if findmnt "${config.device}" "${globals.rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then + umount "${globals.rootMountPoint}${config.mountpoint}" fi ''; }; diff --git a/lib/types/filesystem.nix b/lib/types/filesystem.nix index b957898..28d3fec 100644 --- a/lib/types/filesystem.nix +++ b/lib/types/filesystem.nix @@ -3,7 +3,7 @@ options, lib, diskoLib, - rootMountPoint, + globals, parent, device, ... @@ -64,8 +64,8 @@ inherit config options; default = lib.optionalAttrs (config.mountpoint != null) { fs.${config.mountpoint} = '' - if ! findmnt "${config.device}" "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then - mount "${config.device}" "${rootMountPoint}${config.mountpoint}" \ + if ! findmnt "${config.device}" "${globals.rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then + mount "${config.device}" "${globals.rootMountPoint}${config.mountpoint}" \ -t "${config.format}" \ ${lib.concatMapStringsSep " " (opt: "-o ${lib.escapeShellArg opt}") config.mountOptions} \ -o X-mount.mkdir @@ -77,8 +77,8 @@ inherit config options; default = lib.optionalAttrs (config.mountpoint != null) { fs.${config.mountpoint} = '' - if findmnt "${config.device}" "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then - umount "${rootMountPoint}${config.mountpoint}" + if findmnt "${config.device}" "${globals.rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then + umount "${globals.rootMountPoint}${config.mountpoint}" fi ''; }; diff --git a/lib/types/nodev.nix b/lib/types/nodev.nix index 902dc1c..bff36b4 100644 --- a/lib/types/nodev.nix +++ b/lib/types/nodev.nix @@ -3,7 +3,7 @@ config, options, diskoLib, - rootMountPoint, + globals, ... }: let @@ -60,12 +60,12 @@ in default = let isBindMount = builtins.elem "bind" config.mountOptions; - device = if isBindMount then "${rootMountPoint}${config.device}" else config.device; + device = if isBindMount then "${globals.rootMountPoint}${config.device}" else config.device; in lib.optionalAttrs (config.mountpoint != null) { fs.${config.mountpoint} = '' - if ! findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then - mount -t ${config.fsType} "${device}" "${rootMountPoint}${config.mountpoint}" \ + if ! findmnt ${config.fsType} "${globals.rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then + mount -t ${config.fsType} "${device}" "${globals.rootMountPoint}${config.mountpoint}" \ ${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ -o X-mount.mkdir fi @@ -76,8 +76,8 @@ in inherit config options; default = lib.optionalAttrs (config.mountpoint != null) { fs.${config.mountpoint} = '' - if findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then - umount "${rootMountPoint}${config.mountpoint}" + if findmnt ${config.fsType} "${globals.rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then + umount "${globals.rootMountPoint}${config.mountpoint}" fi ''; }; diff --git a/lib/types/zfs_fs.nix b/lib/types/zfs_fs.nix index 3635e8e..df59c56 100644 --- a/lib/types/zfs_fs.nix +++ b/lib/types/zfs_fs.nix @@ -3,7 +3,7 @@ options, lib, diskoLib, - rootMountPoint, + globals, parent, ... }: @@ -131,8 +131,8 @@ (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") { fs.${config.mountpoint} = '' - if ! findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then - mount ${config._name} "${rootMountPoint}${config.mountpoint}" \ + if ! findmnt ${config._name} "${globals.rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then + mount ${config._name} "${globals.rootMountPoint}${config.mountpoint}" \ -o X-mount.mkdir \ ${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ ${lib.optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \ @@ -157,8 +157,8 @@ (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") { fs.${config.mountpoint} = '' - if findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then - umount "${rootMountPoint}${config.mountpoint}" + if findmnt ${config._name} "${globals.rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then + umount "${globals.rootMountPoint}${config.mountpoint}" fi ''; }; diff --git a/lib/types/zpool.nix b/lib/types/zpool.nix index f9947a1..a3297aa 100644 --- a/lib/types/zpool.nix +++ b/lib/types/zpool.nix @@ -3,7 +3,7 @@ options, lib, diskoLib, - rootMountPoint, + globals, ... }: let @@ -364,7 +364,7 @@ in fi if [ $continue -eq 1 ]; then zpool create -f "${config.name}" \ - -R ${rootMountPoint} \ + -R ${globals.rootMountPoint} \ ${ if ( @@ -407,7 +407,7 @@ in { dev = '' zpool list "${config.name}" >/dev/null 2>/dev/null || - zpool import -l -R ${rootMountPoint} "${config.name}" + zpool import -l -R ${globals.rootMountPoint} "${config.name}" ${lib.concatMapStrings (x: x._mount.dev or "") (lib.attrValues config.datasets)} '';