summaryrefslogtreecommitdiffstats
path: root/nixos/tests/nix-serve-ssh.nix
blob: dfcf1ddd53ef7170e55a97ce525d945b2bf1b0be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ pkgs, lib, ... }:
let
  inherit (import ./ssh-keys.nix pkgs)
    snakeOilPrivateKey
    snakeOilPublicKey
    ;
  ssh-config = builtins.toFile "ssh.conf" ''
    UserKnownHostsFile=/dev/null
    StrictHostKeyChecking=no
  '';
in
{
  name = "nix-ssh-serve";
  meta.maintainers = [ lib.maintainers.shlevy ];
  defaults = {
    nix.enable = true; # disabled by default. See all-tests.nix / tag(no-nix-by-default)
  };
  nodes = {
    server.nix.sshServe = {
      enable = true;
      keys = [ snakeOilPublicKey ];
      protocol = "ssh-ng";
    };
    server.nix.package = pkgs.nix;
    client.nix.package = pkgs.nix;
  };
  testScript = ''
    start_all()

    client.succeed("mkdir -m 700 /root/.ssh")
    client.succeed(
        "cat ${ssh-config} > /root/.ssh/config"
    )
    client.succeed(
        "cat ${snakeOilPrivateKey} > /root/.ssh/id_ecdsa"
    )
    client.succeed("chmod 600 /root/.ssh/id_ecdsa")

    client.succeed("nix-store --add /etc/machine-id > mach-id-path")

    server.wait_for_unit("sshd")

    client.fail("diff /root/other-store$(cat mach-id-path) /etc/machine-id")
    # Currently due to shared store this is a noop :(
    client.succeed("nix copy --experimental-features 'nix-command' --to ssh-ng://nix-ssh@server $(cat mach-id-path)")
    client.succeed(
        "nix-store --realise $(cat mach-id-path) --store /root/other-store --substituters ssh-ng://nix-ssh@server"
    )
    client.succeed("diff /root/other-store$(cat mach-id-path) /etc/machine-id")
  '';
}