Skip to content

Commit

Permalink
Bootstrap: nix-path-registration in persistent path on btrfs-subvol
Browse files Browse the repository at this point in the history
To allow directly provisioning to impermanence, / cannot be used for
files that are needed on-boot.  Move nix-path-registration into /nix
when creating a FS with btrfs-subvol.
  • Loading branch information
nakato committed Sep 10, 2024
1 parent 96488c9 commit d513ba4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions modules/sbc/bootstrap/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ in {
if (builtins.elem cfg.rootFilesystem ["btrfs" "btrfs-subvol"])
then btrfsResizeCommands
else ext4ResizeCommands;
registrationPath =
if (cfg.rootFilesystem == "btrfs-subvol")
then "/nix/nix-path-registration"
else "/nix-path-registration";
in ''
# On the first boot do some maintenance tasks
if [ -f /nix-path-registration ]; then
if [ -f ${registrationPath} ]; then
set -euo pipefail
set -x
# Figure out device names for the boot device and root filesystem.
Expand All @@ -145,14 +149,14 @@ in {
${resizeCommands}
# Register the contents of the initial Nix store
${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration
${config.nix.package.out}/bin/nix-store --load-db < ${registrationPath}
# nixos-rebuild also requires a "system" profile and an /etc/NIXOS tag.
touch /etc/NIXOS
${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system
# Prevents this from running on later boots.
rm -f /nix-path-registration
rm -f ${registrationPath}
fi
'';
})
Expand Down
2 changes: 1 addition & 1 deletion modules/sbc/bootstrap/make-btrfs-fs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pkgs.stdenv.mkDerivation {
done
)
cp ${sdClosureInfo}/registration ./rootImage/nix-path-registration
cp ${sdClosureInfo}/registration ./rootImage/nix/nix-path-registration
${rootSubvolCmd}
${subvolMovePaths}
Expand Down

0 comments on commit d513ba4

Please sign in to comment.