vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / nixops / default.nix
blob6468b8c3822492616c23d2b62cec31a8bacae515
1 { pkgs, ... }:
2 let
3   inherit (pkgs) lib;
5   tests = {
6     # TODO: uncomment stable
7     #  - Blocked on https://github.com/NixOS/nixpkgs/issues/138584 which has a
8     #    PR in staging: https://github.com/NixOS/nixpkgs/pull/139986
9     #  - Alternatively, blocked on a NixOps 2 release
10     #    https://github.com/NixOS/nixops/issues/1242
11     # stable = testsLegacyNetwork { nixopsPkg = pkgs.nixops; };
12     unstable = testsForPackage { nixopsPkg = pkgs.nixops_unstable_minimal; };
14     # inherit testsForPackage;
15   };
17   testsForPackage = args: lib.recurseIntoAttrs {
18     legacyNetwork = testLegacyNetwork args;
19     passthru.override = args': testsForPackage (args // args');
20   };
22   testLegacyNetwork = { nixopsPkg, ... }: pkgs.testers.nixosTest ({
23     name = "nixops-legacy-network";
24     nodes = {
25       deployer = { config, lib, nodes, pkgs, ... }: {
26         imports = [ ../../modules/installer/cd-dvd/channel.nix ];
27         environment.systemPackages = [ nixopsPkg ];
28         nix.settings.substituters = lib.mkForce [ ];
29         users.users.person.isNormalUser = true;
30         virtualisation.writableStore = true;
31         virtualisation.additionalPaths = [
32           pkgs.hello
33           pkgs.figlet
34         ];
35         virtualisation.memorySize = 2048;
37         # TODO: make this efficient, https://github.com/NixOS/nixpkgs/issues/180529
38         system.includeBuildDependencies = true;
39       };
40       server = { lib, ... }: {
41         imports = [ ./legacy/base-configuration.nix ];
42       };
43     };
45     testScript = { nodes }:
46       let
47         deployerSetup = pkgs.writeScript "deployerSetup" ''
48           #!${pkgs.runtimeShell}
49           set -eux -o pipefail
50           cp --no-preserve=mode -r ${./legacy} unicorn
51           cp --no-preserve=mode ${../ssh-keys.nix} unicorn/ssh-keys.nix
52           mkdir -p ~/.ssh
53           cp ${snakeOilPrivateKey} ~/.ssh/id_ed25519
54           chmod 0400 ~/.ssh/id_ed25519
55         '';
56         serverNetworkJSON = pkgs.writeText "server-network.json"
57           (builtins.toJSON nodes.server.system.build.networkConfig);
58       in
59       ''
60         import shlex
62         def deployer_do(cmd):
63             cmd = shlex.quote(cmd)
64             return deployer.succeed(f"su person -l -c {cmd} &>/dev/console")
66         start_all()
68         deployer_do("cat /etc/hosts")
70         deployer_do("${deployerSetup}")
71         deployer_do("cp ${serverNetworkJSON} unicorn/server-network.json")
73         # Establish that ssh works, regardless of nixops
74         # Easy way to accept the server host key too.
75         server.wait_for_open_port(22)
76         deployer.wait_for_unit("network.target")
78         # Put newlines on console, to flush the console reader's line buffer
79         # in case nixops' last output did not end in a newline, as is the case
80         # with a status line (if implemented?)
81         deployer.succeed("while sleep 60s; do echo [60s passed]; done >&2 &")
83         deployer_do("cd ~/unicorn; ssh -oStrictHostKeyChecking=accept-new root@server echo hi")
85         # Create and deploy
86         deployer_do("cd ~/unicorn; nixops create")
88         deployer_do("cd ~/unicorn; nixops deploy --confirm")
90         deployer_do("cd ~/unicorn; nixops ssh server 'hello | figlet'")
91       '';
92   });
94   inherit (import ../ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey;
97 tests