Move let
bindings to the top
This commit is contained in:
parent
8bb98177cf
commit
1ea8734a9c
1 changed files with 51 additions and 49 deletions
|
@ -1,4 +1,53 @@
|
|||
{ config, lib, options, pkgs, ... }: {
|
||||
{ config, lib, options, pkgs, ... }:
|
||||
let
|
||||
packageName = "custom-nixos-vm";
|
||||
|
||||
mergedSystemOption =
|
||||
with options.system;
|
||||
lib.mergeDefinitions
|
||||
build.loc
|
||||
build.type
|
||||
(lib.lists.forEach
|
||||
(
|
||||
builtins.filter
|
||||
(item:
|
||||
!(lib.path.hasPrefix ./. (/. + item.file)))
|
||||
build.definitionsWithLocations)
|
||||
(item: { inherit (item) file value; }));
|
||||
|
||||
vanillaVM = mergedSystemOption.mergedValue.vm;
|
||||
|
||||
createVMWrapper =
|
||||
vm:
|
||||
if (vm.name == packageName)
|
||||
then
|
||||
vm
|
||||
else
|
||||
let
|
||||
prefix =
|
||||
lib.concatStringsSep " " (
|
||||
lib.optionals config.virtualisation.runAsRoot (
|
||||
["sudo"] ++
|
||||
lib.optional config.virtualisation.qemu.runInBackground "-b"));
|
||||
|
||||
suffix =
|
||||
lib.concatStringsSep " " (
|
||||
lib.optional
|
||||
(!config.virtualisation.runAsRoot && config.virtualisation.qemu.runInBackground)
|
||||
"&");
|
||||
|
||||
wrapped = pkgs.writeShellApplication {
|
||||
name = "run-${config.system.name}-vm";
|
||||
text = ''
|
||||
${prefix} ${vm}/bin/run-${config.system.name}-vm ${suffix}
|
||||
'';
|
||||
};
|
||||
in
|
||||
pkgs.symlinkJoin {
|
||||
name = packageName;
|
||||
paths = [ wrapped ];
|
||||
};
|
||||
in {
|
||||
options =
|
||||
let
|
||||
vmVariantOptions = {
|
||||
|
@ -57,54 +106,7 @@
|
|||
# Replace native `qemu` with `remote-viewer`
|
||||
system.build =
|
||||
{
|
||||
vm =
|
||||
let
|
||||
packageName = "custom-nixos-vm";
|
||||
|
||||
mergedSystem =
|
||||
with options.system;
|
||||
lib.mergeDefinitions
|
||||
build.loc
|
||||
build.type
|
||||
(lib.lists.forEach
|
||||
(
|
||||
builtins.filter
|
||||
(item:
|
||||
!(lib.path.hasPrefix ./. (/. + item.file)))
|
||||
build.definitionsWithLocations)
|
||||
(item: { inherit (item) file value; }));
|
||||
in
|
||||
lib.mkForce (
|
||||
with { inherit (mergedSystem.mergedValue) vm; };
|
||||
if (vm.name == packageName)
|
||||
then
|
||||
vm
|
||||
else
|
||||
let
|
||||
prefix =
|
||||
lib.concatStringsSep " " (
|
||||
lib.optionals config.virtualisation.runAsRoot (
|
||||
["sudo"] ++
|
||||
lib.optional config.virtualisation.qemu.runInBackground "-b"));
|
||||
|
||||
suffix =
|
||||
lib.concatStringsSep " " (
|
||||
lib.optional
|
||||
(!config.virtualisation.runAsRoot && config.virtualisation.qemu.runInBackground)
|
||||
"&");
|
||||
|
||||
wrapped = pkgs.writeShellApplication {
|
||||
name = "run-${config.system.name}-vm";
|
||||
text = ''
|
||||
${prefix} ${vm}/bin/run-${config.system.name}-vm ${suffix}
|
||||
'';
|
||||
};
|
||||
in
|
||||
# Rename package to `nixos-vm`
|
||||
pkgs.symlinkJoin {
|
||||
name = packageName;
|
||||
paths = [ wrapped ];
|
||||
});
|
||||
vm = lib.mkForce (createVMWrapper vanillaVM);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue