Dual Booting NixOS and Windows: Difference between revisions
IFreilicht (talk | contribs) Add method to boot Windows if it is installed on a different drive than NixOS |
m Updated syntax |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
This section explains various methods to have the bootloader prompt whether to boot windows or NixOS. | This section explains various methods to have the [[bootloader]] prompt whether to boot windows or NixOS. | ||
== Autodetection == | == Autodetection == | ||
| Line 84: | Line 84: | ||
* the <code>boot.loader.systemd-boot.enable = true;</code> line added to configuration.nix by <code>nixos-generate-config</code> has been removed | * the <code>boot.loader.systemd-boot.enable = true;</code> line added to configuration.nix by <code>nixos-generate-config</code> has been removed | ||
{{File| | {{File|3={ config, ... }: | ||
{ config, ... }: | |||
{ | { | ||
| Line 114: | Line 113: | ||
} | } | ||
''; | ''; | ||
}; | }; | ||
}; | }; | ||
} | }|name=/etc/nixos/configuration.nix|lang=nix}} | ||
==== EFI with multiple disks ==== | ==== EFI with multiple disks ==== | ||
| Line 123: | Line 121: | ||
===== systemd-boot ===== | ===== systemd-boot ===== | ||
As systemd-boot cannot directly load binaries from other ESPs<ref>https://github.com/systemd/systemd/issues/3252</ref>, let alone other disks, we have to employ [https://search.nixos.org/packages?channel=unstable&show=edk2-uefi-shell&from=0&size=50&sort=relevance&type=packages&query=edk2-uefi-shell edk2-uefi-shell] to implement a chainloading strategy<ref>https://wiki.archlinux.org/title/Systemd-boot#Boot_from_another_disk</ref>. The basic config looks like this:{{File|/etc/nixos/configuration.nix|nix|<nowiki> | As systemd-boot cannot directly load binaries from other ESPs<ref>https://github.com/systemd/systemd/issues/3252</ref>, let alone other disks, we have to employ [https://search.nixos.org/packages?channel=unstable&show=edk2-uefi-shell&from=0&size=50&sort=relevance&type=packages&query=edk2-uefi-shell edk2-uefi-shell] to implement a chainloading strategy<ref>https://wiki.archlinux.org/title/Systemd-boot#Boot_from_another_disk</ref>. The basic config looks like this:{{File|/etc/nixos/configuration.nix|nix|<nowiki> | ||
{ | { ... }: | ||
{ | { | ||
boot.loader = { | boot.loader = { | ||
efi.canTouchEfiVariables = true; | efi.canTouchEfiVariables = true; | ||
systemd-boot = { | |||
systemd-boot | enable = true; | ||
windows = { | |||
"windows" = | |||
let | |||
# To determine the name of the windows boot drive, boot into edk2 first, then run | |||
# `map -c` to get drive aliases, and try out running `FS1:`, then `ls EFI` to check | |||
# which alias corresponds to which EFI partition. | |||
boot-drive = "FS1"; | |||
in | |||
{ | |||
title = "Windows"; | |||
efiDeviceHandle = boot-drive; | |||
sortKey = "y_windows"; | |||
}; | |||
}; | |||
edk2-uefi-shell.enable = true; | |||
edk2-uefi-shell.sortKey = "z_edk2"; | |||
}; | }; | ||
}; | }; | ||
| Line 213: | Line 207: | ||
== System time == | == System time == | ||
System clock might be incorrect after booting Windows and going back to | System clock might be incorrect after booting Windows and going back to NixOS. | ||
It can be fixed by setting RTC time standard to UTC on Windows (''recommended'', see [https://wiki.archlinux.org/title/System_time#UTC_in_Microsoft_Windows how to do this]). | |||
Alternatively, you can set NixOS RTC time standard to localtime, compatible with Windows in its default configuration: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
| Line 222: | Line 218: | ||
}</nowiki>}} | }</nowiki>}} | ||
See [https://wiki.archlinux.org/title/System_time#Time_standard Arch Linux wiki#System time]. | See [https://wiki.archlinux.org/title/System_time#Time_standard Arch Linux wiki#System time] for discussion of both options. | ||
== See also == | == See also == | ||
* [[GNU GRUB]] | |||
* [https://wiki.archlinux.org/index.php/GRUB#Windows_installed_in_UEFI-GPT_Mode_menu_entry Arch Linux wiki#GRUB] | * [https://wiki.archlinux.org/index.php/GRUB#Windows_installed_in_UEFI-GPT_Mode_menu_entry Arch Linux wiki#GRUB] | ||
* [https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/loader/grub/install-grub.pl NixOS GRUB installer] (check the code block beginning with <nowiki># install EFI GRUB</nowiki>) | * [https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/loader/grub/install-grub.pl NixOS GRUB installer] (check the code block beginning with <nowiki># install EFI GRUB</nowiki>) | ||
[[Category:Cookbook]][[Category:NixOS]] | [[Category:Cookbook]] | ||
[[Category:NixOS]] | |||
[[Category:Booting]] | |||