nixos/etc: Make symlinks relative instead of absolute
so that the links can be followed if the NixOS installation is not mounted as filesystem root. In particular, this makes /etc/os-release adhere to the standard: https://www.freedesktop.org/software/systemd/man/os-release.html Fixes #28833.
This commit is contained in:
parent
2e76049491
commit
fc8e1745c0
@ -457,6 +457,14 @@
|
|||||||
use <literal>nixos-rebuild boot; reboot</literal>.
|
use <literal>nixos-rebuild boot; reboot</literal>.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Symlinks in <filename>/etc</filename> are now relative instead of absolute,
|
||||||
|
so that the links can be followed if the NixOS installation is not mounted as filesystem root.
|
||||||
|
In particular, this makes <filename>/etc/os-release</filename> adhere to
|
||||||
|
<link xlink:href="https://www.freedesktop.org/software/systemd/man/os-release.html">the standard</link>.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Flat volumes are now disabled by default in <literal>hardware.pulseaudio</literal>.
|
Flat volumes are now disabled by default in <literal>hardware.pulseaudio</literal>.
|
||||||
|
@ -40,7 +40,7 @@ for ((n = 0; n < ${#objects[*]}; n++)); do
|
|||||||
symlink=${symlinks[$n]}
|
symlink=${symlinks[$n]}
|
||||||
if test "$symlink" != "none"; then
|
if test "$symlink" != "none"; then
|
||||||
mkdir -p $(dirname ./$symlink)
|
mkdir -p $(dirname ./$symlink)
|
||||||
ln -s $object ./$symlink
|
ln -s --relative ./$object ./$symlink
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -10,6 +10,11 @@ users_=($users)
|
|||||||
groups_=($groups)
|
groups_=($groups)
|
||||||
set +f
|
set +f
|
||||||
|
|
||||||
|
# Create relative symlinks, so that the links can be followed if
|
||||||
|
# the NixOS installation is not mounted as filesystem root.
|
||||||
|
# Absolute symlinks violate the os-release format
|
||||||
|
# at https://www.freedesktop.org/software/systemd/man/os-release.html
|
||||||
|
# and break e.g. systemd-nspawn and os-prober.
|
||||||
for ((i = 0; i < ${#targets_[@]}; i++)); do
|
for ((i = 0; i < ${#targets_[@]}; i++)); do
|
||||||
source="${sources_[$i]}"
|
source="${sources_[$i]}"
|
||||||
target="${targets_[$i]}"
|
target="${targets_[$i]}"
|
||||||
@ -19,14 +24,14 @@ for ((i = 0; i < ${#targets_[@]}; i++)); do
|
|||||||
# If the source name contains '*', perform globbing.
|
# If the source name contains '*', perform globbing.
|
||||||
mkdir -p $out/etc/$target
|
mkdir -p $out/etc/$target
|
||||||
for fn in $source; do
|
for fn in $source; do
|
||||||
ln -s "$fn" $out/etc/$target/
|
ln -s --relative "$fn" $out/etc/$target/
|
||||||
done
|
done
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
mkdir -p $out/etc/$(dirname $target)
|
mkdir -p $out/etc/$(dirname $target)
|
||||||
if ! [ -e $out/etc/$target ]; then
|
if ! [ -e $out/etc/$target ]; then
|
||||||
ln -s $source $out/etc/$target
|
ln -s --relative $source $out/etc/$target
|
||||||
else
|
else
|
||||||
echo "duplicate entry $target -> $source"
|
echo "duplicate entry $target -> $source"
|
||||||
if test "$(readlink $out/etc/$target)" != "$source"; then
|
if test "$(readlink $out/etc/$target)" != "$source"; then
|
||||||
|
@ -4,6 +4,7 @@ use File::Copy;
|
|||||||
use File::Path;
|
use File::Path;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
use File::Slurp;
|
use File::Slurp;
|
||||||
|
use File::Spec;
|
||||||
|
|
||||||
my $etc = $ARGV[0] or die;
|
my $etc = $ARGV[0] or die;
|
||||||
my $static = "/etc/static";
|
my $static = "/etc/static";
|
||||||
@ -12,7 +13,13 @@ sub atomicSymlink {
|
|||||||
my ($source, $target) = @_;
|
my ($source, $target) = @_;
|
||||||
my $tmp = "$target.tmp";
|
my $tmp = "$target.tmp";
|
||||||
unlink $tmp;
|
unlink $tmp;
|
||||||
symlink $source, $tmp or return 0;
|
# Create relative symlinks, so that the links can be followed if
|
||||||
|
# the NixOS installation is not mounted as filesystem root.
|
||||||
|
# Absolute symlinks violate the os-release format
|
||||||
|
# at https://www.freedesktop.org/software/systemd/man/os-release.html
|
||||||
|
# and break e.g. systemd-nspawn and os-prober.
|
||||||
|
my $rel = File::Spec->abs2rel($source, dirname $target);
|
||||||
|
symlink $rel, $tmp or return 0;
|
||||||
rename $tmp, $target or return 0;
|
rename $tmp, $target or return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -30,7 +37,8 @@ sub isStatic {
|
|||||||
|
|
||||||
if (-l $path) {
|
if (-l $path) {
|
||||||
my $target = readlink $path;
|
my $target = readlink $path;
|
||||||
return substr($target, 0, length "/etc/static/") eq "/etc/static/";
|
my $rel = File::Spec->abs2rel("/etc/static", dirname $path);
|
||||||
|
return substr($target, 0, length $rel) eq $rel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-d $path) {
|
if (-d $path) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user