Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: nixos/vagrant-virtualbox-image: init #76071

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions nixos/modules/virtualisation/vagrant-guest.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Minimal configuration that vagrant depends on

{ config, pkgs, ... }:

{
# Enable the OpenSSH daemon.
services.openssh.enable = true;

# Packages used by Vagrant
environment.systemPackages = with pkgs; [
findutils
iputils
nettools
netcat
nfs-utils
rsync
];

users.extraUsers.vagrant = {
isNormalUser = true;
createHome = true;
description = "Vagrant user account";
extraGroups = [ "users" "wheel" ];
home = "/home/vagrant";
password = "vagrant";
useDefaultShell = true;
uid = 1000;
# Vagrant uses an insecure shared private key by default
openssh.authorizedKeys.keys = [
"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"
];
};

security.sudo.configFile =
''
zimbatm marked this conversation as resolved.
Show resolved Hide resolved
Defaults:root,%wheel env_keep+=LOCALE_ARCHIVE
Defaults:root,%wheel env_keep+=NIX_PATH
Defaults:root,%wheel env_keep+=TERMINFO_DIRS
Defaults env_keep+=SSH_AUTH_SOCK
Defaults lecture = never
root ALL=(ALL) SETENV: ALL
%wheel ALL=(ALL) NOPASSWD: ALL, SETENV: ALL
'';
}
44 changes: 44 additions & 0 deletions nixos/modules/virtualisation/vagrant-virtualbox-image.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Vagrant + VirtualBox

{ config, pkgs, ... }:

{
imports = [
./vagrant-guest.nix
./virtualbox-image.nix
];

users.extraUsers.vagrant.extraGroups = [ "vboxsf" ];

# generate the box v1 format which is much easier to generate
# https://www.vagrantup.com/docs/boxes/format.html
system.build.vagrantVirtualbox = pkgs.runCommand
"virtualbox-vagrant.box"
{}
''
mkdir workdir
cd workdir

# 1. create that metadata.json file
echo '{"provider":"virtualbox"}' > metadata.json

# 2. create a default Vagrantfile config
cat <<VAGRANTFILE > Vagrantfile
Vagrant.configure("2") do |config|
config.vm.base_mac = "0800275F0936"
end
VAGRANTFILE

# 3. add the exported VM files
tar xvf ${config.system.build.virtualBoxOVA}/*.ova

# 4. move the ovf to the fixed location
mv *.ovf box.ovf

# TODO: fix the checksum file instead of removing it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it computed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked into it, which is why it was easier to remove :)

rm *.mf

# 5. compress everything back together
tar --owner=0 --group=0 --sort=name --numeric-owner -czf $out .
'';
}