nixos-container --create: Add option --system-path
This allows creating a container from an existing system store path, which is especially nice for NixOps-deployed hosts because they don't need a Nixpkgs tree anymore.
This commit is contained in:
parent
f932910323
commit
ddd8f0cf66
@ -17,7 +17,7 @@ umask 0022;
|
|||||||
sub showHelp {
|
sub showHelp {
|
||||||
print <<EOF;
|
print <<EOF;
|
||||||
Usage: nixos-container list
|
Usage: nixos-container list
|
||||||
nixos-container create <container-name> [--config <string>] [--ensure-unique-name] [--auto-start]
|
nixos-container create <container-name> [--system-path <path>] [--config <string>] [--ensure-unique-name] [--auto-start]
|
||||||
nixos-container destroy <container-name>
|
nixos-container destroy <container-name>
|
||||||
nixos-container start <container-name>
|
nixos-container start <container-name>
|
||||||
nixos-container stop <container-name>
|
nixos-container stop <container-name>
|
||||||
@ -31,6 +31,7 @@ EOF
|
|||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $systemPath;
|
||||||
my $ensureUniqueName = 0;
|
my $ensureUniqueName = 0;
|
||||||
my $autoStart = 0;
|
my $autoStart = 0;
|
||||||
my $extraConfig;
|
my $extraConfig;
|
||||||
@ -39,6 +40,7 @@ GetOptions(
|
|||||||
"help" => sub { showHelp() },
|
"help" => sub { showHelp() },
|
||||||
"ensure-unique-name" => \$ensureUniqueName,
|
"ensure-unique-name" => \$ensureUniqueName,
|
||||||
"auto-start" => \$autoStart,
|
"auto-start" => \$autoStart,
|
||||||
|
"system-path=s" => \$systemPath,
|
||||||
"config=s" => \$extraConfig
|
"config=s" => \$extraConfig
|
||||||
) or exit 1;
|
) or exit 1;
|
||||||
|
|
||||||
@ -132,11 +134,6 @@ if ($action eq "create") {
|
|||||||
|
|
||||||
print STDERR "host IP is $hostAddress, container IP is $localAddress\n";
|
print STDERR "host IP is $hostAddress, container IP is $localAddress\n";
|
||||||
|
|
||||||
mkpath("$root/etc/nixos", 0, 0755);
|
|
||||||
|
|
||||||
my $nixosConfigFile = "$root/etc/nixos/configuration.nix";
|
|
||||||
writeNixOSConfig $nixosConfigFile;
|
|
||||||
|
|
||||||
# The per-container directory is restricted to prevent users on
|
# The per-container directory is restricted to prevent users on
|
||||||
# the host from messing with guest users who happen to have the
|
# the host from messing with guest users who happen to have the
|
||||||
# same uid.
|
# same uid.
|
||||||
@ -145,10 +142,21 @@ if ($action eq "create") {
|
|||||||
$profileDir = "$profileDir/$containerName";
|
$profileDir = "$profileDir/$containerName";
|
||||||
mkpath($profileDir, 0, 0755);
|
mkpath($profileDir, 0, 0755);
|
||||||
|
|
||||||
system("nix-env", "-p", "$profileDir/system",
|
# Build/set the initial configuration.
|
||||||
"-I", "nixos-config=$nixosConfigFile", "-f", "<nixpkgs/nixos>",
|
if (defined $systemPath) {
|
||||||
"--set", "-A", "system") == 0
|
system("nix-env", "-p", "$profileDir/system", "--set", $systemPath) == 0
|
||||||
or die "$0: failed to build initial container configuration\n";
|
or die "$0: failed to set initial container configuration\n";
|
||||||
|
} else {
|
||||||
|
mkpath("$root/etc/nixos", 0, 0755);
|
||||||
|
|
||||||
|
my $nixosConfigFile = "$root/etc/nixos/configuration.nix";
|
||||||
|
writeNixOSConfig $nixosConfigFile;
|
||||||
|
|
||||||
|
system("nix-env", "-p", "$profileDir/system",
|
||||||
|
"-I", "nixos-config=$nixosConfigFile", "-f", "<nixpkgs/nixos>",
|
||||||
|
"--set", "-A", "system") == 0
|
||||||
|
or die "$0: failed to build initial container configuration\n";
|
||||||
|
}
|
||||||
|
|
||||||
print "$containerName\n" if $ensureUniqueName;
|
print "$containerName\n" if $ensureUniqueName;
|
||||||
exit 0;
|
exit 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user