1{ lib, pkgs, ... }:
2let
3 inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey;
4in
5{
6 name = "locate";
7 meta.maintainers = with pkgs.lib.maintainers; [ chkno ];
8
9 nodes = rec {
10 a = {
11 environment.systemPackages = with pkgs; [ sshfs ];
12 virtualisation.fileSystems = {
13 "/ssh" = {
14 device = "alice@b:/";
15 fsType = "fuse.sshfs";
16 options = [
17 "allow_other"
18 "IdentityFile=/privkey"
19 "noauto"
20 "StrictHostKeyChecking=no"
21 "UserKnownHostsFile=/dev/null"
22 ];
23 };
24 };
25 services.locate = {
26 enable = true;
27 interval = "*:*:0/5";
28 };
29 };
30 b = {
31 services.openssh.enable = true;
32 users.users.alice = {
33 isNormalUser = true;
34 openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
35 };
36 };
37 };
38
39 testScript = ''
40 start_all()
41
42 # Set up sshfs mount
43 a.succeed(
44 "(umask 077; cat ${snakeOilPrivateKey} > /privkey)"
45 )
46 b.succeed("touch /file-on-b-machine")
47 b.wait_for_open_port(22)
48 a.succeed("mkdir /ssh")
49 a.succeed("mount /ssh")
50
51 # Core locatedb functionality
52 a.succeed("touch /file-on-a-machine-1")
53 a.wait_for_file("/var/cache/locatedb")
54 a.wait_until_succeeds("locate file-on-a-machine-1")
55
56 # Wait for a second update to make sure we're using a locatedb from a run
57 # that began after the sshfs mount
58 a.succeed("touch /file-on-a-machine-2")
59 a.wait_until_succeeds("locate file-on-a-machine-2")
60
61 # We shouldn't be able to see files on the other machine
62 a.fail("locate file-on-b-machine")
63 '';
64}