Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ereslibre committed Jan 11, 2024
1 parent 0243ade commit b5677b2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 33 deletions.
4 changes: 3 additions & 1 deletion checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let
id = "qemu";
modules = [ {
microvm.hypervisor = "qemu";
users.users.root.password = "root";
} ];
} {
id = "qemu-tcg";
Expand All @@ -22,8 +23,9 @@ let
# system, and thus, emulated with qemu's Tiny Code Generator
# (TCG)
cpu = if "${system}" == "x86_64-linux" then "cortex-a53"
else "Westmere";
else "Westmere";
};
users.users.root.password = "root";
# This hypervisor requires a crossSystem nixpkgs for the
# guest system
nixpkgs.crossSystem.config = guestSystem;
Expand Down
35 changes: 23 additions & 12 deletions checks/startup-shutdown.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ let
};
microvm = {
volumes = [ {
mountPoint = "/var";
image = "var.img";
mountPoint = "/output";
image = "output.img";
size = 32;
} ];
crosvm.pivotRoot = "/build/empty";
Expand All @@ -34,8 +34,8 @@ let
kvmtool = "reboot";
}.${config.microvm.hypervisor};
in ''
${pkgs.coreutils}/bin/uname > /var/kernel-name
${pkgs.coreutils}/bin/uname -m > /var/machine-name
${pkgs.coreutils}/bin/uname > /output/kernel-name
${pkgs.coreutils}/bin/uname -m > /output/machine-name
${exit}
'';
Expand All @@ -54,21 +54,32 @@ builtins.mapAttrs (_: nixos:
];
requiredSystemFeatures = [ "kvm" ];
meta.timeout = 120;
} ''
} (let
expectedMachineName = (crossSystem:
if crossSystem == null then
expectedMachineName { config = system; }
else if crossSystem.config == "aarch64-unknown-linux-gnu" then
"aarch64"
else if crossSystem.config == "x86_64-linux" then
"x86_64"
else throw "unknown machine name (${crossSystem.config})"
);
in ''
microvm-run
7z e var.img kernel-name machine-name
7z e output.img kernel-name machine-name
if [ "$(cat machine-name)-linux" != "${nixos.config.nixpkgs.system}" ] ; then
echo "Machine does not match (got: $(cat machine-name)-linux; expected: ${nixos.config.nixpkgs.system})"
if [ "$(cat kernel-name)" != "Linux" ] ; then
echo "Kernel does not match (got: $(cat kernel-name); expected: Linux"
exit 1
fi
if [ "$(cat kernel-name)" != "Linux" ] ; then
echo "Kernel does not match (got: $(cat kernel-name); expected: Linux"
if [ "$(cat machine-name)" != "${expectedMachineName nixos.config.nixpkgs.crossSystem}" ] ; then
echo "Machine does not match (got: $(cat machine-name)-linux; expected: ${expectedMachineName nixos.config.nixpkgs.crossSystem})"
exit 1
fi
touch $out
''
mkdir $out
cp {kernel-name,machine-name} $out
'')
) configs
19 changes: 9 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
};

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs.url = "git+file:///home/ereslibre/projects/NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
spectrum = {
url = "git+https://spectrum-os.org/git/spectrum";
Expand Down
10 changes: 1 addition & 9 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@ rec {
defaultFsType = "ext4";

withDriveLetters = { volumes, hypervisor, storeOnDisk, ... }:
let
offset =
if storeOnDisk
then 1
else 0;
in
map ({ fst, snd }:
fst // {
letter = snd;
}
) (nixpkgs-lib.zipLists volumes (
nixpkgs-lib.drop offset nixpkgs-lib.strings.lowerChars
));
) (nixpkgs-lib.zipLists volumes nixpkgs-lib.strings.lowerChars);

createVolumesScript = pkgs: pkgs.lib.concatMapStringsSep "\n" (
{ image
Expand Down

0 comments on commit b5677b2

Please sign in to comment.