nixos-rebuild: add flake support for build-vm

This relies on users using `nixpkgs.lib.nixosSystem` to define their
system; otherwise, the `vm` and `vmWithBootLoader` attributes will not
exist.
This commit is contained in:
Cole Helbling 2020-09-10 23:12:58 -07:00
parent 98a3c77296
commit e26b348689
No known key found for this signature in database
GPG Key ID: B37E0F2371016A4C
2 changed files with 29 additions and 7 deletions

View File

@ -5,7 +5,6 @@
outputs = { self }: outputs = { self }:
let let
jobs = import ./pkgs/top-level/release.nix { jobs = import ./pkgs/top-level/release.nix {
nixpkgs = self; nixpkgs = self;
}; };
@ -28,10 +27,31 @@
lib = lib.extend (final: prev: { lib = lib.extend (final: prev: {
nixosSystem = { modules, ... } @ args: nixosSystem = { modules, ... } @ args:
import ./nixos/lib/eval-config.nix (args // { import ./nixos/lib/eval-config.nix (args // {
modules = modules ++ modules =
[ { system.nixos.versionSuffix = let
vmConfig = (import ./nixos/lib/eval-config.nix
(args // {
modules = modules ++ [ ./nixos/modules/virtualisation/qemu-vm.nix ];
})).config;
vmWithBootLoaderConfig = (import ./nixos/lib/eval-config.nix
(args // {
modules = modules ++ [
./nixos/modules/virtualisation/qemu-vm.nix
{ virtualisation.useBootLoader = true; }
];
})).config;
in
modules ++ [
{
system.nixos.versionSuffix =
".${final.substring 0 8 (self.lastModifiedDate or self.lastModified)}.${self.shortRev or "dirty"}"; ".${final.substring 0 8 (self.lastModifiedDate or self.lastModified)}.${self.shortRev or "dirty"}";
system.nixos.revision = final.mkIf (self ? rev) self.rev; system.nixos.revision = final.mkIf (self ? rev) self.rev;
system.build = {
vm = vmConfig.system.build.vm;
vmWithBootLoader = vmWithBootLoaderConfig.system.build.vm;
};
} }
]; ];
}); });

View File

@ -438,15 +438,17 @@ if [ -z "$rollback" ]; then
if [[ -z $flake ]]; then if [[ -z $flake ]]; then
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A vm -k "${extraBuildFlags[@]}")" pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A vm -k "${extraBuildFlags[@]}")"
else else
echo "$0: 'build-vm' is not supported with '--flake'" >&2 nix "${flakeFlags[@]}" build "$flake#$flakeAttr.config.system.build.vm" \
exit 1 "${extraBuildFlags[@]}" "${lockFlags[@]}"
pathToConfig="$(readlink -f ./result)"
fi fi
elif [ "$action" = build-vm-with-bootloader ]; then elif [ "$action" = build-vm-with-bootloader ]; then
if [[ -z $flake ]]; then if [[ -z $flake ]]; then
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A vmWithBootLoader -k "${extraBuildFlags[@]}")" pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A vmWithBootLoader -k "${extraBuildFlags[@]}")"
else else
echo "$0: 'build-vm-with-bootloader' is not supported with '--flake'" >&2 nix "${flakeFlags[@]}" build "$flake#$flakeAttr.config.system.build.vmWithBootLoader" \
exit 1 "${extraBuildFlags[@]}" "${lockFlags[@]}"
pathToConfig="$(readlink -f ./result)"
fi fi
else else
showSyntax showSyntax