Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,42 @@ addEntry() {
local path="$1"
local generation="$2"
local outdir=/boot/system-$generation
local defaultdir=/boot/default

if ! test -e $path/kernel -a -e $path/initrd; then
return
fi

local kernel=$(readlink -f $path/kernel)
local initrd=$(readlink -f $path/initrd)
local extraLnArgs=""

if test -n "@copyKernels@"; then
copyToKernelsDir $kernel; kernel=$result
copyToKernelsDir $initrd; initrd=$result
extraLnArgs="-r"
fi

mkdir -p $outdir
ln -sf $(readlink -f $path) $outdir/system
ln -sf $(readlink -f $path/init) $outdir/init
ln -sf $initrd $outdir/initrd
ln -sf $kernel $outdir/kernel
ln -sf $extraLnArgs $initrd $outdir/initrd
ln -sf $extraLnArgs $kernel $outdir/kernel

if test $(readlink -f "$path") = "$default"; then
cp "$kernel" /boot/nixos-kernel
cp "$initrd" /boot/nixos-initrd
cp "$(readlink -f "$path/init")" /boot/nixos-init

mkdir -p /boot/default
# ln -sfT: overrides target even if it exists.
ln -sfT $(readlink -f $path) /boot/default/system
ln -sfT $(readlink -f $path/init) /boot/default/init
ln -sfT $initrd /boot/default/initrd
ln -sfT $kernel /boot/default/kernel
if test -n "@copyDefault@"; then
cp "$kernel" /boot/nixos-kernel
cp "$initrd" /boot/nixos-initrd
cp "$(readlink -f "$path/init")" /boot/nixos-init
fi

# Clean up the /boot/default directory created by earlier
# versions of generations-dir.
if test -d $defaultdir -a ! -L $defaultdir; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels very dangerous. Maybe at least log a warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delete is required. If $defaultdir is not deleted, then the following ln would error out with ln: default: cannot overwrite directory.

Further up, there is an unconditional rm -Rf /boot/system*. The updates are already destructive and not atomic. Improvements in those areas would be nice, but is it a blocker?

Is the concern that users are storing files in /boot/default other than those created by generationsDir? If so, then what kind of warning would help? At this point in the script, we either finish setting up /boot or the user is left with an unbootable system.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always hard to tell what is in scope of the bootloader script. IMO if there's an existing directory that contains anything but the files we're about to put there, we should just abort.

rm -Rf $defaultdir
fi

ln -sfrT $outdir $defaultdir
fi
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let
pkgs.gnused
pkgs.gnugrep
];
inherit (config.boot.loader.generationsDir) copyKernels;
inherit (config.boot.loader.generationsDir) copyKernels copyDefault;
};
};

Expand Down Expand Up @@ -58,6 +58,25 @@ in
'';
};

copyDefault = mkOption {
default = true;
type = types.bool;
description = ''
Whether to copy the default system profile boot files to a second set
of files in `/boot` (`nixos-kernel`, `nixos-initrd`, `nixos-init`).

Disable this option to save space on the `/boot` partition if your
boot loader can follow the `default` symlink.

If you previously enabled this option, you need to clean up the old
files manually:

```
rm -vf /boot/nixos-{kernel,initrd,init}
```
'';
};

};

};
Expand Down