nix-community / nixbox

NixOS Vagrant boxes [maintainer=@ifurther]
https://app.vagrantup.com/nixbox/
MIT License
304 stars 101 forks source link

cdituri/feature/hyperv packer builder #58

Closed cdituri closed 4 years ago

cdituri commented 4 years ago

Overview

This pull request adds hyperv-iso builder support to nix-community/nixbox:

!!! Important: the last commit in the series brings iso_urls.json, nixos-i686.json, and nixos-x86_64.json to current. This is note-worthy because it looks like NixOS upstream is now using a 'latest' .iso release, and we leverage that new approach here as well.


Steps

Run packer build:

packer build -force -var "memory=2048" -var "disk_size=10280" -on-error=ask -only=hyperv-iso .\nixos-x86_64.json

Import resultant vagrant .box image:

vagrant box add --force --name hyperv/nixos-x86_64 .\nixos-19.09-hyperv-x86_64.box

Run vagrant:

vagrant init hyperv/nixos-x86_64
vagrant up --provider=hyperv

Final note: many individuals on Windows have git config --global core.autocrlf true set, myself included. Having autocrlf set caused the following error during packer build, after a fresh clone:

==> hyperv-iso: Installation finished. No error reported.
    hyperv-iso: installation finished!
==> hyperv-iso:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
==> hyperv-iso:                                  Dload  Upload   Total   Spent    Left  Speed
==> hyperv-iso: 100   524  100   524    0     0  32750      0 --:--:-- --:--:-- --:--:-- 34933
==> hyperv-iso: setting up /etc...
==> hyperv-iso: /nix/var/nix/profiles/system/sw/bin/bash: line 2: $'\r': command not found
==> hyperv-iso: /nix/var/nix/profiles/system/sw/bin/bash: line 4: $'\r': command not found
==> hyperv-iso: /nix/var/nix/profiles/system/sw/bin/bash: line 7: $'\r': command not found
==> hyperv-iso: /nix/var/nix/profiles/system/sw/bin/bash: line 8: syntax error near unexpected token `$'do\r''
==> hyperv-iso: '
    hyperv-iso: Start postinstall ...
==> hyperv-iso: Script exited with non-zero exit status: 2.Allowed exit codes are: [0]
==> hyperv-iso: Step "StepProvision" failed
==> hyperv-iso: [c] Clean up and exit, [a] abort without cleanup, or [r] retry step (build may fail even if retry succeeds)?

If you see this error, its because scripts/{install, post-install}.sh need to be LF; and git on Windows has presumably checked them out with CRLF line-endings on clone/checkout.

cdituri commented 4 years ago

Thanks for the review @zimbatm, much appreciated :+1: crazy at work atm so aiming to circle back here sometime over the weekend to incorporate your feedback.

This is going to be hard to maintain as it requires the user to have HyperV installed. But there isn't much we can do, this is the current packer design.

Totally understand, re: maintenance and packer design. I just want more NixOS! and as long as Windows is the preference at my employer, more than happy to help maintain this native Hyper-V builder :smiley:

zimbatm commented 4 years ago

Sounds good. Let me know when it's ready to be merged :)

cdituri commented 4 years ago

@zimbatm pull request is ready to merge at the moment. Some things worth nothing below first however:

  1. In the last 2 weeks the NixOS website has changed the way they publish the .iso links, breaking the regex in iso_urls_update.rb. @shajra-simspace left a comment in #59 switching the implementation from regex parsing to XML parsing. It's a more robust implementation, and I've included an attributed commit 1201013e103228f80683efd5e224fff78b7e8a22.

@shajra-simspace hope you're ok with the above approach. Any thoughts, or would you like things attributed differently, etc? see the commit link.

  1. NixOS 20.03 has changed users.group and users.users and are depreciating the current form. For nix-community/nixbox I've left things as-is, as it;s the most graceful approach (ie backwards compatible when building <= NixOS 20.03), and warns adequately while building. See NixOS/nikpkgs/pull/63103 and the below.

    Click to expand and show warnings generated ==> hyperv-iso: mke2fs 1.45.5 (07-Jan-2020) hyperv-iso: Discarding device blocks: done hyperv-iso: Creating filesystem with 2631424 4k blocks and 658368 inodes hyperv-iso: Filesystem UUID: ed750ed0-be48-4875-9572-ae69f994de08 hyperv-iso: Superblock backups stored on blocks: hyperv-iso: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 hyperv-iso: hyperv-iso: Allocating group tables: done hyperv-iso: Writing inode tables: done hyperv-iso: Creating journal (16384 blocks): done hyperv-iso: Writing superblocks and filesystem accounting information: done hyperv-iso: ==> hyperv-iso: writing /mnt/etc/nixos/hardware-configuration.nix... ==> hyperv-iso: writing /mnt/etc/nixos/configuration.nix... hyperv-iso: building the configuration in /mnt/etc/nixos/configuration.nix... ==> hyperv-iso: trace: warning: In file /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/config/users-groups.nix ==> hyperv-iso: a list is being assigned to the option config.users.users. ==> hyperv-iso: This will soon be an error as type loaOf is deprecated. ==> hyperv-iso: See https://github.com/NixOS/nixpkgs/pull/63103 for more information. ==> hyperv-iso: Do ==> hyperv-iso: users.users = ==> hyperv-iso: { root = {...}; vagrant = {...}; } ==> hyperv-iso: instead of ==> hyperv-iso: users.users = ==> hyperv-iso: [ { name = "root"; ...} { name = "vagrant"; ...} ] ==> hyperv-iso: ==> hyperv-iso: trace: warning: In file /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/config/users-groups.nix ==> hyperv-iso: a list is being assigned to the option config.users.groups. ==> hyperv-iso: This will soon be an error as type loaOf is deprecated. ==> hyperv-iso: See https://github.com/NixOS/nixpkgs/pull/63103 for more information. ==> hyperv-iso: Do ==> hyperv-iso: users.groups = ==> hyperv-iso: { vagrant = {...}; } ==> hyperv-iso: instead of ==> hyperv-iso: users.groups = ==> hyperv-iso: [ { name = "vagrant"; ...} ] ==> hyperv-iso: hyperv-iso: copying channel... hyperv-iso: installing the boot loader... ==> hyperv-iso: setting up /etc... ==> hyperv-iso: updating GRUB 2 menu... ==> hyperv-iso: installing the GRUB 2 boot loader on /dev/sda... ==> hyperv-iso: Installing for i386-pc platform. ==> hyperv-iso: Installation finished. No error reported. hyperv-iso: installation finished!
zimbatm commented 4 years ago

thanks!