/default.nix Secret
Last active
January 24, 2020 21:56
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
let | |
pkgs = import <nixpkgs> {}; | |
makeTest = { netboot }: rec { | |
eval = import <nixpkgs/nixos> { | |
configuration = { lib, ... }: { | |
imports = [ | |
<nixpkgs/nixos/modules/profiles/minimal.nix> | |
] ++ (lib.optional netboot <nixpkgs/nixos/modules/installer/netboot/netboot.nix>); | |
boot.supportedFilesystems = [ "zfs" ]; | |
networking.hostId = "ac78b77a"; | |
users.users.root.initialPassword = "password"; | |
fileSystems."/" = lib.mkIf (!netboot) { device = "tmpfs"; }; | |
boot.loader.grub.enable = false; | |
}; | |
}; | |
kernelTarget = eval.pkgs.stdenv.hostPlatform.platform.kernelTarget; | |
netboot_dir = let | |
build = eval.config.system.build; | |
in pkgs.symlinkJoin { | |
name = "netboot"; | |
paths = [ | |
build.netbootRamdisk | |
build.kernel | |
build.netbootIpxeScript | |
]; | |
postBuild = '' | |
mkdir -p $out/nix-support | |
echo "file ${kernelTarget} ${build.kernel}/${kernelTarget}" >> $out/nix-support/hydra-build-products | |
echo "file initrd ${build.netbootRamdisk}/initrd" >> $out/nix-support/hydra-build-products | |
echo "file ipxe ${build.netbootIpxeScript}/netboot.ipxe" >> $out/nix-support/hydra-build-products | |
''; | |
}; | |
custom_dir = pkgs.runCommand "dir" {} '' | |
mkdir $out | |
ln -sv ${eval.config.system.build.kernel}/${kernelTarget} $out/ | |
ln -sv ${custom_initrd}/initrd $out/ | |
''; | |
dir = if netboot then netboot_dir else custom_dir; | |
custom_initrd = pkgs.makeInitrd { | |
compressor = "${pkgs.pigz}/bin/pigz -9n"; | |
contents = [ | |
{ | |
symlink = "/init"; | |
object = "${eval.system}/init"; | |
} | |
]; | |
}; | |
test_script = pkgs.writeShellScript "tester" '' | |
${pkgs.qemu}/bin/qemu-system-x86_64 -kernel ${dir}/${kernelTarget} -initrd ${dir}/initrd -append "${toString eval.config.boot.kernelParams}" -m 2048 | |
''; | |
}; | |
in { | |
netboot = with (makeTest { netboot = true; }); { | |
inherit eval dir test_script; | |
}; | |
direct_stage_2 = with (makeTest { netboot = false; }); { | |
inherit eval custom_initrd test_script dir; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment