2023-09-04 22:17:52 +02:00
|
|
|
{
|
|
|
|
liminix
|
2024-04-17 13:59:13 +02:00
|
|
|
, uevent-watch
|
2023-09-04 22:17:52 +02:00
|
|
|
, lib
|
|
|
|
}:
|
2024-04-17 13:59:13 +02:00
|
|
|
{ partlabel, mountpoint, options, fstype }:
|
2023-09-04 22:17:52 +02:00
|
|
|
let
|
2024-04-04 00:17:36 +02:00
|
|
|
inherit (liminix.services) longrun oneshot;
|
2024-04-17 13:59:13 +02:00
|
|
|
device = "/dev/disk/by-partlabel/${partlabel}";
|
2024-04-04 00:17:36 +02:00
|
|
|
options_string =
|
|
|
|
if options == [] then "" else "-o ${lib.concatStringsSep "," options}";
|
|
|
|
mount_service = oneshot {
|
|
|
|
name = "mount.${lib.escapeURL mountpoint}";
|
|
|
|
timeout-up = 3600;
|
|
|
|
up = "mount -t ${fstype} ${options_string} ${device} ${mountpoint}";
|
|
|
|
down = "umount ${mountpoint}";
|
|
|
|
};
|
|
|
|
in longrun {
|
|
|
|
name = "watch-mount.${lib.strings.sanitizeDerivationName mountpoint}";
|
|
|
|
isTrigger = true;
|
|
|
|
buildInputs = [ mount_service ];
|
|
|
|
|
|
|
|
run = ''
|
2024-04-17 13:59:13 +02:00
|
|
|
${uevent-watch}/bin/uevent-watch -s ${mount_service.name} -n ${device} partname=${partlabel} devtype=partition
|
2023-09-04 22:17:52 +02:00
|
|
|
'';
|
|
|
|
}
|