GithubHelp home page GithubHelp logo

nixos-openvz's Introduction

NixOS on OpenVZ 7

Configurations needed to run NixOS on OpenVZ 7 VPSes created with the Debian/Ubuntu template.

This repo is only useful if you are an end-user without access to the host and it's unreasonable to request configuration changes on the host. If you are the provider, please create a new distribution config that does not attempt to manipulate the guest configurations.

Usage

Create a configuration.nix:

{
  networking.useNetworkd = true;

  systemd.network.networks.venet0 = {
    name = "venet0";
    # Change to your assigned IP
    address = [ "10.10.10.123/32" ];
    networkConfig = {
      DHCP = "no";
      DefaultRouteOnDevice = "yes";
      ConfigureWithoutCarrier = "yes";
    };
  };

  services.openssh.enable = true;

  users.users.root.openssh.authorizedKeys.keyFiles = [
    # ...
  ];
}

Next, build the tarball that contains the bootstrap configuration:

nix-build generate-openvz-tarball.nix --arg configuration ./configuration.nix

Upload the tarball to the VPS, then extract it onto the root filesystem:

tar xpf nixos-system-x86_64-linux.tar.xz -C /
reboot -f

The VPS will reboot into NixOS, with existing files in the root filesystem moved into /old-root. You can delete the directory to save space. When rebuilding, include ./nixos.nix in your NixOS configuration.

Tested Providers

FAQ

Why is this needed?

With most out-of-box templates, OpenVZ automatically runs a set of bash scripts in the guest container prior to every boot to customize the system (setting hostname, IP addresses, etc.). We can't run them in NixOS, but the scripts have to be successfully executed for the container to boot :(

Here we silently ignore the scripts with an ugly hack, which is a /bin/bash wrapper that refuses to do anything if PID 1 is vzctl. Note that vzctl enter as well as the "Serial Console" feature in SolusVM also hard-depend on /bin/bash.

Will this work on OpenVZ 6?

No, because the kernel is too old to start systemd. Please do not buy such VPSes no matter how cheap they may be.

nixos-openvz's People

Contributors

xddxdd avatar zhaofengli avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.