mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-25 04:12:44 +03: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 }:
|
||||
let
|
||||
|
||||
jobs = import ./pkgs/top-level/release.nix {
|
||||
nixpkgs = self;
|
||||
};
|
||||
@ -28,10 +27,31 @@
|
||||
lib = lib.extend (final: prev: {
|
||||
nixosSystem = { modules, ... } @ args:
|
||||
import ./nixos/lib/eval-config.nix (args // {
|
||||
modules = modules ++
|
||||
[ { system.nixos.versionSuffix =
|
||||
modules =
|
||||
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"}";
|
||||
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
|
||||
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A vm -k "${extraBuildFlags[@]}")"
|
||||
else
|
||||
echo "$0: 'build-vm' is not supported with '--flake'" >&2
|
||||
exit 1
|
||||
nix "${flakeFlags[@]}" build "$flake#$flakeAttr.config.system.build.vm" \
|
||||
"${extraBuildFlags[@]}" "${lockFlags[@]}"
|
||||
pathToConfig="$(readlink -f ./result)"
|
||||
fi
|
||||
elif [ "$action" = build-vm-with-bootloader ]; then
|
||||
if [[ -z $flake ]]; then
|
||||
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A vmWithBootLoader -k "${extraBuildFlags[@]}")"
|
||||
else
|
||||
echo "$0: 'build-vm-with-bootloader' is not supported with '--flake'" >&2
|
||||
exit 1
|
||||
nix "${flakeFlags[@]}" build "$flake#$flakeAttr.config.system.build.vmWithBootLoader" \
|
||||
"${extraBuildFlags[@]}" "${lockFlags[@]}"
|
||||
pathToConfig="$(readlink -f ./result)"
|
||||
fi
|
||||
else
|
||||
showSyntax
|
||||
|
Loading…
Reference in New Issue
Block a user