mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-17 19:21:04 +00:00
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:
parent
98a3c77296
commit
e26b348689
26
flake.nix
26
flake.nix
|
@ -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;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue