* Remove nixos-deploy-network. It has been superceded by Charon.
svn path=/nixos/trunk/; revision=33662
This commit is contained in:
parent
6e7859814c
commit
301c4d96b1
@ -1,112 +0,0 @@
|
|||||||
<refentry xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
|
||||||
|
|
||||||
<refmeta>
|
|
||||||
<refentrytitle><command>nixos-deploy-network</command></refentrytitle>
|
|
||||||
<manvolnum>8</manvolnum>
|
|
||||||
<refmiscinfo class="source">NixOS</refmiscinfo>
|
|
||||||
<!-- <refmiscinfo class="version"><xi:include href="version.txt" parse="text"/></refmiscinfo> -->
|
|
||||||
</refmeta>
|
|
||||||
|
|
||||||
<refnamediv>
|
|
||||||
<refname><command>nixos-deploy-network</command></refname>
|
|
||||||
<refpurpose>deploy a network of NixOS configurations into a network of machines</refpurpose>
|
|
||||||
</refnamediv>
|
|
||||||
|
|
||||||
<refsynopsisdiv>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nixos-deploy-network</command>
|
|
||||||
<arg><option>--show-trace</option></arg>
|
|
||||||
<arg><option>--no-out-link</option></arg>
|
|
||||||
<arg><option>--help</option></arg>
|
|
||||||
<arg choice="plain"><replaceable>network.nix</replaceable></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsynopsisdiv>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>This command automatically deploys a network of NixOS
|
|
||||||
configurations into a network of machines.
|
|
||||||
First, it tries to build all the system derivations defined
|
|
||||||
in the network expression. Then it efficiently transfers
|
|
||||||
the closures to the machines in the network. Finally, the configurations
|
|
||||||
are activated. In case of a failure, a rollback is performed,
|
|
||||||
which brings all the updated configurations back into the previous
|
|
||||||
state.</para>
|
|
||||||
|
|
||||||
<para>A network Nix expression has the following structure:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
{
|
|
||||||
test1 = {pkgs, config, ...}:
|
|
||||||
{
|
|
||||||
services.openssh.enable = true;
|
|
||||||
nixpkgs.system = "i686-linux";
|
|
||||||
deployment.targetHost = "test1.example.net";
|
|
||||||
|
|
||||||
# Other NixOS options
|
|
||||||
};
|
|
||||||
|
|
||||||
test2 = {pkgs, config, ...}:
|
|
||||||
{
|
|
||||||
services.openssh.enable = true;
|
|
||||||
services.httpd.enable = true;
|
|
||||||
environment.systemPackages = [ pkgs.lynx ];
|
|
||||||
nixpkgs.system = "x86_64-linux";
|
|
||||||
deployment.targetHost = "test2.example.net";
|
|
||||||
|
|
||||||
# Other NixOS options
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
Each attribute in the expression represents a machine in the network
|
|
||||||
(e.g. <varname>test1</varname> and <varname>test2</varname>)
|
|
||||||
referring to a function defining a NixOS configuration.
|
|
||||||
In each NixOS configuration, two attributes have a special meaning.
|
|
||||||
The <varname>deployment.targetHost</varname> specifies the address
|
|
||||||
(domain name or IP address)
|
|
||||||
of the system which is used by <command>ssh</command> to perform
|
|
||||||
remote deployment operations. The <varname>nixpkgs.system</varname>
|
|
||||||
attribute can be used to specify an architecture for the target machine,
|
|
||||||
such as <varname>i686-linux</varname> which builds a 32-bit NixOS
|
|
||||||
configuration. Omitting this property will build the configuration
|
|
||||||
for the same architecture as the host system.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Options</title>
|
|
||||||
|
|
||||||
<para>This command accepts the following options:</para>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry>
|
|
||||||
<term><option>--show-trace</option></term>
|
|
||||||
<listitem>
|
|
||||||
<para>Shows a trace of the output.</para>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry>
|
|
||||||
<term><option>--no-out-link</option></term>
|
|
||||||
<listitem>
|
|
||||||
<para>Do not create a 'result' symlink.</para>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry>
|
|
||||||
<term><option>-h</option>, <option>--help</option></term>
|
|
||||||
<listitem>
|
|
||||||
<para>Shows the usage of this command to the user.</para>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
</refentry>
|
|
@ -26,6 +26,6 @@
|
|||||||
<xi:include href="man-configuration.xml" />
|
<xi:include href="man-configuration.xml" />
|
||||||
<xi:include href="man-nixos-rebuild.xml" />
|
<xi:include href="man-nixos-rebuild.xml" />
|
||||||
<xi:include href="man-nixos-option.xml" />
|
<xi:include href="man-nixos-option.xml" />
|
||||||
<xi:include href="man-nixos-deploy-network.xml" />
|
|
||||||
<xi:include href="man-nixos-build-vms.xml" />
|
<xi:include href="man-nixos-build-vms.xml" />
|
||||||
|
|
||||||
</reference>
|
</reference>
|
||||||
|
@ -1,121 +0,0 @@
|
|||||||
{ nixos ? /etc/nixos/nixos
|
|
||||||
, nixpkgs ? /etc/nixos/nixpkgs
|
|
||||||
, networkExprs
|
|
||||||
, targetProperty ? "targetHost"
|
|
||||||
}:
|
|
||||||
|
|
||||||
let
|
|
||||||
pkgs = import nixpkgs {};
|
|
||||||
|
|
||||||
inherit (builtins) attrNames getAttr listToAttrs;
|
|
||||||
inherit (pkgs.lib) concatMapStrings zipAttrs;
|
|
||||||
|
|
||||||
networks = map (networkExpr: import networkExpr) networkExprs;
|
|
||||||
|
|
||||||
network = zipAttrs networks;
|
|
||||||
|
|
||||||
generateRollbackSucceededPhase = network: configs:
|
|
||||||
concatMapStrings (configurationName:
|
|
||||||
let
|
|
||||||
config = getAttr configurationName configs;
|
|
||||||
in
|
|
||||||
''
|
|
||||||
if [ "$rollback" != "$succeeded" ]
|
|
||||||
then
|
|
||||||
ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} nix-env -p /nix/var/nix/profiles/system --rollback
|
|
||||||
ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} /nix/var/nix/profiles/system/bin/switch-to-configuration switch
|
|
||||||
|
|
||||||
rollback=$((rollback + 1))
|
|
||||||
fi
|
|
||||||
''
|
|
||||||
) (attrNames network)
|
|
||||||
;
|
|
||||||
|
|
||||||
generateDistributionPhase = network: configs:
|
|
||||||
concatMapStrings (configurationName:
|
|
||||||
let
|
|
||||||
config = getAttr configurationName configs;
|
|
||||||
in
|
|
||||||
''
|
|
||||||
echo "=== copy system closure to ${getAttr targetProperty (config.deployment)} ==="
|
|
||||||
nix-copy-closure --to ${getAttr targetProperty (config.deployment)} ${config.system.build.toplevel}
|
|
||||||
''
|
|
||||||
) (attrNames network)
|
|
||||||
;
|
|
||||||
|
|
||||||
generateActivationPhase = network: configs:
|
|
||||||
concatMapStrings (configurationName:
|
|
||||||
let
|
|
||||||
config = getAttr configurationName configs;
|
|
||||||
in
|
|
||||||
''
|
|
||||||
echo "=== activating system configuration on ${getAttr targetProperty (config.deployment)} ==="
|
|
||||||
ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} nix-env -p /nix/var/nix/profiles/system --set ${config.system.build.toplevel} ||
|
|
||||||
(ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} nix-env -p /nix/var/nix/profiles/system --rollback; rollbackSucceeded)
|
|
||||||
|
|
||||||
ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} /nix/var/nix/profiles/system/bin/switch-to-configuration switch ||
|
|
||||||
( ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} nix-env -p /nix/var/nix/profiles/system --rollback
|
|
||||||
ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} /nix/var/nix/profiles/system/bin/switch-to-configuration switch
|
|
||||||
rollbackSucceeded
|
|
||||||
)
|
|
||||||
|
|
||||||
succeeded=$((succeeded + 1))
|
|
||||||
''
|
|
||||||
) (attrNames network)
|
|
||||||
;
|
|
||||||
|
|
||||||
evaluateMachines = network:
|
|
||||||
listToAttrs (map (configurationName:
|
|
||||||
let
|
|
||||||
modules = getAttr configurationName network;
|
|
||||||
in
|
|
||||||
{ name = configurationName;
|
|
||||||
value = (import "${nixos}/lib/eval-config.nix" {
|
|
||||||
inherit nixpkgs;
|
|
||||||
modules =
|
|
||||||
modules ++
|
|
||||||
[ # Provide a default hostname and deployment target equal
|
|
||||||
# to the attribute name of the machine in the model.
|
|
||||||
{ key = "set-default-hostname";
|
|
||||||
networking.hostName = pkgs.lib.mkOverride 900 configurationName;
|
|
||||||
deployment.targetHost = pkgs.lib.mkOverride 900 configurationName;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
extraArgs = { nodes = evaluateMachines network; };
|
|
||||||
}).config; }
|
|
||||||
) (attrNames (network)));
|
|
||||||
|
|
||||||
configs = evaluateMachines network;
|
|
||||||
in
|
|
||||||
pkgs.stdenv.mkDerivation {
|
|
||||||
name = "deploy-script";
|
|
||||||
|
|
||||||
# This script has a zillion dependencies and is trivial to build, so
|
|
||||||
# we don't want to build it remotely.
|
|
||||||
preferLocalBuild = true;
|
|
||||||
|
|
||||||
buildCommand =
|
|
||||||
''
|
|
||||||
ensureDir $out/bin
|
|
||||||
cat > $out/bin/deploy-systems << "EOF"
|
|
||||||
#! ${pkgs.stdenv.shell} -e
|
|
||||||
|
|
||||||
rollbackSucceeded()
|
|
||||||
{
|
|
||||||
rollback=0
|
|
||||||
${generateRollbackSucceededPhase network configs}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Distribution phase
|
|
||||||
|
|
||||||
${generateDistributionPhase network configs}
|
|
||||||
|
|
||||||
# Activation phase
|
|
||||||
|
|
||||||
succeeded=0
|
|
||||||
|
|
||||||
${generateActivationPhase network configs}
|
|
||||||
EOF
|
|
||||||
chmod +x $out/bin/deploy-systems
|
|
||||||
'';
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
#! @shell@ -e
|
|
||||||
|
|
||||||
# Shows the usage of this command to the user
|
|
||||||
|
|
||||||
showUsage()
|
|
||||||
{
|
|
||||||
echo "Usage: $0 network_expr [network_expr2 ...]"
|
|
||||||
echo "Options:"
|
|
||||||
echo
|
|
||||||
echo "--show-trace Shows an output trace"
|
|
||||||
echo "--no-out-link Do not create a 'result' symlink"
|
|
||||||
echo "-h,--help Shows the usage of this command"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Parse valid argument options
|
|
||||||
|
|
||||||
PARAMS=`getopt -n $0 -o h -l show-trace,no-out-link,help -- "$@"`
|
|
||||||
|
|
||||||
if [ $? != 0 ]
|
|
||||||
then
|
|
||||||
showUsage
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
eval set -- "$PARAMS"
|
|
||||||
|
|
||||||
# Evaluate valid options
|
|
||||||
|
|
||||||
while [ "$1" != "--" ]
|
|
||||||
do
|
|
||||||
case "$1" in
|
|
||||||
--show-trace)
|
|
||||||
showTraceArg="--show-trace"
|
|
||||||
;;
|
|
||||||
--no-out-link)
|
|
||||||
noOutLinkArg="--no-out-link"
|
|
||||||
;;
|
|
||||||
-h|--help)
|
|
||||||
showUsage
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
shift
|
|
||||||
|
|
||||||
# Validate the given options
|
|
||||||
|
|
||||||
if [ -z "$NIXOS" ]
|
|
||||||
then
|
|
||||||
NIXOS=/etc/nixos/nixos
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$@" = "" ]
|
|
||||||
then
|
|
||||||
echo "ERROR: At least one network Nix expression must be specified!" >&2
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
for i in $@
|
|
||||||
do
|
|
||||||
networkExprs="$networkExprs \"$(readlink -f $i)\""
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Deploy the network
|
|
||||||
|
|
||||||
vms=`nix-build $NIXOS/modules/installer/tools/nixos-deploy-network/deploy.nix --arg networkExprs "[ $networkExprs ]" --argstr nixos $NIXOS $showTraceArg $noOutLinkArg`
|
|
||||||
$vms/bin/deploy-systems
|
|
@ -17,11 +17,6 @@ let
|
|||||||
src = ./nixos-build-vms/nixos-build-vms.sh;
|
src = ./nixos-build-vms/nixos-build-vms.sh;
|
||||||
};
|
};
|
||||||
|
|
||||||
nixosDeployNetwork = makeProg {
|
|
||||||
name = "nixos-deploy-network";
|
|
||||||
src = ./nixos-deploy-network/nixos-deploy-network.sh;
|
|
||||||
};
|
|
||||||
|
|
||||||
nixosInstall = makeProg {
|
nixosInstall = makeProg {
|
||||||
name = "nixos-install";
|
name = "nixos-install";
|
||||||
src = ./nixos-install.sh;
|
src = ./nixos-install.sh;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user