Loading pkgs/by-name/ni/nixos-container/nixos-container.pl +42 −26 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ Usage: nixos-container list [--port <port>] [--host-address <string>] [--local-address <string>] [--use-host-network] nixos-container destroy <container-name> nixos-container restart <container-name> nixos-container start <container-name> Loading Loading @@ -74,6 +75,7 @@ my $signal; my $configFile; my $hostAddress; my $localAddress; my $useHostNetwork = 0; my $flake; my $flakeAttr = "container"; Loading Loading @@ -106,6 +108,7 @@ GetOptions( "config-file=s" => \$configFile, "host-address=s" => \$hostAddress, "local-address=s" => \$localAddress, "use-host-network" => \$useHostNetwork, "flake=s" => \$flake, # Nix passthru options. "log-format=s" => \©NixFlags1, Loading @@ -127,6 +130,10 @@ if (defined $hostAddress and !defined $localAddress or defined $localAddress and die "With --host-address set, --local-address is required as well!"; } if ($useHostNetwork && (defined $hostAddress || defined $localAddress)) { die "--use-host-network cannot be used with --host-address or --local-address!"; } my $action = $ARGV[0] or die "$0: no action specified\n"; if (defined $configFile and defined $extraConfig) { Loading Loading @@ -231,6 +238,12 @@ if ($action eq "create") { # be restricted too. die "$0: container name ‘$containerName’ is too long\n" if length $containerName > 11; my @conf; if ($useHostNetwork) { push @conf, "PRIVATE_NETWORK=0\n"; print STDERR "using host network\n"; } else { # Get an unused IP address. my %usedIPs; foreach my $confFile2 (glob "$configurationDirectory/*.conf") { Loading @@ -257,10 +270,12 @@ if ($action eq "create") { die "$0: out of IP addresses\n" unless defined $ipPrefix; } my @conf; push @conf, "PRIVATE_NETWORK=1\n"; push @conf, "HOST_ADDRESS=$hostAddress\n"; push @conf, "LOCAL_ADDRESS=$localAddress\n"; print STDERR "host IP is $hostAddress, container IP is $localAddress\n"; } push @conf, "HOST_BRIDGE=$bridge\n"; push @conf, "HOST_PORT=$port\n"; push @conf, "AUTO_START=$autoStart\n"; Loading @@ -269,8 +284,6 @@ if ($action eq "create") { close($lock); print STDERR "host IP is $hostAddress, container IP is $localAddress\n"; # The per-container directory is restricted to prevent users on # the host from messing with guest users who happen to have the # same uid. Loading Loading @@ -517,6 +530,9 @@ elsif ($action eq "run") { elsif ($action eq "show-ip") { my $s = read_file($confFile) or die; if ($s =~ /^PRIVATE_NETWORK=0$/m) { die "$0: container uses host network, no separate IP address\n"; } $s =~ /^LOCAL_ADDRESS=([0-9\.]+)(\/[0-9]+)?$/m or $s =~ /^LOCAL_ADDRESS6=([0-9a-f:]+)(\/[0-9]+)?$/m or die "$0: cannot get IP address\n"; Loading Loading
pkgs/by-name/ni/nixos-container/nixos-container.pl +42 −26 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ Usage: nixos-container list [--port <port>] [--host-address <string>] [--local-address <string>] [--use-host-network] nixos-container destroy <container-name> nixos-container restart <container-name> nixos-container start <container-name> Loading Loading @@ -74,6 +75,7 @@ my $signal; my $configFile; my $hostAddress; my $localAddress; my $useHostNetwork = 0; my $flake; my $flakeAttr = "container"; Loading Loading @@ -106,6 +108,7 @@ GetOptions( "config-file=s" => \$configFile, "host-address=s" => \$hostAddress, "local-address=s" => \$localAddress, "use-host-network" => \$useHostNetwork, "flake=s" => \$flake, # Nix passthru options. "log-format=s" => \©NixFlags1, Loading @@ -127,6 +130,10 @@ if (defined $hostAddress and !defined $localAddress or defined $localAddress and die "With --host-address set, --local-address is required as well!"; } if ($useHostNetwork && (defined $hostAddress || defined $localAddress)) { die "--use-host-network cannot be used with --host-address or --local-address!"; } my $action = $ARGV[0] or die "$0: no action specified\n"; if (defined $configFile and defined $extraConfig) { Loading Loading @@ -231,6 +238,12 @@ if ($action eq "create") { # be restricted too. die "$0: container name ‘$containerName’ is too long\n" if length $containerName > 11; my @conf; if ($useHostNetwork) { push @conf, "PRIVATE_NETWORK=0\n"; print STDERR "using host network\n"; } else { # Get an unused IP address. my %usedIPs; foreach my $confFile2 (glob "$configurationDirectory/*.conf") { Loading @@ -257,10 +270,12 @@ if ($action eq "create") { die "$0: out of IP addresses\n" unless defined $ipPrefix; } my @conf; push @conf, "PRIVATE_NETWORK=1\n"; push @conf, "HOST_ADDRESS=$hostAddress\n"; push @conf, "LOCAL_ADDRESS=$localAddress\n"; print STDERR "host IP is $hostAddress, container IP is $localAddress\n"; } push @conf, "HOST_BRIDGE=$bridge\n"; push @conf, "HOST_PORT=$port\n"; push @conf, "AUTO_START=$autoStart\n"; Loading @@ -269,8 +284,6 @@ if ($action eq "create") { close($lock); print STDERR "host IP is $hostAddress, container IP is $localAddress\n"; # The per-container directory is restricted to prevent users on # the host from messing with guest users who happen to have the # same uid. Loading Loading @@ -517,6 +530,9 @@ elsif ($action eq "run") { elsif ($action eq "show-ip") { my $s = read_file($confFile) or die; if ($s =~ /^PRIVATE_NETWORK=0$/m) { die "$0: container uses host network, no separate IP address\n"; } $s =~ /^LOCAL_ADDRESS=([0-9\.]+)(\/[0-9]+)?$/m or $s =~ /^LOCAL_ADDRESS6=([0-9a-f:]+)(\/[0-9]+)?$/m or die "$0: cannot get IP address\n"; Loading