Skip to content

Commit

Permalink
Set system to x86_64-linux on non-linux platforms
Browse files Browse the repository at this point in the history
Taken from NixOS#412 to generate a minimal change
as an improvement of the current situation regarding remote building.

Adjusted to use "mkOverride 900" to make it consistent with all other backends.

If building a container on a non-linux system and "nixpkgs.system" is not set,
then we default now to "x86_64-linux".
  • Loading branch information
johbo authored and Olaf Miller committed Jul 24, 2018
1 parent d4e5b77 commit 5a66619
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions nix/container.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ in

boot.isContainer = true;

nixpkgs.system = mkIf (! any (platform: platform == builtins.currentSystem) platforms.linux) (mkOverride 900 "x86_64-linux");
};

}
5 changes: 5 additions & 0 deletions nixops/backends/container.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from nixops.backends import MachineDefinition, MachineState
from nixops.nix_expr import py2nix
import nixops.util
import nixops.ssh_util
import subprocess
Expand Down Expand Up @@ -126,10 +127,14 @@ def create(self, defn, check, allow_reboot, allow_recreate):
if self.vm_id is None:
self.log("building initial configuration...")

eval_args = self.depl._eval_args(self.depl.nix_exprs)
eval_args['checkConfigurationOptions'] = False
expr = " ".join([
'{ imports = [ <nixops/container-base.nix> ];',
' boot.isContainer = true;',
' networking.hostName = "{0}";'.format(self.name),
' nixpkgs.system = let final = import <nixops/eval-machine-info.nix> {0};'.format(py2nix(eval_args, inline=True)),
' in final.resources.machines.{0}.nixpkgs.system;'.format(self.name),
' users.extraUsers.root.openssh.authorizedKeys.keys = [ "{0}" ];'.format(self.client_public_key),
'}'])

Expand Down
22 changes: 16 additions & 6 deletions nixops/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,26 @@ def _nix_path_flags(self):
flags.extend(["-I", "nixops=" + self.expr_path])
return flags

def _eval_args(self, exprs):
args = {key: RawValue(val) for key, val in self.args.iteritems()}
exprs_ = [RawValue(x) if x[0] == '<' else x for x in exprs]
eval_args = {
'networkExprs' : exprs_,
'args' : args,
'uuid' : self.uuid,
'deploymentName' : self.name if self.name else ""
}
return eval_args


def _eval_flags(self, exprs):
flags = self._nix_path_flags()
args = {key: RawValue(val) for key, val in self.args.iteritems()}
exprs_ = [RawValue(x) if x[0] == '<' else x for x in exprs]
args = self._eval_args(exprs)
flags.extend(
["--arg", "networkExprs", py2nix(exprs_, inline=True),
"--arg", "args", py2nix(args, inline=True),
"--argstr", "uuid", self.uuid,
"--argstr", "deploymentName", self.name if self.name else "",
["--arg", "networkExprs", py2nix(args['networkExprs'], inline=True),
"--arg", "args", py2nix(args['args'], inline=True),
"--argstr", "uuid", args['uuid'],
"--argstr", "deploymentName", args['deploymentName'],
"<nixops/eval-machine-info.nix>"])
return flags

Expand Down

0 comments on commit 5a66619

Please sign in to comment.