From 6b4e6548e55c9b1c023cf2acb822dc41a800541d Mon Sep 17 00:00:00 2001 From: adisbladis Date: Tue, 28 Jan 2020 23:16:49 +0000 Subject: [PATCH] windows: Fix stupid quoting issues in autounattend XML The windows XML parser is shit and bails out extremely late, making debugging this a 1+ hour ordeal for every iteration. Let's just write out a powershell script and be done with it. --- artiq-fast/windows/autounattend.nix | 39 +++++++++++++++++++++-------- artiq-fast/windows/run-test.nix | 3 ++- artiq-fast/windows/win.nix | 8 +++++- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/artiq-fast/windows/autounattend.nix b/artiq-fast/windows/autounattend.nix index c2cfd23..5853a6b 100644 --- a/artiq-fast/windows/autounattend.nix +++ b/artiq-fast/windows/autounattend.nix @@ -34,21 +34,18 @@ let ) ) services; - # If we are running in impure mode we can also enable networked services - impureSetupCommands = let + sshSetupCommands = let makeDirs = lib.mapAttrsToList (n: v: ''mkdir C:\Users\${n}\.ssh'') users; writeKeys = lib.flatten (lib.mapAttrsToList (n: v: builtins.map (key: let commands = [ - ''powershell.exe "echo ${key} | Out-File -FilePath C:\Users\${n}\.ssh\authorized_keys"'' + ''powershell.exe Set-Content -Path C:\Users\${n}\.ssh\authorized_keys -Value '${key}' '' ]; in lib.concatStringsSep "\n" commands) (v.sshKeys or [])) users); mkDirsDesc = builtins.map (c: {Path = c; Description = "Make SSH key dir";}) makeDirs; writeKeysDesc = builtins.map (c: {Path = c; Description = "Add SSH key";}) writeKeys; - in mkDirsDesc ++ writeKeysDesc ++ [ - # TODO: Figure out how to do this step with sandboxing enabled { - Path = ''Register-PSRepository -Name bootstraprepo -SourceLocation F:\files''; + Path = ''powershell.exe Register-PSRepository -Name bootstraprepo -SourceLocation F:\files''; Description = "Local powershell repo import"; } { @@ -81,7 +78,12 @@ let } ] ++ setupCommands - ++ impureSetupCommands + ++ [ + { + Path = ''powershell.exe F:\ssh-setup.ps1''; + Description = "Setup SSH and keys"; + } + ] ++ serviceCommands ++ impureShellCommands ); @@ -290,8 +292,23 @@ let ''; -in +in { # Lint and format as a sanity check -pkgs.runCommandNoCC "autounattend.xml" {} '' - ${pkgs.libxml2}/bin/xmllint --format ${autounattendXML} > $out -'' + autounattendXML = pkgs.runCommandNoCC "autounattend.xml" {} '' + ${pkgs.libxml2}/bin/xmllint --format ${autounattendXML} > $out + ''; + + # autounattend.xml is _super_ picky about quotes and other things + setupScript = pkgs.writeText "ssh-setup.ps1" ( + '' + # Setup SSH and keys + '' + + lib.concatStrings ( + builtins.map (c: '' + # ${c.Description} + ${c.Path} + '') sshSetupCommands + ) + ); + +} diff --git a/artiq-fast/windows/run-test.nix b/artiq-fast/windows/run-test.nix index a501b5a..916d571 100644 --- a/artiq-fast/windows/run-test.nix +++ b/artiq-fast/windows/run-test.nix @@ -35,7 +35,8 @@ stdenv.mkDerivation { name = "windows-test-runner"; # Dummy sources - src = pkgs.runCommandNoCC "" {} "touch $out"; + src = pkgs.runCommandNoCC "dummy" {} "touch $out"; + dontUnpack = true; propagatedBuildInputs = qemu.inputs; dontBuild = true; diff --git a/artiq-fast/windows/win.nix b/artiq-fast/windows/win.nix index b41971e..5a69c8f 100644 --- a/artiq-fast/windows/win.nix +++ b/artiq-fast/windows/win.nix @@ -81,6 +81,10 @@ let mkdir pkgs/files cp ${bundleInstaller} pkgs/"$(stripHash "${bundleInstaller}")" + + # SSH setup script goes here because windows XML parser sucks + cp ${autounattend.setupScript} pkgs/ssh-setup.ps1 + cp ${nuget} pkgs/bootstrap/00_"$(stripHash "${nuget}")" cp ${opensshutils} pkgs/bootstrap/01_"$(stripHash "${opensshutils}")" cp ${anaconda} pkgs/bootstrap/02_"$(stripHash "${anaconda}")" @@ -133,7 +137,9 @@ let mkdir -p win mkdir -p win/nix-win 7z x -y ${windowsIso} -owin - cp ${autounattend} win/autounattend.xml + + cp ${autounattend.autounattendXML} win/autounattend.xml + virt-make-fs --partition --type=fat win/ usbimage.img rm -rf win