Skip to content

Instantly share code, notes, and snippets.

@monadplus
Last active February 4, 2020 18:47
Show Gist options
  • Save monadplus/759eedc03288c52aea00c2506ffa67e5 to your computer and use it in GitHub Desktop.
Save monadplus/759eedc03288c52aea00c2506ffa67e5 to your computer and use it in GitHub Desktop.
NixOps: where is it compiling the derivation ? Remote Builds

NixOps Compilation

If the machine running nixOps is linux, it will build it locally, but also obey any build machines configured in /etc/nix/machines.

If nixops is being ran on darwin/windows, it cant build linux things, so it will try to configure the remote machine as a build machine, automatically.

There is a workaround for this if you don't won't to compile on your sever (for example, if the instances is too small it will fail): set a remote build machine over ssh.

To set up a remote build read these links:

  1. Go to the AWS Console and generate a pem OpenSSH keyPair.

  2. Add your ssh remote host $ vim ~/.ssh/config:

Host test
     HostName 54.154.60.196
     User root
     IdentitiesOnly yes
     IdentityFile ~/path/to/test.pem
  1. Test you can ping your remote builder:
$ nix ping-store --store ssh://test
  1. Build a remote derivation:
# this should produce a ./result -> /nix/store/<hash>foo with "linux" as content
$ nix build '(with import <nixpkgs> { system = "i686-linux"; }; runCommand "foo" {} "uname > $out")' --builders 'ssh://test i686-linux'
  1. Add the following to your physical.nix:
keyPair = "test";
privateKey = "/path/to/test.pem";
  1. Add the following to your /etc/nixos/configuration.nix:
  # Remote builds
	nix.buildMachines = [ {
	 hostName = "test";
   sshUser = "root";
   sshKey = "/home/arnau/Downloads/test.pem";
	 system = "x86_64-linux";
	 maxJobs = 1;
	 speedFactor = 2;
	 supportedFeatures = [ "kvm" ];
	 mandatoryFeatures = [ ];
	}] ;

	nix.distributedBuilds = true;
	nix.extraOptions = ''
		builders-use-substitutes = true
	'';
  1. Now, your builds should be able to build remotely.

You can test it:

nix build -j0 '(with import <nixpkgs> { system = "x86_64-linux"; }; runCommand "xxx" {} "pwd > $out")'

# WRONG <- I am missing something...
cannot build on 'ssh://root@test': cannot connect to 'root@test': ssh: Could not resolve hostname test: Name or service not known
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment