forked from DGNum/liminix
mount service: use uevent-watch
This commit is contained in:
parent
721e7499f3
commit
00076c7b81
4 changed files with 39 additions and 47 deletions
|
@ -83,7 +83,7 @@ in rec {
|
|||
};
|
||||
|
||||
services.mount_external_disk = svc.mount.build {
|
||||
device = "LABEL=backup-disk";
|
||||
partlabel = "backup-disk";
|
||||
mountpoint = "/srv";
|
||||
fstype = "ext4";
|
||||
};
|
||||
|
|
|
@ -19,11 +19,12 @@ in {
|
|||
type = liminix.lib.types.serviceDefn;
|
||||
};
|
||||
};
|
||||
config.system.service = {
|
||||
mount = liminix.callService ./service.nix {
|
||||
device = mkOption {
|
||||
imports = [ ../mdevd.nix ];
|
||||
config.system.service.mount =
|
||||
let svc = liminix.callService ./service.nix {
|
||||
partlabel = mkOption {
|
||||
type = types.str;
|
||||
example = "/dev/sda1";
|
||||
example = "my-usb-stick";
|
||||
};
|
||||
mountpoint = mkOption {
|
||||
type = types.str;
|
||||
|
@ -40,7 +41,14 @@ in {
|
|||
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 = {
|
||||
|
|
|
@ -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
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue