nixos-{rebuild,container}: Use flakeref#attrpath syntax
This makes them consistent with the 'nix' command line.
This commit is contained in:
parent
20087bd553
commit
fb051f0dec
@ -83,10 +83,6 @@
|
|||||||
<option>--flake</option> <replaceable>flake-uri</replaceable>
|
<option>--flake</option> <replaceable>flake-uri</replaceable>
|
||||||
</arg>
|
</arg>
|
||||||
|
|
||||||
<arg>
|
|
||||||
<option>--config</option> <replaceable>name</replaceable>
|
|
||||||
</arg>
|
|
||||||
|
|
||||||
<sbr />
|
<sbr />
|
||||||
|
|
||||||
<arg>
|
<arg>
|
||||||
@ -525,7 +521,7 @@
|
|||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>
|
<term>
|
||||||
<option>--flake</option> <replaceable>flake-uri</replaceable>
|
<option>--flake</option> <replaceable>flake-uri</replaceable>[<replaceable>name</replaceable>]
|
||||||
</term>
|
</term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
@ -533,22 +529,9 @@
|
|||||||
the directory containing the target of the symlink
|
the directory containing the target of the symlink
|
||||||
<filename>/etc/nixos/flake.nix</filename>, if it exists. The
|
<filename>/etc/nixos/flake.nix</filename>, if it exists. The
|
||||||
flake must contain an output named
|
flake must contain an output named
|
||||||
<literal>nixosConfigurations.<replaceable>name</replaceable></literal>,
|
<literal>nixosConfigurations.<replaceable>name</replaceable></literal>. If
|
||||||
where <replaceable>name</replaceable> denotes the name of the
|
<replaceable>name</replaceable> is omitted, it default to the
|
||||||
configuration and can be specified using the
|
current host name.
|
||||||
<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.
|
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -100,10 +100,6 @@ while [ "$#" -gt 0 ]; do
|
|||||||
flake="$1"
|
flake="$1"
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
--config)
|
|
||||||
flakeAttr="nixosConfigurations.$1"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
echo "$0: unknown option \`$i'"
|
echo "$0: unknown option \`$i'"
|
||||||
exit 1
|
exit 1
|
||||||
@ -254,12 +250,20 @@ fi
|
|||||||
|
|
||||||
# For convenience, use the hostname as the default configuration to
|
# For convenience, use the hostname as the default configuration to
|
||||||
# build from the flake.
|
# build from the flake.
|
||||||
if [[ -n $flake && -z $flakeAttr ]]; then
|
if [[ -n $flake ]]; then
|
||||||
hostname=$(cat /proc/sys/kernel/hostname)
|
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
|
||||||
if [[ -z $hostname ]]; then
|
flake="${BASH_REMATCH[1]}"
|
||||||
hostname=default
|
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
|
fi
|
||||||
flakeAttr="nixosConfigurations.\"$hostname\""
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Resolve the flake.
|
# Resolve the flake.
|
||||||
@ -391,17 +395,13 @@ fi
|
|||||||
# or "boot"), or just build it and create a symlink "result" in the
|
# or "boot"), or just build it and create a symlink "result" in the
|
||||||
# current directory (for "build" and "test").
|
# current directory (for "build" and "test").
|
||||||
if [ -z "$rollback" ]; then
|
if [ -z "$rollback" ]; then
|
||||||
if [[ -z $flake ]]; then
|
echo "building the system configuration..." >&2
|
||||||
echo "building the system configuration..." >&2
|
|
||||||
else
|
|
||||||
echo "building the system configuration '$flake:$flakeAttr'..." >&2
|
|
||||||
fi
|
|
||||||
if [ "$action" = switch -o "$action" = boot ]; then
|
if [ "$action" = switch -o "$action" = boot ]; then
|
||||||
if [[ -z $flake ]]; then
|
if [[ -z $flake ]]; then
|
||||||
pathToConfig="$(nixBuild '<nixpkgs/nixos>' --no-out-link -A system "${extraBuildFlags[@]}")"
|
pathToConfig="$(nixBuild '<nixpkgs/nixos>' --no-out-link -A system "${extraBuildFlags[@]}")"
|
||||||
else
|
else
|
||||||
outLink=$tmpDir/result
|
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)"
|
pathToConfig="$(readlink -f $outLink)"
|
||||||
fi
|
fi
|
||||||
copyToTarget "$pathToConfig"
|
copyToTarget "$pathToConfig"
|
||||||
@ -410,7 +410,7 @@ if [ -z "$rollback" ]; then
|
|||||||
if [[ -z $flake ]]; then
|
if [[ -z $flake ]]; then
|
||||||
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A system -k "${extraBuildFlags[@]}")"
|
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A system -k "${extraBuildFlags[@]}")"
|
||||||
else
|
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)"
|
pathToConfig="$(readlink -f ./result)"
|
||||||
fi
|
fi
|
||||||
elif [ "$action" = build-vm ]; then
|
elif [ "$action" = build-vm ]; then
|
||||||
|
@ -64,6 +64,7 @@ my $configFile;
|
|||||||
my $hostAddress;
|
my $hostAddress;
|
||||||
my $localAddress;
|
my $localAddress;
|
||||||
my $flake;
|
my $flake;
|
||||||
|
my $flakeAttr = "container";
|
||||||
|
|
||||||
GetOptions(
|
GetOptions(
|
||||||
"help" => sub { showHelp() },
|
"help" => sub { showHelp() },
|
||||||
@ -92,6 +93,11 @@ if (defined $configFile and defined $extraConfig) {
|
|||||||
"Please define on or the other, but not both";
|
"Please define on or the other, but not both";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (defined $flake && $flake =~ /^(.*)#([^#"]+)$/) {
|
||||||
|
$flake = $1;
|
||||||
|
$flakeAttr = $2;
|
||||||
|
}
|
||||||
|
|
||||||
# Execute the selected action.
|
# Execute the selected action.
|
||||||
|
|
||||||
mkpath("/etc/containers", 0, 0755);
|
mkpath("/etc/containers", 0, 0755);
|
||||||
@ -137,7 +143,7 @@ EOF
|
|||||||
|
|
||||||
sub buildFlake {
|
sub buildFlake {
|
||||||
system("nix", "build", "-o", "$systemPath.tmp", "--",
|
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";
|
or die "$0: failed to build container from flake '$flake'\n";
|
||||||
$systemPath = readlink("$systemPath.tmp") or die;
|
$systemPath = readlink("$systemPath.tmp") or die;
|
||||||
unlink("$systemPath.tmp");
|
unlink("$systemPath.tmp");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user