From 10bb7df7edead6c49667d7dc7bb4e6c49b597d60 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 14 Jun 2020 12:15:00 +0800 Subject: [PATCH] wfvm: reorganize --- artiq-fast/wfvm/README.md | 6 +- artiq-fast/wfvm/build.nix | 147 ------------------ artiq-fast/wfvm/default.nix | 3 +- artiq-fast/wfvm/demo-image.nix | 80 ++++++++++ artiq-fast/wfvm/layers/default.nix | 64 ++++++++ .../wfvm/{ => layers}/make_msys_packages.sh | 0 .../wfvm/{ => layers}/msys_packages.nix | 0 7 files changed, 148 insertions(+), 152 deletions(-) delete mode 100644 artiq-fast/wfvm/build.nix create mode 100644 artiq-fast/wfvm/demo-image.nix create mode 100644 artiq-fast/wfvm/layers/default.nix rename artiq-fast/wfvm/{ => layers}/make_msys_packages.sh (100%) rename artiq-fast/wfvm/{ => layers}/msys_packages.nix (100%) diff --git a/artiq-fast/wfvm/README.md b/artiq-fast/wfvm/README.md index 9272098..5914229 100644 --- a/artiq-fast/wfvm/README.md +++ b/artiq-fast/wfvm/README.md @@ -2,19 +2,19 @@ ## Install a Windows image -1. Adjust build.nix accordingly +1. Adjust demo-image.nix accordingly 2. Run: If in impure mode ```shell -nix-build build.nix +nix-build demo-image.nix ./result ``` Results in a file called c.img If in pure mode ```shell -nix-build build.nix +nix-build demo-image.nix ls -la ./result ``` Results in a symlink to the image in the nix store diff --git a/artiq-fast/wfvm/build.nix b/artiq-fast/wfvm/build.nix deleted file mode 100644 index c764b48..0000000 --- a/artiq-fast/wfvm/build.nix +++ /dev/null @@ -1,147 +0,0 @@ -{ - pkgs ? import {} - , impureMode ? false -}: - -let - win = (import ./default.nix { inherit pkgs; }); - -in -win.makeWindowsImage { - - # Custom base iso - # windowsImage = pkgs.fetchurl { - # url = "https://software-download.microsoft.com/download/sg/17763.107.101029-1455.rs5_release_svc_refresh_CLIENT_LTSC_EVAL_x64FRE_en-us.iso"; - # sha256 = "668fe1af70c2f7416328aee3a0bb066b12dc6bbd2576f40f812b95741e18bc3a"; - # }; - - # User accounts - users = { - artiq = { - password = "1234"; - # description = "Default user"; - # displayName = "Display name"; - groups = [ - "Administrators" - ]; - }; - }; - - # Build install script & skip building iso - inherit impureMode; - - # impureShellCommands = [ - # "powershell.exe echo Hello" - # ]; - - fullName = "M-Labs"; - organization = "m-labs"; - - administratorPassword = "12345"; - - # Auto login - defaultUser = "artiq"; - - # Imperative installation commands, to be installed incrementally - installCommands = [ - - { - name = "Anaconda3"; - script = let - Anaconda3 = pkgs.fetchurl { - name = "Anaconda3.exe"; - url = "https://repo.anaconda.com/archive/Anaconda3-2019.03-Windows-x86_64.exe"; - sha256 = "1f9icm5rwab6l1f23a70dw0qixzrl62wbglimip82h4zhxlh3jfj"; - }; - in '' - ln -s ${Anaconda3} ./Anaconda3.exe - win-put Anaconda3.exe 'C:\Users\artiq' - echo Running Anaconda installer... - win-exec 'start /wait "" .\Anaconda3.exe /S /D=%UserProfile%\Anaconda3' - echo Anaconda installer finished - ''; - } - { - name = "MSYS2"; - buildInputs = [ pkgs.expect ]; - script = let - msys2 = pkgs.fetchurl { - name = "msys2.exe"; - url = "https://github.com/msys2/msys2-installer/releases/download/2020-06-02/msys2-x86_64-20200602.exe"; - sha256 = "1mswlfybvk42vdr4r85dypgkwhrp5ff47gcbxgjqwq86ym44xzd4"; - }; - msys2-auto-install = pkgs.fetchurl { - url = "https://raw.githubusercontent.com/msys2/msys2-installer/master/auto-install.js"; - sha256 = "0ww48xch2q427c58arg5llakfkfzh3kb32kahwplp0s7jc8224g7"; - }; - in '' - ln -s ${msys2} ./msys2.exe - ln -s ${msys2-auto-install} ./auto-install.js - win-put msys2.exe 'C:\Users\artiq' - win-put auto-install.js 'C:\Users\artiq' - echo Running MSYS2 installer... - # work around MSYS2 installer bug that prevents it from closing at the end of unattended install - expect -c 'set timeout 600; spawn win-exec ".\\msys2.exe --script auto-install.js -v InstallPrefix=C:\\msys64"; expect FinishedPageCallback { close }' - echo MSYS2 installer finished - ''; - } - { - name = "MSYS2-with-packages"; - script = let - msys-packages = import ./msys_packages.nix { inherit pkgs; }; - msys-packages-put = pkgs.lib.strings.concatStringsSep "\n" - (map (package: ''win-put ${package} 'C:\Users\artiq\msyspackages' '') msys-packages); - in - # Windows command line is so shitty it can't even do glob expansion. Why do people use Windows? - '' - win-exec 'mkdir msyspackages' - ${msys-packages-put} - cat > installmsyspackages.bat << EOF - set MSYS=c:\msys64 - set ARCH=64 - set PATH=%MSYS%\usr\bin;%MSYS%\mingw%ARCH%\bin;%PATH% - bash -c "pacman -U --noconfirm C:/Users/artiq/msyspackages/*" - EOF - win-put installmsyspackages.bat 'C:\Users\artiq' - win-exec installmsyspackages - ''; - } - - ]; - - # services = { - # # Enable remote management - # WinRm = { - # Status = "Running"; - # PassThru = true; - # }; - # }; - - # License key - # productKey = "iboughtthisone"; - - # Locales - # uiLanguage = "en-US"; - # inputLocale = "en-US"; - # userLocale = "en-US"; - # systemLocale = "en-US"; - - # packages = [ - # ( - # win.pkgs.makeMSIPkg { - # # Note: File not in repository, it's meant as an example to subsitute - # name = "notepadplusplus"; - # msi = ./Notepad++7.7.msi; - # # Custom cert - # # cert = ./notepad++-cert.cer - # } - # ) - # ( - # win.pkgs.makeCrossPkg { - # name = "hello"; - # pkg = pkgs.pkgsCross.mingwW64.hello; - # } - # ) - # ]; - -} diff --git a/artiq-fast/wfvm/default.nix b/artiq-fast/wfvm/default.nix index 74a82d1..85c9a32 100644 --- a/artiq-fast/wfvm/default.nix +++ b/artiq-fast/wfvm/default.nix @@ -1,5 +1,4 @@ -{ pkgs ? import {} -}: +{ pkgs ? import {} }: { makeWindowsImage = attrs: import ./win.nix ({ inherit pkgs; } // attrs); diff --git a/artiq-fast/wfvm/demo-image.nix b/artiq-fast/wfvm/demo-image.nix new file mode 100644 index 0000000..d233202 --- /dev/null +++ b/artiq-fast/wfvm/demo-image.nix @@ -0,0 +1,80 @@ +{ pkgs ? import {}, impureMode ? false }: + +let + win = (import ./default.nix { inherit pkgs; }); + layers = (import ./layers { inherit pkgs; }); +in +win.makeWindowsImage { + + # Custom base iso + # windowsImage = pkgs.fetchurl { + # url = "https://software-download.microsoft.com/download/sg/17763.107.101029-1455.rs5_release_svc_refresh_CLIENT_LTSC_EVAL_x64FRE_en-us.iso"; + # sha256 = "668fe1af70c2f7416328aee3a0bb066b12dc6bbd2576f40f812b95741e18bc3a"; + # }; + + # User accounts + users = { + artiq = { + password = "1234"; + # description = "Default user"; + # displayName = "Display name"; + groups = [ + "Administrators" + ]; + }; + }; + + # Build install script & skip building iso + inherit impureMode; + + # impureShellCommands = [ + # "powershell.exe echo Hello" + # ]; + + fullName = "M-Labs"; + organization = "m-labs"; + + administratorPassword = "12345"; + + # Auto login + defaultUser = "artiq"; + + # Imperative installation commands, to be installed incrementally + installCommands = [ layers.anaconda3 layers.msys2 layers.msys2-packages ]; + + # services = { + # # Enable remote management + # WinRm = { + # Status = "Running"; + # PassThru = true; + # }; + # }; + + # License key + # productKey = "iboughtthisone"; + + # Locales + # uiLanguage = "en-US"; + # inputLocale = "en-US"; + # userLocale = "en-US"; + # systemLocale = "en-US"; + + # packages = [ + # ( + # win.pkgs.makeMSIPkg { + # # Note: File not in repository, it's meant as an example to subsitute + # name = "notepadplusplus"; + # msi = ./Notepad++7.7.msi; + # # Custom cert + # # cert = ./notepad++-cert.cer + # } + # ) + # ( + # win.pkgs.makeCrossPkg { + # name = "hello"; + # pkg = pkgs.pkgsCross.mingwW64.hello; + # } + # ) + # ]; + +} diff --git a/artiq-fast/wfvm/layers/default.nix b/artiq-fast/wfvm/layers/default.nix new file mode 100644 index 0000000..4a98165 --- /dev/null +++ b/artiq-fast/wfvm/layers/default.nix @@ -0,0 +1,64 @@ +{ pkgs }: +{ + anaconda3 = { + name = "Anaconda3"; + script = let + Anaconda3 = pkgs.fetchurl { + name = "Anaconda3.exe"; + url = "https://repo.anaconda.com/archive/Anaconda3-2019.03-Windows-x86_64.exe"; + sha256 = "1f9icm5rwab6l1f23a70dw0qixzrl62wbglimip82h4zhxlh3jfj"; + }; + in '' + ln -s ${Anaconda3} ./Anaconda3.exe + win-put Anaconda3.exe 'C:\Users\artiq' + echo Running Anaconda installer... + win-exec 'start /wait "" .\Anaconda3.exe /S /D=%UserProfile%\Anaconda3' + echo Anaconda installer finished + ''; + }; + msys2 = { + name = "MSYS2"; + buildInputs = [ pkgs.expect ]; + script = let + msys2 = pkgs.fetchurl { + name = "msys2.exe"; + url = "https://github.com/msys2/msys2-installer/releases/download/2020-06-02/msys2-x86_64-20200602.exe"; + sha256 = "1mswlfybvk42vdr4r85dypgkwhrp5ff47gcbxgjqwq86ym44xzd4"; + }; + msys2-auto-install = pkgs.fetchurl { + url = "https://raw.githubusercontent.com/msys2/msys2-installer/master/auto-install.js"; + sha256 = "0ww48xch2q427c58arg5llakfkfzh3kb32kahwplp0s7jc8224g7"; + }; + in '' + ln -s ${msys2} ./msys2.exe + ln -s ${msys2-auto-install} ./auto-install.js + win-put msys2.exe 'C:\Users\artiq' + win-put auto-install.js 'C:\Users\artiq' + echo Running MSYS2 installer... + # work around MSYS2 installer bug that prevents it from closing at the end of unattended install + expect -c 'set timeout 600; spawn win-exec ".\\msys2.exe --script auto-install.js -v InstallPrefix=C:\\msys64"; expect FinishedPageCallback { close }' + echo MSYS2 installer finished + ''; + }; + msys2-packages = { + name = "MSYS2-packages"; + script = let + msys-packages = import ./msys_packages.nix { inherit pkgs; }; + msys-packages-put = pkgs.lib.strings.concatStringsSep "\n" + (map (package: ''win-put ${package} 'C:\Users\artiq\msyspackages' '') msys-packages); + in + # Windows command line is so shitty it can't even do glob expansion. Why do people use Windows? + '' + win-exec 'mkdir msyspackages' + ${msys-packages-put} + cat > installmsyspackages.bat << EOF + set MSYS=c:\msys64 + set ARCH=64 + set PATH=%MSYS%\usr\bin;%MSYS%\mingw%ARCH%\bin;%PATH% + bash -c "pacman -U --noconfirm C:/Users/artiq/msyspackages/*" + EOF + win-put installmsyspackages.bat 'C:\Users\artiq' + win-exec installmsyspackages + ''; + }; +} diff --git a/artiq-fast/wfvm/make_msys_packages.sh b/artiq-fast/wfvm/layers/make_msys_packages.sh similarity index 100% rename from artiq-fast/wfvm/make_msys_packages.sh rename to artiq-fast/wfvm/layers/make_msys_packages.sh diff --git a/artiq-fast/wfvm/msys_packages.nix b/artiq-fast/wfvm/layers/msys_packages.nix similarity index 100% rename from artiq-fast/wfvm/msys_packages.nix rename to artiq-fast/wfvm/layers/msys_packages.nix