aboutsummaryrefslogtreecommitdiff
path: root/nix/tests/deploy-flake.nix
blob: 3e1e426c3b4af0fcca22ebdd55773dd07a2e67cf (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# SPDX-FileCopyrightText: 2024 Serokell <https://serokell.io/>
#
# SPDX-License-Identifier: MPL-2.0

{
  inputs = {
    # real inputs are substituted in ./default.nix
##inputs##
  };

  outputs = { self, nixpkgs, deploy-rs, ... }@inputs: let
    system = "x86_64-linux";
    pkgs = inputs.nixpkgs.legacyPackages.${system};
    user = "deploy";
  in {
    nixosConfigurations.server = nixpkgs.lib.nixosSystem {
      inherit system pkgs;
      specialArgs = { inherit inputs; };
      modules = [
        ./server.nix
        ./common.nix
        # Import the base config used by nixos tests
        (pkgs.path + "/nixos/lib/testing/nixos-test-base.nix")
        # Deployment breaks the network settings, so we need to restore them
        (pkgs.lib.importJSON ./network.json)
        # Deploy packages
        { environment.systemPackages = [ pkgs.figlet pkgs.hello ]; }
      ];
    };

    deploy.nodes = {
      server = {
        hostname = "server";
        sshUser = "root";
        sshOpts = [
          "-o" "StrictHostKeyChecking=no"
          "-o" "StrictHostKeyChecking=no"
        ];
        profiles.system.path = deploy-rs.lib."${system}".activate.nixos self.nixosConfigurations.server;
      };
      server-override = {
        hostname = "override";
        sshUser = "override";
        user = "override";
        sudo = "override";
        sshOpts = [ ];
        confirmTimeout = 0;
        activationTimeout = 0;
        profiles.system.path = deploy-rs.lib."${system}".activate.nixos self.nixosConfigurations.server;
      };
      profile = {
        hostname = "server";
        sshUser = "${user}";
        sshOpts = [
          "-o" "UserKnownHostsFile=/dev/null"
          "-o" "StrictHostKeyChecking=no"
        ];
        profiles = {
          "hello-world".path = let
            activateProfile = pkgs.writeShellScriptBin "activate" ''
              set -euo pipefail
              mkdir -p /home/${user}/.nix-profile/bin
              rm -f -- /home/${user}/.nix-profile/bin/hello /home/${user}/.nix-profile/bin/figlet
              ln -s ${pkgs.hello}/bin/hello /home/${user}/.nix-profile/bin/hello
              ln -s ${pkgs.figlet}/bin/figlet /home/${user}/.nix-profile/bin/figlet
            '';
          in deploy-rs.lib.${system}.activate.custom activateProfile "$PROFILE/bin/activate";
        };
      };
    };
  };
}