mount service: use uevent-watch

This commit is contained in:
Daniel Barlow 2024-04-17 12:59:13 +01:00
parent 721e7499f3
commit 00076c7b81
4 changed files with 39 additions and 47 deletions

View file

@ -83,7 +83,7 @@ in rec {
};
services.mount_external_disk = svc.mount.build {
device = "LABEL=backup-disk";
partlabel = "backup-disk";
mountpoint = "/srv";
fstype = "ext4";
};

View file

@ -19,28 +19,36 @@ in {
type = liminix.lib.types.serviceDefn;
};
};
config.system.service = {
mount = liminix.callService ./service.nix {
device = mkOption {
type = types.str;
example = "/dev/sda1";
};
mountpoint = mkOption {
type = types.str;
example = "/mnt/media";
};
options = mkOption {
type = types.listOf types.str;
default = [];
example = ["noatime" "ro" "sync"];
};
fstype = mkOption {
type = types.str;
default = "auto";
example = "vfat";
};
imports = [ ../mdevd.nix ];
config.system.service.mount =
let svc = liminix.callService ./service.nix {
partlabel = mkOption {
type = types.str;
example = "my-usb-stick";
};
mountpoint = mkOption {
type = types.str;
example = "/mnt/media";
};
options = mkOption {
type = types.listOf types.str;
default = [];
example = ["noatime" "ro" "sync"];
};
fstype = mkOption {
type = types.str;
default = "auto";
example = "vfat";
};
};
in svc // {
build = args:
let args' = args // {
dependencies = (args.dependencies or []) ++ [config.services.mdevd];
};
in svc.build args' ;
};
};
config.programs.busybox = {
applets = ["blkid" "findfs"];
options = {

View file

@ -1,10 +1,12 @@
{
liminix
, uevent-watch
, lib
}:
{ device, mountpoint, options, fstype }:
{ partlabel, mountpoint, options, fstype }:
let
inherit (liminix.services) longrun oneshot;
device = "/dev/disk/by-partlabel/${partlabel}";
options_string =
if options == [] then "" else "-o ${lib.concatStringsSep "," options}";
mount_service = oneshot {
@ -18,14 +20,7 @@ in longrun {
isTrigger = true;
buildInputs = [ mount_service ];
# This accommodates bringing the service up when the device appears.
# It doesn't bring it down on unplug because unmount will probably
# fail anyway (so don't do that)
run = ''
while ! findfs ${device}; do
echo waiting for device ${device}
sleep 1
done
s6-rc -b -u change ${mount_service.name}
${uevent-watch}/bin/uevent-watch -s ${mount_service.name} -n ${device} partname=${partlabel} devtype=partition
'';
}

View file

@ -47,20 +47,9 @@ in rec {
rootfsType = "jffs2";
hostname = "inout";
services.watch_mount_srv =
let
node = "/dev/disk/by-partlabel/backup-disk";
mount = oneshot {
name = "mount-srv";
up = "mount -t ext2 ${node} /srv";
down = "umount /srv";
};
in longrun {
name = "mount_srv";
run = ''
${pkgs.uevent-watch}/bin/uevent-watch -s ${mount.name} -n ${node} partname=backup-disk devtype=partition
'';
dependencies = [ config.services.mdevd ];
buildInputs = [ mount ];
};
services.mount_backup_disk = svc.mount.build {
partlabel = "backup-disk";
mountpoint = "/srv";
fstype = "ext4";
};
}