diff options
-rw-r--r-- | nixos/doc/manual/man-nixos-rebuild.xml | 25 | ||||
-rw-r--r-- | nixos/modules/installer/tools/nixos-rebuild.sh | 32 | ||||
-rwxr-xr-x | pkgs/tools/virtualization/nixos-container/nixos-container.pl | 8 |
3 files changed, 27 insertions, 38 deletions
diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml index 4341b8918df..f4f663b84f0 100644 --- a/nixos/doc/manual/man-nixos-rebuild.xml +++ b/nixos/doc/manual/man-nixos-rebuild.xml @@ -83,10 +83,6 @@ <option>--flake</option> <replaceable>flake-uri</replaceable> </arg> - <arg> - <option>--config</option> <replaceable>name</replaceable> - </arg> - <sbr /> <arg> @@ -525,7 +521,7 @@ <varlistentry> <term> - <option>--flake</option> <replaceable>flake-uri</replaceable> + <option>--flake</option> <replaceable>flake-uri</replaceable>[<replaceable>name</replaceable>] </term> <listitem> <para> @@ -533,22 +529,9 @@ the directory containing the target of the symlink <filename>/etc/nixos/flake.nix</filename>, if it exists. The flake must contain an output named - <literal>nixosConfigurations.<replaceable>name</replaceable></literal>, - where <replaceable>name</replaceable> denotes the name of the - configuration and can be specified using the - <option>--config</option> option. - </para> - </listitem> - </varlistentry> - - <varlistentry> - <term> - <option>--config</option> <replaceable>name</replaceable> - </term> - <listitem> - <para> - Specifies which NixOS configuration to use from the - flake. Defaults to the current hostname. + <literal>nixosConfigurations.<replaceable>name</replaceable></literal>. If + <replaceable>name</replaceable> is omitted, it default to the + current host name. </para> </listitem> </varlistentry> diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh index 18088e4f9ea..b681a170b6b 100644 --- a/nixos/modules/installer/tools/nixos-rebuild.sh +++ b/nixos/modules/installer/tools/nixos-rebuild.sh @@ -100,10 +100,6 @@ while [ "$#" -gt 0 ]; do flake="$1" shift 1 ;; - --config) - flakeAttr="nixosConfigurations.$1" - shift 1 - ;; *) echo "$0: unknown option \`$i'" exit 1 @@ -254,12 +250,20 @@ fi # For convenience, use the hostname as the default configuration to # build from the flake. -if [[ -n $flake && -z $flakeAttr ]]; then - hostname=$(cat /proc/sys/kernel/hostname) - if [[ -z $hostname ]]; then - hostname=default +if [[ -n $flake ]]; then + if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then + flake="${BASH_REMATCH[1]}" + flakeAttr="${BASH_REMATCH[2]}" + fi + if [[ -z $flakeAttr ]]; then + hostname=$(cat /proc/sys/kernel/hostname) + if [[ -z $hostname ]]; then + hostname=default + fi + flakeAttr="nixosConfigurations.\"$hostname\"" + else + flakeAttr="nixosConfigurations.\"$flakeAttr\"" fi - flakeAttr="nixosConfigurations.\"$hostname\"" fi # Resolve the flake. @@ -391,17 +395,13 @@ fi # or "boot"), or just build it and create a symlink "result" in the # current directory (for "build" and "test"). if [ -z "$rollback" ]; then - if [[ -z $flake ]]; then - echo "building the system configuration..." >&2 - else - echo "building the system configuration '$flake:$flakeAttr'..." >&2 - fi + echo "building the system configuration..." >&2 if [ "$action" = switch -o "$action" = boot ]; then if [[ -z $flake ]]; then pathToConfig="$(nixBuild '<nixpkgs/nixos>' --no-out-link -A system "${extraBuildFlags[@]}")" else outLink=$tmpDir/result - nix build "$flake:$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" --out-link $outLink + nix build "$flake#$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" --out-link $outLink pathToConfig="$(readlink -f $outLink)" fi copyToTarget "$pathToConfig" @@ -410,7 +410,7 @@ if [ -z "$rollback" ]; then if [[ -z $flake ]]; then pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A system -k "${extraBuildFlags[@]}")" else - nix build "$flake:$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" + nix build "$flake#$flakeAttr.config.system.build.toplevel" --keep-going "${extraBuildFlags[@]}" pathToConfig="$(readlink -f ./result)" fi elif [ "$action" = build-vm ]; then diff --git a/pkgs/tools/virtualization/nixos-container/nixos-container.pl b/pkgs/tools/virtualization/nixos-container/nixos-container.pl index 392d59486c1..727c0333b27 100755 --- a/pkgs/tools/virtualization/nixos-container/nixos-container.pl +++ b/pkgs/tools/virtualization/nixos-container/nixos-container.pl @@ -64,6 +64,7 @@ my $configFile; my $hostAddress; my $localAddress; my $flake; +my $flakeAttr = "container"; GetOptions( "help" => sub { showHelp() }, @@ -92,6 +93,11 @@ if (defined $configFile and defined $extraConfig) { "Please define on or the other, but not both"; } +if (defined $flake && $flake =~ /^(.*)#([^#"]+)$/) { + $flake = $1; + $flakeAttr = $2; +} + # Execute the selected action. mkpath("/etc/containers", 0, 0755); @@ -137,7 +143,7 @@ EOF sub buildFlake { system("nix", "build", "-o", "$systemPath.tmp", "--", - "$flake:nixosConfigurations.container.config.system.build.toplevel") == 0 + "$flake#nixosConfigurations.\"$flakeAttr\".config.system.build.toplevel") == 0 or die "$0: failed to build container from flake '$flake'\n"; $systemPath = readlink("$systemPath.tmp") or die; unlink("$systemPath.tmp"); |