-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add testing VM - needs x86_64 builder
- Loading branch information
Showing
5 changed files
with
107 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,4 +124,8 @@ Cargo.lock | |
# Lerna debug | ||
lerna-debug.log | ||
|
||
result | ||
# Nix outputs | ||
result | ||
|
||
# Nix VM disk image | ||
nixos.qcow2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,11 @@ | ||
{ | ||
outputs = { self, nixpkgs, }: { | ||
nixosModules.vm = { ... }: { | ||
# Make VM output to the terminal instead of a separate window | ||
virtualisation.vmVariant.virtualisation.graphics = false; | ||
}; | ||
|
||
nixosModules.base = { pkgs, ... }: { | ||
system.stateVersion = "23.11"; | ||
|
||
# Configure networking | ||
networking.useDHCP = false; | ||
networking.interfaces.eth0.useDHCP = true; | ||
outputs = { self, nixpkgs, }: | ||
let vms = import ./vm_modules.nix { inherit nixpkgs; }; | ||
in { | ||
packages.x86_64-linux.linuxVM = | ||
vms.nixosConfigurations.linuxVM.config.system.build.vm; | ||
|
||
# Create user "test" | ||
services.getty.autologinUser = "tester"; | ||
users.users.test.isNormalUser = true; | ||
|
||
# Enable passwordless ‘sudo’ for the "test" user | ||
users.users.test.extraGroups = [ "wheel" ]; | ||
security.sudo.wheelNeedsPassword = false; | ||
packages.aarch64-darwin.darwinVM = | ||
vms.nixosConfigurations.darwinVM.config.system.build.vm; | ||
}; | ||
|
||
nixosConfigurations.linuxVM = nixpkgs.lib.nixosSystem { | ||
system = "x86_64-linux"; | ||
modules = [ self.nixosModules.base self.nixosModules.vm ]; | ||
}; | ||
packages.x86_64-linux.linuxVM = | ||
self.nixosConfigurations.linuxVM.config.system.build.vm; | ||
|
||
nixosConfigurations.darwinVM = nixpkgs.lib.nixosSystem { | ||
system = "aarch64-linux"; | ||
modules = [ | ||
self.nixosModules.base | ||
self.nixosModules.vm | ||
{ | ||
virtualisation.vmVariant.virtualisation.host.pkgs = | ||
nixpkgs.legacyPackages.aarch64-darwin; | ||
} | ||
]; | ||
}; | ||
packages.aarch64-darwin.darwinVM = | ||
self.nixosConfigurations.darwinVM.config.system.build.vm; | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ nixpkgs, engine_image, ... }: | ||
let | ||
nixosModulesVM = { ... }: { | ||
# Make VM output to the terminal instead of a separate window | ||
virtualisation.vmVariant.virtualisation.graphics = false; | ||
}; | ||
|
||
nixosModulesBase = { pkgs, ... }: { | ||
system.stateVersion = "23.11"; | ||
|
||
# Configure networking | ||
networking.useDHCP = false; | ||
networking.interfaces.eth0.useDHCP = true; | ||
|
||
# Create user "tester" | ||
services.getty.autologinUser = "tester"; | ||
users.users.tester.isNormalUser = true; | ||
|
||
# setup k3s | ||
services.k3s.enable = true; | ||
services.k3s.role = "server"; | ||
environment.systemPackages = [ pkgs.k3s ]; | ||
|
||
# setup docker | ||
virtualisation.docker.enable = true; | ||
|
||
# Enable passwordless ‘sudo’ for the "tester" user | ||
users.users.tester.extraGroups = [ "wheel" "docker" ]; | ||
security.sudo.wheelNeedsPassword = false; | ||
}; | ||
|
||
in { | ||
nixosConfigurations.linuxVM = nixpkgs.lib.nixosSystem { | ||
system = "x86_64-linux"; | ||
modules = [ nixosModulesBase nixosModulesVM ]; | ||
}; | ||
|
||
nixosConfigurations.darwinVM = nixpkgs.lib.nixosSystem { | ||
system = "aarch64-linux"; | ||
modules = [ | ||
nixosModulesBase | ||
nixosModulesVM | ||
{ | ||
virtualisation.vmVariant.virtualisation.host.pkgs = | ||
nixpkgs.legacyPackages.aarch64-darwin; | ||
} | ||
]; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ nixpkgs, pkgs, ... }: | ||
let nixos-lib = import (nixpkgs + "/nixos/lib") { }; | ||
in nixos-lib.runTest rec { | ||
name = "demo-test"; | ||
|
||
hostPkgs = import nixpkgs { system = pkgs.stdenv.hostPlatform.system; }; | ||
|
||
node = pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin { | ||
pkgs = import nixpkgs { | ||
system = builtins.replaceStrings [ "darwin" ] [ "linux" ] | ||
pkgs.stdenv.hostPlatform.system; | ||
}; | ||
}; | ||
|
||
nodes.machine = { config, pkgs, ... }: { | ||
users.users.alice = { | ||
isNormalUser = true; | ||
extraGroups = [ "wheel" ]; | ||
packages = with pkgs; [ tree ]; | ||
}; | ||
system.stateVersion = "23.11"; | ||
virtualisation.vmVariant.virtualisation.graphics = false; | ||
}; | ||
|
||
testScript = '' | ||
machine.wait_for_unit("default.target") | ||
machine.succeed("su -- alice -c 'which firefox'") | ||
machine.fail("su -- root -c 'which firefox'") | ||
''; | ||
} |