1 import ./make-test-python.nix ({ pkgs, ... }:
5 stick = pkgs.fetchurl {
6 url = "https://nixos.org/~eelco/nix/udisks-test.img.xz";
7 sha256 = "0was1xgjkjad91nipzclaz5biv3m4b2nk029ga6nk7iklwi19l8b";
14 meta = with pkgs.stdenv.lib.maintainers; {
15 maintainers = [ eelco ];
20 { services.udisks2.enable = true;
21 imports = [ ./common/user-account.nix ];
23 security.polkit.extraConfig =
25 polkit.addRule(function(action, subject) {
26 if (subject.user == "alice") return "yes";
37 ) as data, open(machine.state_dir + "/usbstick.img", "wb") as stick:
38 stick.write(data.read())
40 machine.succeed("udisksctl info -b /dev/vda >&2")
41 machine.fail("udisksctl info -b /dev/sda1")
43 # Attach a USB stick and wait for it to show up.
44 machine.send_monitor_command(
45 f"drive_add 0 id=stick,if=none,file={stick.name},format=raw"
47 machine.send_monitor_command("device_add usb-storage,id=stick,drive=stick")
48 machine.wait_until_succeeds("udisksctl info -b /dev/sda1")
49 machine.succeed("udisksctl info -b /dev/sda1 | grep 'IdLabel:.*USBSTICK'")
51 # Mount the stick as a non-root user and do some stuff with it.
52 machine.succeed("su - alice -c 'udisksctl info -b /dev/sda1'")
53 machine.succeed("su - alice -c 'udisksctl mount -b /dev/sda1'")
55 "su - alice -c 'cat /run/media/alice/USBSTICK/test.txt' | grep -q 'Hello World'"
57 machine.succeed("su - alice -c 'echo foo > /run/media/alice/USBSTICK/bar.txt'")
59 # Unmounting the stick should make the mountpoint disappear.
60 machine.succeed("su - alice -c 'udisksctl unmount -b /dev/sda1'")
61 machine.fail("[ -d /run/media/alice/USBSTICK ]")
63 # Remove the USB stick.
64 machine.send_monitor_command("device_del stick")
65 machine.wait_until_fails("udisksctl info -b /dev/sda1")
66 machine.fail("[ -e /dev/sda ]")