aboutsummaryrefslogtreecommitdiff
path: root/nix/tests/deploy-flake.nix
diff options
context:
space:
mode:
authorSereja3132024-03-29 20:29:42 +0300
committerGitHub2024-03-29 20:29:42 +0300
commit2bad21828ee2c5d1e42588d5f4c53f5b10300c6a (patch)
treef22e488e7d057772809a9936ad124915ff968b6f /nix/tests/deploy-flake.nix
parent0a0187794ac7f7a1e62cda3dabf8dc041f868790 (diff)
parenta92835264100583903dc408abe43d461ff7d4dca (diff)
Merge pull request #264 from serokell/sereja/OPS-1384-add-nixos-vm-test
[OPS-1384] Introduce NixOS VM tests
Diffstat (limited to 'nix/tests/deploy-flake.nix')
-rw-r--r--nix/tests/deploy-flake.nix72
1 files changed, 72 insertions, 0 deletions
diff --git a/nix/tests/deploy-flake.nix b/nix/tests/deploy-flake.nix
new file mode 100644
index 0000000..3e1e426
--- /dev/null
+++ b/nix/tests/deploy-flake.nix
@@ -0,0 +1,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";
+ };
+ };
+ };
+ };
+}