flake: slight cleanup of redundant code

pull/14/head
mwojcik 2022-02-17 17:24:36 +08:00
parent 35dea5d8a6
commit 0e53281c09
1 changed files with 13 additions and 19 deletions

View File

@ -4,6 +4,7 @@
outputs = { self, nixpkgs }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
# common settings
baseRtc = "2020-04-20T14:21:42";
cores = "4";
@ -24,7 +25,7 @@
"-rtc base=${baseRtc}"
"-device qemu-xhci"
"-device virtio-net-pci,netdev=n1"
] ++ pkgs.lib.optionals efi [
] ++ lib.optionals efi [
"-bios ${pkgs.OVMF.fd}/FV/OVMF.fd"
] ++ extraFlags;
@ -95,7 +96,7 @@
(map ({ listenAddr, targetAddr, port }:
",guestfwd=tcp:${listenAddr}:${toString port}-cmd:${pkgs.socat}/bin/socat\\ -\\ tcp:${targetAddr}:${toString port}"
) forwardedPorts);
qemuParams = mkQemuFlags (pkgs.lib.optional (!display) "-display none" ++ pkgs.lib.optional (!fakeRtc) "-rtc base=localtime" ++ [
qemuParams = mkQemuFlags (lib.optional (!display) "-display none" ++ lib.optional (!fakeRtc) "-rtc base=localtime" ++ [
"-drive"
"file=${image},index=0,media=disk,cache=unsafe"
"-snapshot"
@ -103,7 +104,7 @@
]);
in pkgs.writeShellScriptBin "wfvm-run-${name}" ''
set -e -m
${qemu}/bin/qemu-system-x86_64 ${pkgs.lib.concatStringsSep " " qemuParams} &
${qemu}/bin/qemu-system-x86_64 ${lib.concatStringsSep " " qemuParams} &
${win-wait}/bin/win-wait
@ -165,7 +166,7 @@
msys2-packages = msys-packages: {
name = "MSYS2-packages";
script = let
msys-packages-put = pkgs.lib.strings.concatStringsSep "\n"
msys-packages-put = lib.strings.concatStringsSep "\n"
(map (package: ''win-put ${package} 'msyspackages' '') msys-packages);
in
# Windows command line is so shitty it can't even do glob expansion. Why do people use Windows?
@ -286,7 +287,7 @@
# Chain together layers that are quick to run so that the VM does
# not have to be started/shutdown for each.
collapseLayers = scripts: {
name = pkgs.lib.concatMapStringsSep "-" ({ name, ... }: name) scripts;
name = lib.concatMapStringsSep "-" ({ name, ... }: name) scripts;
script = builtins.concatStringsSep "\n" (
map ({ script, ... }: script) scripts
);
@ -305,9 +306,7 @@
, inputLocale ? "en-US"
, userLocale ? "en-US"
, systemLocale ? "en-US"
, users ? { wfvm = { password = "1234";
description = "WFVM Administrator";
groups = [ "Administrators" ]; }; }
, additionalUsers ? {}
, productKey ? null
, defaultUser ? "wfvm"
, setupCommands ? []
@ -320,7 +319,9 @@
}:
let
lib = pkgs.lib;
users = additionalUsers // { wfvm = { password = "1234";
description = "WFVM Administrator";
groups = [ "Administrators" ]; }; };
serviceCommands = lib.mapAttrsToList (
serviceName: attrs: "powershell Set-Service -Name ${serviceName} " + (
lib.concatStringsSep " " (
@ -644,7 +645,7 @@
, ...
}@attrs:
let
lib = pkgs.lib;
libguestfs = pkgs.libguestfs-with-appliance;
# p7zip on >20.03 has known vulns but we have no better option
@ -667,7 +668,7 @@
);
windowsIso = if windowsImage != null then windowsImage else pkgs.requireFile rec {
name = "Win10_21H1_English_x64.iso";
name = "Win10_21H2_English_x64.iso";
sha256 = "1sl51lnx4r6ckh5fii7m2hi15zh8fh7cf7rjgjq9kacg8hwyh4b9";
message = "Get ${name} from https://www.microsoft.com/en-us/software-download/windows10ISO";
};
@ -684,14 +685,7 @@
};
autounattend = build-autounattend attrs // {
users = users // { wfvm = {
password = "1234";
description = "WFVM Administrator";
groups = [
"Administrators"
];
};
};
additionalUsers = users;
};
# Packages required to drive installation of other packages