From 9f8a1b6e179f81313e89dd6a0f3787c937cb5a73 Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 10 Apr 2021 23:09:30 +0200 Subject: [PATCH 1/3] layers: add disable-firewall, disable-autosleep, disable-autolock --- wfvm/demo-image.nix | 5 ++++- wfvm/layers/default.nix | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/wfvm/demo-image.nix b/wfvm/demo-image.nix index 66040c0..dd0727f 100644 --- a/wfvm/demo-image.nix +++ b/wfvm/demo-image.nix @@ -37,7 +37,10 @@ wfvm.makeWindowsImage { # administratorPassword = "12345"; # Imperative installation commands, to be installed incrementally - installCommands = with wfvm.layers; [ anaconda3 msys2 msvc msvc-ide-unbreak ]; + installCommands = with wfvm.layers; [ + disable-autosleep disable-autolock disable-firewall + anaconda3 msys2 msvc msvc-ide-unbreak + ]; # services = { # # Enable remote management diff --git a/wfvm/layers/default.nix b/wfvm/layers/default.nix index 5129632..452b737 100644 --- a/wfvm/layers/default.nix +++ b/wfvm/layers/default.nix @@ -122,4 +122,36 @@ in sleep 40 ''; }; + # Disable the Windows firewall + disable-firewall = { + name = "disable-firewall"; + script = '' + echo Disabling firewall + win-exec "netsh advfirewall set allprofiles state off" + ''; + }; + # Disable automatic power management which causes the machine to go + # into standby after periods without mouse wiggling. + disable-autosleep = { + name = "disable-autosleep"; + script = '' + echo Disabling autosleep + win-exec "powercfg /x -hibernate-timeout-ac 0" + win-exec "powercfg /x -hibernate-timeout-dc 0" + win-exec "powercfg /x -disk-timeout-ac 0" + win-exec "powercfg /x -disk-timeout-dc 0" + win-exec "powercfg /x -monitor-timeout-ac 0" + win-exec "powercfg /x -monitor-timeout-dc 0" + win-exec "powercfg /x -standby-timeout-ac 0" + win-exec "powercfg /x -standby-timeout-dc 0" + ''; + }; + # Turn off automatic locking of idle user sessions + disable-autolock = { + name = "disable-autolock"; + script = '' + echo Disabling autolock + win-exec "reg add HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Personalization /v NoLockScreen /t REG_DWORD /d 1" + ''; + }; } -- 2.42.0 From 78c9363b648864162d00123cbd1aac3406b5e5a0 Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 10 Apr 2021 23:11:19 +0200 Subject: [PATCH 2/3] demo-image: use empty installCommands for impureMode --- wfvm/demo-image.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wfvm/demo-image.nix b/wfvm/demo-image.nix index dd0727f..0259c08 100644 --- a/wfvm/demo-image.nix +++ b/wfvm/demo-image.nix @@ -37,10 +37,13 @@ wfvm.makeWindowsImage { # administratorPassword = "12345"; # Imperative installation commands, to be installed incrementally - installCommands = with wfvm.layers; [ - disable-autosleep disable-autolock disable-firewall - anaconda3 msys2 msvc msvc-ide-unbreak - ]; + installCommands = + if impureMode + then [] + else with wfvm.layers; [ + disable-autosleep disable-autolock disable-firewall + anaconda3 msys2 msvc msvc-ide-unbreak + ]; # services = { # # Enable remote management -- 2.42.0 From 4771cee64b1faccb92181009d1a0198709b9a89a Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 10 Apr 2021 23:12:13 +0200 Subject: [PATCH 3/3] layers: add collapseLayers --- wfvm/demo-image.nix | 6 +++++- wfvm/layers/default.nix | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/wfvm/demo-image.nix b/wfvm/demo-image.nix index 0259c08..183f65c 100644 --- a/wfvm/demo-image.nix +++ b/wfvm/demo-image.nix @@ -41,7 +41,11 @@ wfvm.makeWindowsImage { if impureMode then [] else with wfvm.layers; [ - disable-autosleep disable-autolock disable-firewall + (collapseLayers [ + disable-autosleep + disable-autolock + disable-firewall + ]) anaconda3 msys2 msvc msvc-ide-unbreak ]; diff --git a/wfvm/layers/default.nix b/wfvm/layers/default.nix index 452b737..8fb9958 100644 --- a/wfvm/layers/default.nix +++ b/wfvm/layers/default.nix @@ -154,4 +154,15 @@ in win-exec "reg add HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Personalization /v NoLockScreen /t REG_DWORD /d 1" ''; }; + + # 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; + script = builtins.concatStringsSep "\n" ( + map ({ script, ... }: script) scripts + ); + buildInputs = + builtins.concatMap ({ buildInputs ? [], ... }: buildInputs) scripts; + }; } -- 2.42.0