Skip to content

Instantly share code, notes, and snippets.

@Xe
Created March 12, 2020 09:35
Show Gist options
  • Save Xe/4a6262ca88dbf3e8d7bea2f68e0d114f to your computer and use it in GitHub Desktop.
Save Xe/4a6262ca88dbf3e8d7bea2f68e0d114f to your computer and use it in GitHub Desktop.
docker-containers example for NixOS/NixOps

NixOps Deployment of a Docker Container

Install NixOps

If using NixOS:

$ nix-env -iA nixos.nixops

If using Nix on another OS:

$ nix-env -iA nixpkgs.nixops

Create the Deployment

$ nixops create ./trivial.nix ./trivial-vbox.nix -d http
$ nixops deploy -d http
$ nixops info -d http

Get the IP address from that last command and:

$ curl http://192.168.56.105

Destroy the Deployment

$ nixops destroy -d http
$ nixops delete -d http
{
webserver =
{ config, pkgs, ... }:
{ deployment.targetEnv = "virtualbox";
deployment.virtualbox.memorySize = 1024; # megabytes
deployment.virtualbox.vcpu = 2; # number of cpus
};
}
{
network.description = "Web server";
webserver = { config, pkgs, ... }: {
docker-containers."nginx" = {
image = "nginx:latest";
environment = {
"FOO" = "bar";
};
ports = [ "80:80" ];
};
networking.firewall.allowedTCPPorts = [ 80 ];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment