diff --git a/examples/arhcive.nix b/examples/arhcive.nix index 7d30d91..6616d81 100644 --- a/examples/arhcive.nix +++ b/examples/arhcive.nix @@ -83,7 +83,7 @@ in rec { }; services.mount_external_disk = svc.mount.build { - device = "LABEL=backup-disk"; + partlabel = "backup-disk"; mountpoint = "/srv"; fstype = "ext4"; }; diff --git a/modules/mount/default.nix b/modules/mount/default.nix index 310f892..76e1cf5 100644 --- a/modules/mount/default.nix +++ b/modules/mount/default.nix @@ -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 = { diff --git a/modules/mount/service.nix b/modules/mount/service.nix index 7491bff..ed30879 100644 --- a/modules/mount/service.nix +++ b/modules/mount/service.nix @@ -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 ''; } diff --git a/tests/inout/configuration.nix b/tests/inout/configuration.nix index cf474a6..6a326da 100644 --- a/tests/inout/configuration.nix +++ b/tests/inout/configuration.nix @@ -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"; + }; }