nixpkgs/nixos/tests/os-prober.nix

134 lines
3.8 KiB
Nix
Raw Normal View History

import ./make-test-python.nix ({pkgs, lib, ...}:
2019-06-09 17:05:30 +00:00
let
# A filesystem image with a (presumably) bootable debian
debianImage = pkgs.vmTools.diskImageFuns.debian11i386 {
2019-06-09 17:05:30 +00:00
# os-prober cannot detect systems installed on disks without a partition table
# so we create the disk ourselves
createRootFS = with pkgs; ''
${parted}/bin/parted --script /dev/vda mklabel msdos
${parted}/sbin/parted --script /dev/vda -- mkpart primary ext2 1M -1s
mkdir /mnt
${e2fsprogs}/bin/mkfs.ext4 -O '^metadata_csum_seed' /dev/vda1
2020-11-24 15:29:28 +00:00
${util-linux}/bin/mount -t ext4 /dev/vda1 /mnt
2019-06-09 17:05:30 +00:00
if test -e /mnt/.debug; then
exec ${bash}/bin/sh
fi
touch /mnt/.debug
mkdir /mnt/proc /mnt/dev /mnt/sys
'';
extraPackages = [
# /etc/os-release
"base-files"
# make the disk bootable-looking
"grub2" "linux-image-686"
];
# install grub
postInstall = ''
ln -sf /proc/self/mounts > /etc/mtab
PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \
grub-install /dev/vda --force
PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \
update-grub
'';
};
# a part of the configuration of the test vm
simpleConfig = {
boot.loader.grub = {
enable = true;
useOSProber = true;
device = "/dev/vda";
# vda is a filesystem without partition table
forceInstall = true;
};
nixos/nix-daemon: use structural settings The `nix.*` options, apart from options for setting up the daemon itself, currently provide a lot of setting mappings for the Nix daemon configuration. The scope of the mapping yields convience, but the line where an option is considered essential is blurry. For instance, the `extra-sandbox-paths` mapping is provided without its primary consumer, and the corresponding `sandbox-paths` option is also not mapped. The current system increases the maintenance burden as maintainers have to closely follow upstream changes. In this case, there are two state versions of Nix which have to be maintained collectively, with different options avaliable. This commit aims to following the standard outlined in RFC 42[1] to implement a structural setting pattern. The Nix configuration is encoded at its core as key-value pairs which maps nicely to attribute sets, making it feasible to express in the Nix language itself. Some existing options are kept such as `buildMachines` and `registry` which present a simplified interface to managing the respective settings. The interface is exposed as `nix.settings`. Legacy configurations are mapped to their corresponding options under `nix.settings` for backwards compatibility. Various options settings in other nixos modules and relevant tests have been updated to use structural setting for consistency. The generation and validation of the configration file has been modified to use `writeTextFile` instead of `runCommand` for clarity. Note that validation is now mandatory as strict checking of options has been pushed down to the derivation level due to freeformType consuming unmatched options. Furthermore, validation can not occur when cross-compiling due to current limitations. A new option `publicHostKey` was added to the `buildMachines` submodule corresponding to the base64 encoded public host key settings exposed in the builder syntax. The build machine generation was subsequently rewritten to use `concatStringsSep` for better performance by grouping concatenations. [1] - https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md
2021-11-19 22:36:26 +00:00
nix.settings = {
substituters = lib.mkForce [];
hashed-mirrors = null;
connect-timeout = 1;
};
# save some memory
documentation.enable = false;
2019-06-09 17:05:30 +00:00
};
# /etc/nixos/configuration.nix for the vm
configFile = pkgs.writeText "configuration.nix" ''
{config, pkgs, lib, ...}: ({
imports =
2019-06-09 17:05:30 +00:00
[ ./hardware-configuration.nix
<nixpkgs/nixos/modules/testing/test-instrumentation.nix>
];
} // lib.importJSON ${
pkgs.writeText "simpleConfig.json" (builtins.toJSON simpleConfig)
})
2019-06-09 17:05:30 +00:00
'';
in {
name = "os-prober";
2022-03-20 23:15:30 +00:00
nodes.machine = { config, pkgs, ... }: (simpleConfig // {
imports = [ ../modules/profiles/installation-device.nix
../modules/profiles/base.nix ];
virtualisation.memorySize = 1300;
# To add the secondary disk:
virtualisation.qemu.options = [ "-drive index=2,file=${debianImage}/disk-image.qcow2,read-only,if=virtio" ];
2019-06-09 17:05:30 +00:00
# The test cannot access the network, so any packages
# nixos-rebuild needs must be included in the VM.
system.extraDependencies = with pkgs;
[
nixosTests.os-prober: add bintools to the VM machine # warning: error: unable to download 'https://ftpmirror.gnu.org/bash/bash-5.2.tar.gz': Couldn't resolve host name (6); retrying in 329 ms machine # warning: error: unable to download 'https://ftpmirror.gnu.org/bash/bash-5.2.tar.gz': Couldn't resolve host name (6); retrying in 530 ms machine # warning: error: unable to download 'https://ftpmirror.gnu.org/bash/bash-5.2.tar.gz': Couldn't resolve host name (6); retrying in 1066 ms machine # warning: error: unable to download 'https://ftpmirror.gnu.org/bash/bash-5.2.tar.gz': Couldn't resolve host name (6); retrying in 2544 ms machine # [ 1283.199545] GUEST-test1[1465]: [ 414.478221] stage-1-init: [Wed Aug 23 13:26:29 UTC 2023] + loadkmap machine # error: machine # … writing file '/nix/store/v28dv6l0qk3j382kp40bksa1v6h7dx9p-bash-5.2.tar.gz' machine # machine # error: unable to download 'https://ftpmirror.gnu.org/bash/bash-5.2.tar.gz': Couldn't resolve host name (6) machine # error: builder for '/nix/store/5jrd75v747s76s16zxk59384xfcjqn58-bash-5.2.tar.gz.drv' failed with exit code 1 machine # error: 1 dependencies of derivation '/nix/store/0cgj4m2h51hjhmz5h4440pd73kv5lm5v-bash-5.2-p15.drv' failed to build machine # error: 1 dependencies of derivation '/nix/store/d2x66i0dfv9w81gl1w3nbkn0nz7mawaz-bash-5.2-p15.drv' failed to build machine # error: 1 dependencies of derivation '/nix/store/lcz1v3h1nsbyz2fp7xkp113jvyjqq0sx-bash-5.2-p15.drv' failed to build machine # building '/nix/store/20d5pi1a5i9jj041i0gvr9zcs7bjbw46-binutils-2.40.tar.bz2.drv'... machine # error: 1 dependencies of derivation '/nix/store/zb0ykvcllgc8l9ki38fdv9n8xp3rnphb-gcc-12.3.0.drv' failed to build machine # error: 1 dependencies of derivation '/nix/store/7kxjnzmc79sickp7hiyp8v169idyw8f2-gettext-0.21.1.drv' failed to build machine # error: 1 dependencies of derivation '/nix/store/wp7hpglhgwljl3fsfyx8caaakh4a1r72-xgcc-12.3.0.drv' failed to build machine # error: 1 dependencies of derivation '/nix/store/f7glbcn7n59k22b911bx1vyy13g4bdxh-binutils-2.40.drv' failed to build machine # error: 1 dependencies of derivation '/nix/store/q7yvprjmnqprx743ikkcz4kqx2mjdas4-binutils-wrapper-2.40.drv' failed to build machine # building '/nix/store/vks3aqqal1rjvrsbj61nl1yh7r5shhdh-builder.pl.drv'... machine # error: 1 dependencies of derivation '/nix/store/qmdff14r0l31mzx8al7h1kp9h5pck5wr-extra-utils.drv' failed to build machine # error: 1 dependencies of derivation '/nix/store/rdlk4188b2jp4ac38w94qazdaxk6sga9-stage-1-init.sh.drv' failed to build machine # error: 1 dependencies of derivation '/nix/store/rq15acvd6hcr52a5dlmk1p7mlyzjack0-initrd-linux-6.1.46.drv' failed to build machine # error: 1 dependencies of derivation '/nix/store/h1rch2zqjacijnn0szq2hgwmd6v1r1ld-nixos-system-nixos-23.11pre-git.drv' failed to build
2023-08-23 13:50:44 +00:00
bintools
brotli
brotli.dev
brotli.lib
2019-06-09 17:05:30 +00:00
desktop-file-utils
docbook5
docbook_xsl_ns
grub2
kbd
kbd.dev
kmod.dev
libarchive
libarchive.dev
libxml2.bin
libxslt.bin
2019-06-09 17:05:30 +00:00
nixos-artwork.wallpapers.simple-dark-gray-bottom
ntp
2019-06-09 17:05:30 +00:00
perlPackages.ListCompare
perlPackages.XMLLibXML
python3
2019-06-09 17:05:30 +00:00
shared-mime-info
stdenv
sudo
2019-06-09 17:05:30 +00:00
texinfo
unionfs-fuse
2019-06-09 17:05:30 +00:00
xorg.lndir
# add curl so that rather than seeing the test attempt to download
# curl's tarball, we see what it's trying to download
curl
];
});
testScript = ''
machine.start()
machine.succeed("udevadm settle")
machine.wait_for_unit("multi-user.target")
print(machine.succeed("lsblk"))
2019-06-09 17:05:30 +00:00
# check that os-prober works standalone
machine.succeed(
"${pkgs.os-prober}/bin/os-prober | grep /dev/vdb1"
)
2019-06-09 17:05:30 +00:00
# rebuild and test that debian is available in the grub menu
machine.succeed("nixos-generate-config")
machine.copy_from_host(
2019-06-09 17:05:30 +00:00
"${configFile}",
"/etc/nixos/configuration.nix",
)
machine.succeed("nixos-rebuild boot --show-trace >&2")
2019-06-09 17:05:30 +00:00
machine.succeed("egrep 'menuentry.*debian' /boot/grub/grub.cfg")
2019-06-09 17:05:30 +00:00
'';
})