1#! @perl@
2
3use strict;
4use Cwd 'abs_path';
5use File::Spec;
6use File::Path;
7use File::Basename;
8use File::Slurp;
9use File::stat;
10
11umask(0022);
12
13sub uniq {
14 my %seen;
15 my @res = ();
16 foreach my $s (@_) {
17 if (!defined $seen{$s}) {
18 $seen{$s} = 1;
19 push @res, $s;
20 }
21 }
22 return @res;
23}
24
25sub runCommand {
26 my ($cmd) = @_;
27 open FILE, "$cmd 2>&1 |" or die "Failed to execute: $cmd\n";
28 my @ret = <FILE>;
29 close FILE;
30 return ($?, @ret);
31}
32
33# Process the command line.
34my $outDir = "/etc/nixos";
35my $rootDir = ""; # = /
36my $force = 0;
37my $noFilesystems = 0;
38my $showHardwareConfig = 0;
39
40for (my $n = 0; $n < scalar @ARGV; $n++) {
41 my $arg = $ARGV[$n];
42 if ($arg eq "--help") {
43 exec "man nixos-generate-config" or die;
44 }
45 elsif ($arg eq "--dir") {
46 $n++;
47 $outDir = $ARGV[$n];
48 die "$0: ‘--dir’ requires an argument\n" unless defined $outDir;
49 }
50 elsif ($arg eq "--root") {
51 $n++;
52 $rootDir = $ARGV[$n];
53 die "$0: ‘--root’ requires an argument\n" unless defined $rootDir;
54 die "$0: no need to specify `/` with `--root`, it is the default\n" if $rootDir eq "/";
55 $rootDir =~ s/\/*$//; # remove trailing slashes
56 $rootDir = File::Spec->rel2abs($rootDir); # resolve absolute path
57 }
58 elsif ($arg eq "--force") {
59 $force = 1;
60 }
61 elsif ($arg eq "--no-filesystems") {
62 $noFilesystems = 1;
63 }
64 elsif ($arg eq "--show-hardware-config") {
65 $showHardwareConfig = 1;
66 }
67 else {
68 die "$0: unrecognized argument ‘$arg’\n";
69 }
70}
71
72
73my @attrs = ();
74my @kernelModules = ();
75my @initrdKernelModules = ();
76my @initrdAvailableKernelModules = ();
77my @modulePackages = ();
78my @imports;
79
80
81sub debug {
82 return unless defined $ENV{"DEBUG"};
83 print STDERR @_;
84}
85
86
87# nixpkgs.system
88push @attrs, "nixpkgs.hostPlatform = lib.mkDefault \"@hostPlatformSystem@\";";
89
90
91my $cpuinfo = read_file "/proc/cpuinfo";
92
93
94sub hasCPUFeature {
95 my $feature = shift;
96 return $cpuinfo =~ /^flags\s*:.* $feature( |$)/m;
97}
98
99
100sub cpuManufacturer {
101 my $id = shift;
102 return $cpuinfo =~ /^vendor_id\s*:.* $id$/m;
103}
104
105# Virtualization support?
106push @kernelModules, "kvm-intel" if hasCPUFeature "vmx";
107push @kernelModules, "kvm-amd" if hasCPUFeature "svm";
108
109
110# Look at the PCI devices and add necessary modules. Note that most
111# modules are auto-detected so we don't need to list them here.
112# However, some are needed in the initrd to boot the system.
113
114my $videoDriver;
115
116sub pciCheck {
117 my $path = shift;
118 my $vendor = read_file "$path/vendor"; chomp $vendor;
119 my $device = read_file "$path/device"; chomp $device;
120 my $class = read_file "$path/class"; chomp $class;
121
122 my $module;
123 if (-e "$path/driver/module") {
124 $module = basename `readlink -f $path/driver/module`;
125 chomp $module;
126 }
127
128 debug "$path: $vendor $device $class";
129 debug " $module" if defined $module;
130 debug "\n";
131
132 if (defined $module) {
133 # See the bottom of https://pciids.sourceforge.net/pci.ids for
134 # device classes.
135 if (# Mass-storage controller. Definitely important.
136 $class =~ /^0x01/ ||
137
138 # Firewire controller. A disk might be attached.
139 $class =~ /^0x0c00/ ||
140
141 # USB controller. Needed if we want to use the
142 # keyboard when things go wrong in the initrd.
143 $class =~ /^0x0c03/
144 )
145 {
146 push @initrdAvailableKernelModules, $module;
147 }
148 }
149
150 # broadcom STA driver (wl.ko)
151 # list taken from http://www.broadcom.com/docs/linux_sta/README.txt
152 if ($vendor eq "0x14e4" &&
153 ($device eq "0x4311" || $device eq "0x4312" || $device eq "0x4313" ||
154 $device eq "0x4315" || $device eq "0x4327" || $device eq "0x4328" ||
155 $device eq "0x4329" || $device eq "0x432a" || $device eq "0x432b" ||
156 $device eq "0x432c" || $device eq "0x432d" || $device eq "0x4353" ||
157 $device eq "0x4357" || $device eq "0x4358" || $device eq "0x4359" ||
158 $device eq "0x4331" || $device eq "0x43a0" || $device eq "0x43b1"
159 ) )
160 {
161 push @modulePackages, "config.boot.kernelPackages.broadcom_sta";
162 push @kernelModules, "wl";
163 }
164
165 # broadcom FullMac driver
166 # list taken from
167 # https://wireless.wiki.kernel.org/en/users/Drivers/brcm80211#brcmfmac
168 if ($vendor eq "0x14e4" &&
169 ($device eq "0x43a3" || $device eq "0x43df" || $device eq "0x43ec" ||
170 $device eq "0x43d3" || $device eq "0x43d9" || $device eq "0x43e9" ||
171 $device eq "0x43ba" || $device eq "0x43bb" || $device eq "0x43bc" ||
172 $device eq "0xaa52" || $device eq "0x43ca" || $device eq "0x43cb" ||
173 $device eq "0x43cc" || $device eq "0x43c3" || $device eq "0x43c4" ||
174 $device eq "0x43c5"
175 ) )
176 {
177 # we need e.g. brcmfmac43602-pcie.bin
178 push @imports, "(modulesPath + \"/hardware/network/broadcom-43xx.nix\")";
179 }
180
181 # In case this is a virtio scsi device, we need to explicitly make this available.
182 if ($vendor eq "0x1af4" && ($device eq "0x1004" || $device eq "0x1048") ) {
183 push @initrdAvailableKernelModules, "virtio_scsi";
184 }
185
186 # Can't rely on $module here, since the module may not be loaded
187 # due to missing firmware. Ideally we would check modules.pcimap
188 # here.
189 push @attrs, "networking.enableIntel2200BGFirmware = true;" if
190 $vendor eq "0x8086" &&
191 ($device eq "0x1043" || $device eq "0x104f" || $device eq "0x4220" ||
192 $device eq "0x4221" || $device eq "0x4223" || $device eq "0x4224");
193
194 push @attrs, "networking.enableIntel3945ABGFirmware = true;" if
195 $vendor eq "0x8086" &&
196 ($device eq "0x4229" || $device eq "0x4230" ||
197 $device eq "0x4222" || $device eq "0x4227");
198
199 # Assume that all NVIDIA cards are supported by the NVIDIA driver.
200 # There may be exceptions (e.g. old cards).
201 # FIXME: do we want to enable an unfree driver here?
202 #$videoDriver = "nvidia" if $vendor eq "0x10de" && $class =~ /^0x03/;
203}
204
205foreach my $path (glob "/sys/bus/pci/devices/*") {
206 pciCheck $path;
207}
208
209# Idem for USB devices.
210
211sub usbCheck {
212 my $path = shift;
213 my $class = read_file "$path/bInterfaceClass"; chomp $class;
214 my $subclass = read_file "$path/bInterfaceSubClass"; chomp $subclass;
215 my $protocol = read_file "$path/bInterfaceProtocol"; chomp $protocol;
216
217 my $module;
218 if (-e "$path/driver/module") {
219 $module = basename `readlink -f $path/driver/module`;
220 chomp $module;
221 }
222
223 debug "$path: $class $subclass $protocol";
224 debug " $module" if defined $module;
225 debug "\n";
226
227 if (defined $module) {
228 if (# Mass-storage controller. Definitely important.
229 $class eq "08" ||
230
231 # Keyboard. Needed if we want to use the
232 # keyboard when things go wrong in the initrd.
233 ($class eq "03" && $protocol eq "01")
234 )
235 {
236 push @initrdAvailableKernelModules, $module;
237 }
238 }
239}
240
241foreach my $path (glob "/sys/bus/usb/devices/*") {
242 if (-e "$path/bInterfaceClass") {
243 usbCheck $path;
244 }
245}
246
247
248# Add the modules for all block and MMC devices.
249foreach my $path (glob "/sys/class/{block,mmc_host}/*") {
250 my $module;
251 if (-e "$path/device/driver/module") {
252 $module = basename `readlink -f $path/device/driver/module`;
253 chomp $module;
254 push @initrdAvailableKernelModules, $module;
255 }
256}
257
258# Add bcache module, if needed.
259my @bcacheDevices = glob("/dev/bcache*");
260@bcacheDevices = grep(!qr#dev/bcachefs.*#, @bcacheDevices);
261if (scalar @bcacheDevices > 0) {
262 push @initrdAvailableKernelModules, "bcache";
263}
264
265# Prevent unbootable systems if LVM snapshots are present at boot time.
266if (`lsblk -o TYPE` =~ "lvm") {
267 push @initrdKernelModules, "dm-snapshot";
268}
269
270my $virt = `@detectvirt@`;
271chomp $virt;
272
273
274# Check if we're a VirtualBox guest. If so, enable the guest
275# additions.
276if ($virt eq "oracle") {
277 push @attrs, "virtualisation.virtualbox.guest.enable = true;"
278}
279
280# Check if we're a Parallels guest. If so, enable the guest additions.
281# It is blocked by https://github.com/systemd/systemd/pull/23859
282if ($virt eq "parallels") {
283 push @attrs, "hardware.parallels.enable = true;";
284 push @attrs, "nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ \"prl-tools\" ];";
285}
286
287# Likewise for QEMU.
288if ($virt eq "qemu" || $virt eq "kvm" || $virt eq "bochs") {
289 push @imports, "(modulesPath + \"/profiles/qemu-guest.nix\")";
290}
291
292# Also for Hyper-V.
293if ($virt eq "microsoft") {
294 push @attrs, "virtualisation.hypervGuest.enable = true;"
295}
296
297
298# Pull in NixOS configuration for containers.
299if ($virt eq "systemd-nspawn") {
300 push @attrs, "boot.isContainer = true;";
301}
302
303
304# Check if we're on bare metal, not in a VM/container.
305if ($virt eq "none") {
306 # Provide firmware for devices that are not detected by this script.
307 push @imports, "(modulesPath + \"/installer/scan/not-detected.nix\")";
308
309 # Update the microcode.
310 push @attrs, "hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;" if cpuManufacturer "AuthenticAMD";
311 push @attrs, "hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;" if cpuManufacturer "GenuineIntel";
312}
313
314# For a device name like /dev/sda1, find a more stable path like
315# /dev/disk/by-uuid/X or /dev/disk/by-label/Y.
316sub findStableDevPath {
317 my ($dev) = @_;
318 return $dev if substr($dev, 0, 1) ne "/";
319 return $dev unless -e $dev;
320
321 my $st = stat($dev) or return $dev;
322
323 foreach my $dev2 (glob("/dev/stratis/*/*"), glob("/dev/disk/by-uuid/*"), glob("/dev/mapper/*"), glob("/dev/disk/by-label/*")) {
324 my $st2 = stat($dev2) or next;
325 return $dev2 if $st->rdev == $st2->rdev;
326 }
327
328 return $dev;
329}
330
331push @attrs, "services.xserver.videoDrivers = [ \"$videoDriver\" ];" if $videoDriver;
332
333# Generate the swapDevices option from the currently activated swap
334# devices.
335my @swaps = read_file("/proc/swaps", err_mode => 'carp');
336my @swapDevices;
337if (@swaps) {
338 shift @swaps;
339 foreach my $swap (@swaps) {
340 my @fields = split ' ', $swap;
341 my $swapFilename = $fields[0];
342 my $swapType = $fields[1];
343 next unless -e $swapFilename;
344 my $dev = findStableDevPath $swapFilename;
345 if ($swapType =~ "partition") {
346 # zram devices are more likely created by configuration.nix, so
347 # ignore them here
348 next if ($swapFilename =~ /^\/dev\/zram/);
349 push @swapDevices, "{ device = \"$dev\"; }";
350 } elsif ($swapType =~ "file") {
351 # swap *files* are more likely specified in configuration.nix, so
352 # ignore them here.
353 } else {
354 die "Unsupported swap type: $swapType\n";
355 }
356 }
357}
358
359
360# Generate the fileSystems option from the currently mounted
361# filesystems.
362sub in {
363 my ($d1, $d2) = @_;
364 return $d1 eq $d2 || substr($d1, 0, length($d2) + 1) eq "$d2/";
365}
366
367my $fileSystems;
368my %fsByDev;
369my $useSwraid = 0;
370foreach my $fs (read_file("/proc/self/mountinfo")) {
371 chomp $fs;
372 my @fields = split / /, $fs;
373 my $mountPoint = $fields[4];
374 $mountPoint =~ s/\\040/ /g; # account for mount points with spaces in the name (\040 is the escape character)
375 $mountPoint =~ s/\\011/\t/g; # account for mount points with tabs in the name (\011 is the escape character)
376 next unless -d $mountPoint;
377 my @mountOptions = split /,/, $fields[5];
378
379 next if !in($mountPoint, $rootDir);
380 $mountPoint = substr($mountPoint, length($rootDir)); # strip the root directory (e.g. /mnt)
381 $mountPoint = "/" if $mountPoint eq "";
382
383 # Skip special filesystems.
384 next if in($mountPoint, "/proc") || in($mountPoint, "/dev") || in($mountPoint, "/sys") || in($mountPoint, "/run") || $mountPoint eq "/var/lib/nfs/rpc_pipefs";
385
386 # Skip the optional fields.
387 my $n = 6; $n++ while $fields[$n] ne "-"; $n++;
388 my $fsType = $fields[$n];
389 my $device = $fields[$n + 1];
390 my @superOptions = split /,/, $fields[$n + 2];
391 $device =~ s/\\040/ /g; # account for devices with spaces in the name (\040 is the escape character)
392 $device =~ s/\\011/\t/g; # account for mount points with tabs in the name (\011 is the escape character)
393
394 # Skip the read-only bind-mount on /nix/store.
395 next if $mountPoint eq "/nix/store" && (grep { $_ eq "rw" } @superOptions) && (grep { $_ eq "ro" } @mountOptions);
396
397 # Maybe this is a bind-mount of a filesystem we saw earlier?
398 if (defined $fsByDev{$fields[2]}) {
399 # Make sure this isn't a btrfs subvolume.
400 my $msg = `@btrfs@ subvol show $rootDir$mountPoint`;
401 if ($? != 0 || $msg =~ /ERROR:/s) {
402 my $path = $fields[3]; $path = "" if $path eq "/";
403 my $base = $fsByDev{$fields[2]};
404 $base = "" if $base eq "/";
405 $fileSystems .= <<EOF;
406 fileSystems.\"$mountPoint\" =
407 { device = \"$base$path\";
408 fsType = \"none\";
409 options = \[ \"bind\" \];
410 };
411
412EOF
413 next;
414 }
415 }
416 $fsByDev{$fields[2]} = $mountPoint;
417
418 # We don't know how to handle FUSE filesystems.
419 if ($fsType eq "fuseblk" || $fsType eq "fuse") {
420 print STDERR "warning: don't know how to emit ‘fileSystem’ option for FUSE filesystem ‘$mountPoint’\n";
421 next;
422 }
423
424 # Is this a mount of a loopback device?
425 my @extraOptions;
426 if ($device =~ /\/dev\/loop(\d+)/) {
427 my $loopnr = $1;
428 my $backer = read_file "/sys/block/loop$loopnr/loop/backing_file";
429 if (defined $backer) {
430 chomp $backer;
431 $device = $backer;
432 push @extraOptions, "loop";
433 }
434 }
435
436 # Is this a btrfs filesystem?
437 if ($fsType eq "btrfs") {
438 my ($status, @info) = runCommand("@btrfs@ subvol show $rootDir$mountPoint");
439 if ($status != 0 || join("", @info) =~ /ERROR:/) {
440 die "Failed to retrieve subvolume info for $mountPoint\n";
441 }
442 my @ids = join("\n", @info) =~ m/^(?!\/\n).*Subvolume ID:[ \t\n]*([0-9]+)/s;
443 if ($#ids > 0) {
444 die "Btrfs subvol name for $mountPoint listed multiple times in mount\n"
445 } elsif ($#ids == 0) {
446 my @paths = join("", @info) =~ m/^([^\n]*)/;
447 if ($#paths > 0) {
448 die "Btrfs returned multiple paths for a single subvolume id, mountpoint $mountPoint\n";
449 } elsif ($#paths != 0) {
450 die "Btrfs did not return a path for the subvolume at $mountPoint\n";
451 }
452 push @extraOptions, "subvol=$paths[0]";
453 }
454 }
455
456 # is this a stratis fs?
457 my $stableDevPath = findStableDevPath $device;
458 my $stratisPool;
459 if ($stableDevPath =~ qr#/dev/stratis/(.*)/.*#) {
460 my $poolName = $1;
461 my ($header, @lines) = split "\n", qx/stratis pool list/;
462 my $uuidIndex = index $header, 'UUID';
463 my ($line) = grep /^$poolName /, @lines;
464 $stratisPool = substr $line, $uuidIndex - 32, 36;
465 }
466
467 # Don't emit tmpfs entry for /tmp, because it most likely comes from the
468 # boot.tmp.useTmpfs option in configuration.nix (managed declaratively).
469 next if ($mountPoint eq "/tmp" && $fsType eq "tmpfs");
470
471 # This should work for single and multi-device systems.
472 # still needs subvolume support
473 if ($fsType eq "bcachefs") {
474 my ($status, @info) = runCommand("bcachefs fs usage $rootDir$mountPoint");
475 my $UUID = $info[0];
476
477 if ($status == 0 && $UUID =~ /^Filesystem:[ \t\n]*([0-9a-z-]+)/) {
478 $stableDevPath = "UUID=$1";
479 } else {
480 print STDERR "warning: can't find bcachefs mount UUID falling back to device-path";
481 }
482 }
483
484 # Emit the filesystem.
485 $fileSystems .= <<EOF;
486 fileSystems.\"$mountPoint\" =
487 { device = \"$stableDevPath\";
488 fsType = \"$fsType\";
489EOF
490
491 if (scalar @extraOptions > 0) {
492 $fileSystems .= <<EOF;
493 options = \[ ${\join " ", map { "\"" . $_ . "\"" } uniq(@extraOptions)} \];
494EOF
495 }
496
497 if ($stratisPool) {
498 $fileSystems .= <<EOF;
499 stratis.poolUuid = "$stratisPool";
500EOF
501 }
502
503 $fileSystems .= <<EOF;
504 };
505
506EOF
507
508 # If this filesystem is on a LUKS device, then add a
509 # boot.initrd.luks.devices entry.
510 if (-e $device) {
511 my $deviceName = basename(abs_path($device));
512 my $dmUuid = read_file("/sys/class/block/$deviceName/dm/uuid", err_mode => 'quiet');
513 if ($dmUuid =~ /^CRYPT-LUKS/)
514 {
515 my @slaves = glob("/sys/class/block/$deviceName/slaves/*");
516 if (scalar @slaves == 1) {
517 my $slave = "/dev/" . basename($slaves[0]);
518 if (-e $slave) {
519 my $dmName = read_file("/sys/class/block/$deviceName/dm/name");
520 chomp $dmName;
521 # Ensure to add an entry only once
522 my $luksDevice = " boot.initrd.luks.devices.\"$dmName\".device";
523 if ($fileSystems !~ /^\Q$luksDevice\E/m) {
524 $fileSystems .= "$luksDevice = \"${\(findStableDevPath $slave)}\";\n\n";
525 }
526 }
527 }
528 }
529 if (-e "/sys/class/block/$deviceName/md/uuid") {
530 $useSwraid = 1;
531 }
532 }
533}
534if ($useSwraid) {
535 push @attrs, "boot.swraid.enable = true;\n\n";
536}
537
538
539# Generate the hardware configuration file.
540
541sub toNixStringList {
542 my $res = "";
543 foreach my $s (@_) {
544 $res .= " \"$s\"";
545 }
546 return $res;
547}
548sub toNixList {
549 my $res = "";
550 foreach my $s (@_) {
551 $res .= " $s";
552 }
553 return $res;
554}
555
556sub multiLineList {
557 my $indent = shift;
558 return " [ ]" if !@_;
559 my $res = "\n${indent}[ ";
560 my $first = 1;
561 foreach my $s (@_) {
562 $res .= "$indent " if !$first;
563 $first = 0;
564 $res .= "$s\n";
565 }
566 $res .= "$indent]";
567 return $res;
568}
569
570my $initrdAvailableKernelModules = toNixStringList(uniq @initrdAvailableKernelModules);
571my $initrdKernelModules = toNixStringList(uniq @initrdKernelModules);
572my $kernelModules = toNixStringList(uniq @kernelModules);
573my $modulePackages = toNixList(uniq @modulePackages);
574
575my $fsAndSwap = "";
576if (!$noFilesystems) {
577 $fsAndSwap = "\n$fileSystems ";
578 $fsAndSwap .= "swapDevices =" . multiLineList(" ", @swapDevices) . ";\n";
579}
580
581my $networkingDhcpConfig = generateNetworkingDhcpConfig();
582
583my $hwConfig = <<EOF;
584# Do not modify this file! It was generated by ‘nixos-generate-config’
585# and may be overwritten by future invocations. Please make changes
586# to /etc/nixos/configuration.nix instead.
587{ config, lib, pkgs, modulesPath, ... }:
588
589{
590 imports =${\multiLineList(" ", @imports)};
591
592 boot.initrd.availableKernelModules = [$initrdAvailableKernelModules ];
593 boot.initrd.kernelModules = [$initrdKernelModules ];
594 boot.kernelModules = [$kernelModules ];
595 boot.extraModulePackages = [$modulePackages ];
596$fsAndSwap
597$networkingDhcpConfig
598${\join "", (map { " $_\n" } (uniq @attrs))}}
599EOF
600
601sub generateNetworkingDhcpConfig {
602 # FIXME disable networking.useDHCP by default when switching to networkd.
603 my $config = <<EOF;
604 # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
605 # (the default) this is the recommended approach. When using systemd-networkd it's
606 # still possible to use this option, but it's recommended to use it in conjunction
607 # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
608 networking.useDHCP = lib.mkDefault true;
609EOF
610
611 foreach my $path (glob "/sys/class/net/*") {
612 my $dev = basename($path);
613 if ($dev ne "lo") {
614 $config .= " # networking.interfaces.$dev.useDHCP = lib.mkDefault true;\n";
615 }
616 }
617
618 return $config;
619}
620
621sub generateXserverConfig {
622 my $xserverEnabled = "@xserverEnabled@";
623
624 my $config = "";
625 if ($xserverEnabled eq "1") {
626 $config = <<EOF;
627 # Enable the X11 windowing system.
628 services.xserver.enable = true;
629EOF
630 } else {
631 $config = <<EOF;
632 # Enable the X11 windowing system.
633 # services.xserver.enable = true;
634EOF
635 }
636}
637
638if ($showHardwareConfig) {
639 print STDOUT $hwConfig;
640} else {
641 if ($outDir eq "/etc/nixos") {
642 $outDir = "$rootDir$outDir";
643 } else {
644 $outDir = File::Spec->rel2abs($outDir);
645 $outDir =~ s/\/*$//; # remove trailing slashes
646 }
647
648 my $fn = "$outDir/hardware-configuration.nix";
649 print STDERR "writing $fn...\n";
650 mkpath($outDir, 0, 0755);
651 write_file($fn, $hwConfig);
652
653 # Generate a basic configuration.nix, unless one already exists.
654 $fn = "$outDir/configuration.nix";
655 if ($force || ! -e $fn) {
656 print STDERR "writing $fn...\n";
657
658 my $bootLoaderConfig = "";
659 if (-e "/sys/firmware/efi/efivars") {
660 $bootLoaderConfig = <<EOF;
661 # Use the systemd-boot EFI boot loader.
662 boot.loader.systemd-boot.enable = true;
663 boot.loader.efi.canTouchEfiVariables = true;
664EOF
665 } elsif (-e "/boot/extlinux") {
666 $bootLoaderConfig = <<EOF;
667 # Use the extlinux boot loader. (NixOS wants to enable GRUB by default)
668 boot.loader.grub.enable = false;
669 # Enables the generation of /boot/extlinux/extlinux.conf
670 boot.loader.generic-extlinux-compatible.enable = true;
671EOF
672 } elsif ($virt ne "systemd-nspawn") {
673 $bootLoaderConfig = <<EOF;
674 # Use the GRUB 2 boot loader.
675 boot.loader.grub.enable = true;
676 # boot.loader.grub.efiSupport = true;
677 # boot.loader.grub.efiInstallAsRemovable = true;
678 # boot.loader.efi.efiSysMountPoint = "/boot/efi";
679 # Define on which hard drive you want to install Grub.
680 # boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only
681EOF
682 }
683
684 my $networkingDhcpConfig = generateNetworkingDhcpConfig();
685
686 my $xserverConfig = generateXserverConfig();
687
688 (my $desktopConfiguration = <<EOF)=~s/^/ /gm;
689@desktopConfiguration@
690EOF
691
692 write_file($fn, <<EOF);
693@configuration@
694EOF
695 print STDERR "For more hardware-specific settings, see https://github.com/NixOS/nixos-hardware.\n"
696 } else {
697 print STDERR "warning: not overwriting existing $fn\n";
698 }
699}
700
701# workaround for a bug in substituteAll