voidzero / nixos-zfs-setup

A bash script that sets up zfs disks for NixOS.
GNU General Public License v3.0
29 stars 8 forks source link

mktemp not found when running boot.loader.grub.extraInstallCommands in nixos-rebuild #2

Open 00Asgaroth00 opened 10 months ago

00Asgaroth00 commented 10 months ago

Hi,

First of all, thank you for this script!!

I'm (very) new to nixos and used your script to build zfs on my boot disk, installed nixos (using flake) and then rebooted, all good, everything comes up. However, if i try to update my configuration, the switch fails with the following messages:

[nix-shell:~/git_repos/nixos-config]$ sudo nixos-rebuild switch --flake .#$(hostname -s)
building the system configuration...
updating GRUB 2 menu...
/nix/store/dd8bfvhsxfjnb14r62ans5aprjvsk5my-install-grub.sh: line 5: mktemp: command not found
warning: error(s) occurred while switching to the new configuration

mktemp appears to be installed on the system (within the nix-shell):

[nix-shell:~/git_repos/nixos-config]$ which mktemp
/nix/store/bblyj5b3ii8n6v4ra0nb37cmi3lf8rz9-coreutils-9.3/bin/mktemp

as the super user on the system

[root@thanos:~]# command -v mktemp
/run/current-system/sw/bin/mktemp

The content of the install-grub.sh script is as follows:

[nix-shell:~/git_repos/nixos-config]$ cat /nix/store/dd8bfvhsxfjnb14r62ans5aprjvsk5my-install-grub.sh 
#!/nix/store/q1c2flcykgr4wwg5a6h450hxbk4ch589-bash-5.2-p15/bin/bash
set -e

/nix/store/lnaxkqj8hg37q9mb4cv5l8zgb919baw2-perl-5.38.0-env/bin/perl /nix/store/75qbm0iq2qdc5kkijmyymf3mzswjivrc-install-grub.pl /nix/store/9g2vb0ppkx6npbihl3dqf6qcy4vzxb6j-grub-config.xml $@
ESP_MIRROR=$(mktemp -d)
cp -r /boot/efi/EFI $ESP_MIRROR
for i in /boot/efis/*; do
  cp -r $ESP_MIRROR/EFI $i
done
rm -rf $ESP_MIRROR

The modifications I made to your script when installing the system can be seen HERE, the changes I made were:

[1] DISK variable [2] ROOTPW variable [3] Forced creation of boot pool (added -f on line 118) [4] Forced creation of root pool (added -f on line 135)

Any thoughts on this, have you encountered this issue when using the script?

antonionardella commented 2 months ago

Hi @00Asgaroth00,

I also installed a machine using this script and I am getting the same error while trying to run nixos-rebuild switch.

Someone pointed out this workaround: https://github.com/NixOS/nixpkgs/issues/262266#issuecomment-1772743499

But I still have to see if it works


Changed

  boot.loader.grub.extraInstallCommands = ''
    ESP_MIRROR=$(mktemp -d)
    cp -r /boot/efi/EFI $ESP_MIRROR
    for i in /boot/efis/*; do
      cp -r $ESP_MIRROR/EFI $i
    done
    rm -rf $ESP_MIRROR
  '';

to

  boot.loader.grub.extraInstallCommands = ''
    ESP_MIRROR=$(${pkgs.coreutils}/bin/mktemp -d)
    ${pkgs.coreutils}/bin/cp -r /boot/efi/EFI $ESP_MIRROR
    for i in /boot/efis/*; do
      ${pkgs.coreutils}/bin/cp -r $ESP_MIRROR/EFI $i
    done
    ${pkgs.coreutils}/bin/rm -rf $ESP_MIRROR
  '';

To make it work