nix-community / nixops-vbox

NixOps VirtualBox backend [maintainer=@AmineChikhaoui]
GNU Lesser General Public License v3.0
22 stars 15 forks source link

Solve outdated virtualbox image issue #1

Open DavHau opened 4 years ago

DavHau commented 4 years ago

Motivation

It seems to be a recurring issue since years that the included vbox images for the stable version of NixOps are outdated. This is especially bad for people (like me) who are just starting to dive into the NixOS / NixOps topic. The NixOps Manual provides the virtualbox backend as first example but it will crash when you are on stable versions for NixOS and NixOps. As a result, my first experience with NixOps was reading through the pull requests for hours and figuring out that i need to generate my own base image somehow. I would like to work on a solution to fix that permanently.

Current Situation

My understanding of the situation is as follows (please correct me if I'm wrong): In general there wouldn't be a problem with building the base image locally, but rebuilding the image on every channel update is costly.

The current solution to prevent constant rebuilding is to fetch the base image from an online source that isn't updated often, resulting in high initial update times inside the VM or even crashes because of incompatibility.

Another Proposed Solution

https://github.com/NixOS/nixops/issues/511 proposes to solve the problem by moving the image building to nixpkgs where it will be updated more frequently. That sounds interesting. How can i help to achieve this?

My Proposal

At the same time I don't understand why it's necessary to fetch these images from the internet at all. Currently I'm using the following derivation which takes as inputs the nixpkgs branch + revision and produces the vbox image. Through this, the base image will only be rebuilt when i update the branch/revision manually, but not everytime i update my nixpkgs channel. Would it make sense to include something like that as the default (or as an option) into the project?

{ pkgs ? import <nixpkgs> {},
  nixpkgs_branch ? "nixos-19.09",
  nixpkgs_rev ? "274e095f761b2da76a376d105c41591739350b14"
}:

let
  nixpkgs_vbox_src = builtins.fetchGit {
    url="https://github.com/NixOS/nixpkgs";
    rev=nixpkgs_rev;
    ref=nixpkgs_branch;
  };
  machine = import "${nixpkgs_vbox_src}/nixos" {
    system = "x86_64-linux";
    configuration = import "${pkgs.nixops}/share/nix/nixops/virtualbox-image-nixops.nix";
  };
  ova = machine.config.system.build.virtualBoxOVA;

in
pkgs.runCommand 
  "virtualbox-nixops-image-${machine.config.system.nixos.version}"
  { nativeBuildInputs = [ ova ]; }
  ''
    mkdir ova
    tar -xf ${ova}/*.ova -C ova
    mv ova/nixos*.vmdk $out
  ''