2013-10-11 12:44:32 +00:00
|
|
|
|
#! @perl@
|
2008-01-30 14:16:38 +00:00
|
|
|
|
|
2016-05-25 12:56:28 +00:00
|
|
|
|
use strict;
|
2014-05-08 19:00:06 +00:00
|
|
|
|
use Cwd 'abs_path';
|
2008-01-30 14:16:38 +00:00
|
|
|
|
use File::Spec;
|
2013-10-11 12:44:32 +00:00
|
|
|
|
use File::Path;
|
2008-01-30 14:16:38 +00:00
|
|
|
|
use File::Basename;
|
2013-10-11 12:44:32 +00:00
|
|
|
|
use File::Slurp;
|
2014-05-08 19:00:06 +00:00
|
|
|
|
use File::stat;
|
2013-10-11 12:44:32 +00:00
|
|
|
|
|
2017-10-30 21:58:37 +00:00
|
|
|
|
umask(0022);
|
2013-10-11 12:44:32 +00:00
|
|
|
|
|
2013-10-11 15:17:26 +00:00
|
|
|
|
sub uniq {
|
|
|
|
|
my %seen;
|
|
|
|
|
my @res = ();
|
|
|
|
|
foreach my $s (@_) {
|
|
|
|
|
if (!defined $seen{$s}) {
|
|
|
|
|
$seen{$s} = 1;
|
|
|
|
|
push @res, $s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return @res;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-31 16:18:13 +00:00
|
|
|
|
sub runCommand {
|
|
|
|
|
my ($cmd) = @_;
|
2014-08-30 23:30:56 +00:00
|
|
|
|
open FILE, "$cmd 2>&1 |" or die "Failed to execute: $cmd\n";
|
2014-08-31 16:18:13 +00:00
|
|
|
|
my @ret = <FILE>;
|
|
|
|
|
close FILE;
|
|
|
|
|
return ($?, @ret);
|
|
|
|
|
}
|
2013-10-11 15:17:26 +00:00
|
|
|
|
|
2013-10-11 12:44:32 +00:00
|
|
|
|
# Process the command line.
|
|
|
|
|
my $outDir = "/etc/nixos";
|
2013-10-13 13:44:50 +00:00
|
|
|
|
my $rootDir = ""; # = /
|
|
|
|
|
my $force = 0;
|
2013-10-23 13:55:27 +00:00
|
|
|
|
my $noFilesystems = 0;
|
2013-10-23 14:42:34 +00:00
|
|
|
|
my $showHardwareConfig = 0;
|
2013-10-11 12:44:32 +00:00
|
|
|
|
|
|
|
|
|
for (my $n = 0; $n < scalar @ARGV; $n++) {
|
|
|
|
|
my $arg = $ARGV[$n];
|
|
|
|
|
if ($arg eq "--help") {
|
|
|
|
|
exec "man nixos-generate-config" or die;
|
|
|
|
|
}
|
|
|
|
|
elsif ($arg eq "--dir") {
|
|
|
|
|
$n++;
|
|
|
|
|
$outDir = $ARGV[$n];
|
|
|
|
|
die "$0: ‘--dir’ requires an argument\n" unless defined $outDir;
|
|
|
|
|
}
|
2013-10-13 13:44:50 +00:00
|
|
|
|
elsif ($arg eq "--root") {
|
|
|
|
|
$n++;
|
|
|
|
|
$rootDir = $ARGV[$n];
|
|
|
|
|
die "$0: ‘--root’ requires an argument\n" unless defined $rootDir;
|
2022-03-18 21:02:49 +00:00
|
|
|
|
die "$0: no need to specify `/` with `--root`, it is the default\n" if $rootDir eq "/";
|
2013-10-13 13:44:50 +00:00
|
|
|
|
$rootDir =~ s/\/*$//; # remove trailing slashes
|
2022-02-20 09:08:35 +00:00
|
|
|
|
$rootDir = File::Spec->rel2abs($rootDir); # resolve absolute path
|
2013-10-13 13:44:50 +00:00
|
|
|
|
}
|
|
|
|
|
elsif ($arg eq "--force") {
|
|
|
|
|
$force = 1;
|
|
|
|
|
}
|
2013-10-23 13:55:27 +00:00
|
|
|
|
elsif ($arg eq "--no-filesystems") {
|
|
|
|
|
$noFilesystems = 1;
|
|
|
|
|
}
|
2013-10-23 14:42:34 +00:00
|
|
|
|
elsif ($arg eq "--show-hardware-config") {
|
|
|
|
|
$showHardwareConfig = 1;
|
|
|
|
|
}
|
2013-10-11 12:44:32 +00:00
|
|
|
|
else {
|
|
|
|
|
die "$0: unrecognized argument ‘$arg’\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-01-30 14:16:38 +00:00
|
|
|
|
|
|
|
|
|
|
2009-08-04 08:50:02 +00:00
|
|
|
|
my @attrs = ();
|
2008-01-30 14:16:38 +00:00
|
|
|
|
my @kernelModules = ();
|
|
|
|
|
my @initrdKernelModules = ();
|
2016-05-25 12:56:28 +00:00
|
|
|
|
my @initrdAvailableKernelModules = ();
|
2010-12-09 19:08:33 +00:00
|
|
|
|
my @modulePackages = ();
|
2015-07-13 16:08:23 +00:00
|
|
|
|
my @imports;
|
2008-01-30 14:16:38 +00:00
|
|
|
|
|
|
|
|
|
|
2008-02-08 15:59:15 +00:00
|
|
|
|
sub debug {
|
|
|
|
|
return unless defined $ENV{"DEBUG"};
|
|
|
|
|
print STDERR @_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-06-14 18:12:45 +00:00
|
|
|
|
# nixpkgs.system
|
2023-06-11 17:28:51 +00:00
|
|
|
|
push @attrs, "nixpkgs.hostPlatform = lib.mkDefault \"@hostPlatformSystem@\";";
|
2022-06-14 18:12:45 +00:00
|
|
|
|
|
|
|
|
|
|
2013-10-11 13:43:04 +00:00
|
|
|
|
my $cpuinfo = read_file "/proc/cpuinfo";
|
2008-01-30 14:16:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub hasCPUFeature {
|
|
|
|
|
my $feature = shift;
|
|
|
|
|
return $cpuinfo =~ /^flags\s*:.* $feature( |$)/m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-11-15 20:18:05 +00:00
|
|
|
|
sub cpuManufacturer {
|
|
|
|
|
my $id = shift;
|
|
|
|
|
return $cpuinfo =~ /^vendor_id\s*:.* $id$/m;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-30 14:16:38 +00:00
|
|
|
|
|
2017-01-02 16:20:28 +00:00
|
|
|
|
# Determine CPU governor to use
|
|
|
|
|
if (-e "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors") {
|
|
|
|
|
my $governors = read_file("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors");
|
|
|
|
|
# ondemand governor is not available on sandy bridge or later Intel CPUs
|
|
|
|
|
my @desired_governors = ("ondemand", "powersave");
|
|
|
|
|
my $e;
|
|
|
|
|
|
|
|
|
|
foreach $e (@desired_governors) {
|
|
|
|
|
if (index($governors, $e) != -1) {
|
2019-01-03 11:57:49 +00:00
|
|
|
|
last if (push @attrs, "powerManagement.cpuFreqGovernor = lib.mkDefault \"$e\";");
|
2017-01-02 16:20:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-30 14:16:38 +00:00
|
|
|
|
# Virtualization support?
|
|
|
|
|
push @kernelModules, "kvm-intel" if hasCPUFeature "vmx";
|
|
|
|
|
push @kernelModules, "kvm-amd" if hasCPUFeature "svm";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Look at the PCI devices and add necessary modules. Note that most
|
|
|
|
|
# modules are auto-detected so we don't need to list them here.
|
|
|
|
|
# However, some are needed in the initrd to boot the system.
|
|
|
|
|
|
2011-03-18 13:52:09 +00:00
|
|
|
|
my $videoDriver;
|
2008-01-30 14:32:02 +00:00
|
|
|
|
|
2008-01-30 14:16:38 +00:00
|
|
|
|
sub pciCheck {
|
|
|
|
|
my $path = shift;
|
2014-04-08 13:13:27 +00:00
|
|
|
|
my $vendor = read_file "$path/vendor"; chomp $vendor;
|
|
|
|
|
my $device = read_file "$path/device"; chomp $device;
|
|
|
|
|
my $class = read_file "$path/class"; chomp $class;
|
2013-10-11 12:44:32 +00:00
|
|
|
|
|
2008-01-30 14:16:38 +00:00
|
|
|
|
my $module;
|
|
|
|
|
if (-e "$path/driver/module") {
|
|
|
|
|
$module = basename `readlink -f $path/driver/module`;
|
|
|
|
|
chomp $module;
|
|
|
|
|
}
|
2013-10-11 12:44:32 +00:00
|
|
|
|
|
2008-02-08 15:59:15 +00:00
|
|
|
|
debug "$path: $vendor $device $class";
|
|
|
|
|
debug " $module" if defined $module;
|
|
|
|
|
debug "\n";
|
2008-01-30 14:16:38 +00:00
|
|
|
|
|
|
|
|
|
if (defined $module) {
|
|
|
|
|
# See the bottom of http://pciids.sourceforge.net/pci.ids for
|
|
|
|
|
# device classes.
|
|
|
|
|
if (# Mass-storage controller. Definitely important.
|
|
|
|
|
$class =~ /^0x01/ ||
|
|
|
|
|
|
|
|
|
|
# Firewire controller. A disk might be attached.
|
|
|
|
|
$class =~ /^0x0c00/ ||
|
|
|
|
|
|
|
|
|
|
# USB controller. Needed if we want to use the
|
|
|
|
|
# keyboard when things go wrong in the initrd.
|
|
|
|
|
$class =~ /^0x0c03/
|
|
|
|
|
)
|
|
|
|
|
{
|
2013-10-13 13:41:58 +00:00
|
|
|
|
push @initrdAvailableKernelModules, $module;
|
2008-01-30 14:16:38 +00:00
|
|
|
|
}
|
2008-01-30 14:32:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-09 19:08:33 +00:00
|
|
|
|
# broadcom STA driver (wl.ko)
|
|
|
|
|
# list taken from http://www.broadcom.com/docs/linux_sta/README.txt
|
|
|
|
|
if ($vendor eq "0x14e4" &&
|
|
|
|
|
($device eq "0x4311" || $device eq "0x4312" || $device eq "0x4313" ||
|
|
|
|
|
$device eq "0x4315" || $device eq "0x4327" || $device eq "0x4328" ||
|
|
|
|
|
$device eq "0x4329" || $device eq "0x432a" || $device eq "0x432b" ||
|
|
|
|
|
$device eq "0x432c" || $device eq "0x432d" || $device eq "0x4353" ||
|
2014-05-08 13:22:01 +00:00
|
|
|
|
$device eq "0x4357" || $device eq "0x4358" || $device eq "0x4359" ||
|
|
|
|
|
$device eq "0x4331" || $device eq "0x43a0" || $device eq "0x43b1"
|
|
|
|
|
) )
|
2010-12-09 19:08:33 +00:00
|
|
|
|
{
|
2016-01-25 06:55:42 +00:00
|
|
|
|
push @modulePackages, "config.boot.kernelPackages.broadcom_sta";
|
2010-12-09 19:08:33 +00:00
|
|
|
|
push @kernelModules, "wl";
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-20 22:33:28 +00:00
|
|
|
|
# broadcom FullMac driver
|
|
|
|
|
# list taken from
|
|
|
|
|
# https://wireless.wiki.kernel.org/en/users/Drivers/brcm80211#brcmfmac
|
|
|
|
|
if ($vendor eq "0x14e4" &&
|
|
|
|
|
($device eq "0x43a3" || $device eq "0x43df" || $device eq "0x43ec" ||
|
|
|
|
|
$device eq "0x43d3" || $device eq "0x43d9" || $device eq "0x43e9" ||
|
|
|
|
|
$device eq "0x43ba" || $device eq "0x43bb" || $device eq "0x43bc" ||
|
|
|
|
|
$device eq "0xaa52" || $device eq "0x43ca" || $device eq "0x43cb" ||
|
|
|
|
|
$device eq "0x43cc" || $device eq "0x43c3" || $device eq "0x43c4" ||
|
|
|
|
|
$device eq "0x43c5"
|
|
|
|
|
) )
|
|
|
|
|
{
|
|
|
|
|
# we need e.g. brcmfmac43602-pcie.bin
|
2020-04-20 14:57:17 +00:00
|
|
|
|
push @imports, "(modulesPath + \"/hardware/network/broadcom-43xx.nix\")";
|
2015-09-20 22:33:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-22 19:40:41 +00:00
|
|
|
|
# In case this is a virtio scsi device, we need to explicitly make this available.
|
2021-05-17 12:11:37 +00:00
|
|
|
|
if ($vendor eq "0x1af4" && ($device eq "0x1004" || $device eq "0x1048") ) {
|
2020-06-22 19:40:41 +00:00
|
|
|
|
push @initrdAvailableKernelModules, "virtio_scsi";
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-30 14:32:02 +00:00
|
|
|
|
# Can't rely on $module here, since the module may not be loaded
|
|
|
|
|
# due to missing firmware. Ideally we would check modules.pcimap
|
|
|
|
|
# here.
|
2009-08-04 08:50:02 +00:00
|
|
|
|
push @attrs, "networking.enableIntel2200BGFirmware = true;" if
|
2009-01-25 15:48:59 +00:00
|
|
|
|
$vendor eq "0x8086" &&
|
2008-01-30 14:32:02 +00:00
|
|
|
|
($device eq "0x1043" || $device eq "0x104f" || $device eq "0x4220" ||
|
|
|
|
|
$device eq "0x4221" || $device eq "0x4223" || $device eq "0x4224");
|
2008-01-30 14:50:25 +00:00
|
|
|
|
|
2009-08-04 08:50:02 +00:00
|
|
|
|
push @attrs, "networking.enableIntel3945ABGFirmware = true;" if
|
2009-01-25 15:48:59 +00:00
|
|
|
|
$vendor eq "0x8086" &&
|
2008-02-04 10:39:06 +00:00
|
|
|
|
($device eq "0x4229" || $device eq "0x4230" ||
|
|
|
|
|
$device eq "0x4222" || $device eq "0x4227");
|
|
|
|
|
|
2008-01-30 14:53:06 +00:00
|
|
|
|
# Assume that all NVIDIA cards are supported by the NVIDIA driver.
|
|
|
|
|
# There may be exceptions (e.g. old cards).
|
2014-04-08 13:13:27 +00:00
|
|
|
|
# FIXME: do we want to enable an unfree driver here?
|
2014-05-08 18:20:12 +00:00
|
|
|
|
#$videoDriver = "nvidia" if $vendor eq "0x10de" && $class =~ /^0x03/;
|
2008-01-30 14:16:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach my $path (glob "/sys/bus/pci/devices/*") {
|
|
|
|
|
pciCheck $path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Idem for USB devices.
|
|
|
|
|
|
|
|
|
|
sub usbCheck {
|
|
|
|
|
my $path = shift;
|
2014-04-08 13:13:27 +00:00
|
|
|
|
my $class = read_file "$path/bInterfaceClass"; chomp $class;
|
|
|
|
|
my $subclass = read_file "$path/bInterfaceSubClass"; chomp $subclass;
|
|
|
|
|
my $protocol = read_file "$path/bInterfaceProtocol"; chomp $protocol;
|
2008-01-30 14:16:38 +00:00
|
|
|
|
|
|
|
|
|
my $module;
|
|
|
|
|
if (-e "$path/driver/module") {
|
|
|
|
|
$module = basename `readlink -f $path/driver/module`;
|
|
|
|
|
chomp $module;
|
|
|
|
|
}
|
2013-10-11 12:44:32 +00:00
|
|
|
|
|
2008-02-08 15:59:15 +00:00
|
|
|
|
debug "$path: $class $subclass $protocol";
|
|
|
|
|
debug " $module" if defined $module;
|
|
|
|
|
debug "\n";
|
2013-10-11 12:44:32 +00:00
|
|
|
|
|
2008-01-30 14:16:38 +00:00
|
|
|
|
if (defined $module) {
|
|
|
|
|
if (# Mass-storage controller. Definitely important.
|
|
|
|
|
$class eq "08" ||
|
|
|
|
|
|
|
|
|
|
# Keyboard. Needed if we want to use the
|
|
|
|
|
# keyboard when things go wrong in the initrd.
|
|
|
|
|
($class eq "03" && $protocol eq "01")
|
|
|
|
|
)
|
|
|
|
|
{
|
2013-10-13 13:41:58 +00:00
|
|
|
|
push @initrdAvailableKernelModules, $module;
|
2008-01-30 14:16:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach my $path (glob "/sys/bus/usb/devices/*") {
|
|
|
|
|
if (-e "$path/bInterfaceClass") {
|
|
|
|
|
usbCheck $path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-10-16 06:38:41 +00:00
|
|
|
|
# Add the modules for all block and MMC devices.
|
|
|
|
|
foreach my $path (glob "/sys/class/{block,mmc_host}/*") {
|
2010-01-06 20:09:53 +00:00
|
|
|
|
my $module;
|
|
|
|
|
if (-e "$path/device/driver/module") {
|
|
|
|
|
$module = basename `readlink -f $path/device/driver/module`;
|
|
|
|
|
chomp $module;
|
2013-10-13 13:41:58 +00:00
|
|
|
|
push @initrdAvailableKernelModules, $module;
|
2010-01-06 20:09:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-10 19:12:01 +00:00
|
|
|
|
# Add bcache module, if needed.
|
|
|
|
|
my @bcacheDevices = glob("/dev/bcache*");
|
|
|
|
|
if (scalar @bcacheDevices > 0) {
|
|
|
|
|
push @initrdAvailableKernelModules, "bcache";
|
|
|
|
|
}
|
2010-01-06 20:09:53 +00:00
|
|
|
|
|
2019-06-10 19:59:01 +00:00
|
|
|
|
# Prevent unbootable systems if LVM snapshots are present at boot time.
|
|
|
|
|
if (`lsblk -o TYPE` =~ "lvm") {
|
|
|
|
|
push @initrdKernelModules, "dm-snapshot";
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-20 01:48:59 +00:00
|
|
|
|
my $virt = `@detectvirt@`;
|
2014-04-30 09:17:30 +00:00
|
|
|
|
chomp $virt;
|
2014-03-30 15:26:43 +00:00
|
|
|
|
|
|
|
|
|
|
2012-03-16 01:57:23 +00:00
|
|
|
|
# Check if we're a VirtualBox guest. If so, enable the guest
|
|
|
|
|
# additions.
|
2014-04-30 09:17:30 +00:00
|
|
|
|
if ($virt eq "oracle") {
|
2015-08-15 14:33:37 +00:00
|
|
|
|
push @attrs, "virtualisation.virtualbox.guest.enable = true;"
|
2012-03-16 01:57:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-29 14:00:39 +00:00
|
|
|
|
# Check if we're a Parallels guest. If so, enable the guest additions.
|
|
|
|
|
# It is blocked by https://github.com/systemd/systemd/pull/23859
|
|
|
|
|
if ($virt eq "parallels") {
|
|
|
|
|
push @attrs, "hardware.parallels.enable = true;";
|
|
|
|
|
push @attrs, "nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ \"prl-tools\" ];";
|
|
|
|
|
}
|
2012-03-16 01:57:23 +00:00
|
|
|
|
|
2014-03-30 15:26:43 +00:00
|
|
|
|
# Likewise for QEMU.
|
2014-04-30 09:17:30 +00:00
|
|
|
|
if ($virt eq "qemu" || $virt eq "kvm" || $virt eq "bochs") {
|
2020-04-20 14:57:17 +00:00
|
|
|
|
push @imports, "(modulesPath + \"/profiles/qemu-guest.nix\")";
|
2014-03-30 15:26:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 02:46:27 +00:00
|
|
|
|
# Also for Hyper-V.
|
|
|
|
|
if ($virt eq "microsoft") {
|
2018-09-28 14:10:31 +00:00
|
|
|
|
push @attrs, "virtualisation.hypervGuest.enable = true;"
|
2017-02-05 02:46:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-30 15:26:43 +00:00
|
|
|
|
|
2015-07-13 16:08:23 +00:00
|
|
|
|
# Pull in NixOS configuration for containers.
|
|
|
|
|
if ($virt eq "systemd-nspawn") {
|
|
|
|
|
push @attrs, "boot.isContainer = true;";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-03-13 19:04:21 +00:00
|
|
|
|
# Check if we're on bare metal, not in a VM/container.
|
|
|
|
|
if ($virt eq "none") {
|
|
|
|
|
# Provide firmware for devices that are not detected by this script.
|
|
|
|
|
push @imports, "(modulesPath + \"/installer/scan/not-detected.nix\")";
|
2015-07-13 16:08:23 +00:00
|
|
|
|
|
2023-03-13 19:04:21 +00:00
|
|
|
|
# Update the microcode.
|
|
|
|
|
push @attrs, "hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;" if cpuManufacturer "AuthenticAMD";
|
|
|
|
|
push @attrs, "hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;" if cpuManufacturer "GenuineIntel";
|
|
|
|
|
}
|
2015-07-13 16:08:23 +00:00
|
|
|
|
|
2014-05-08 19:00:06 +00:00
|
|
|
|
# For a device name like /dev/sda1, find a more stable path like
|
|
|
|
|
# /dev/disk/by-uuid/X or /dev/disk/by-label/Y.
|
|
|
|
|
sub findStableDevPath {
|
|
|
|
|
my ($dev) = @_;
|
|
|
|
|
return $dev if substr($dev, 0, 1) ne "/";
|
|
|
|
|
return $dev unless -e $dev;
|
|
|
|
|
|
|
|
|
|
my $st = stat($dev) or return $dev;
|
|
|
|
|
|
2023-05-16 00:41:10 +00:00
|
|
|
|
foreach my $dev2 (glob("/dev/stratis/*/*"), glob("/dev/disk/by-uuid/*"), glob("/dev/mapper/*"), glob("/dev/disk/by-label/*")) {
|
2014-05-08 19:00:06 +00:00
|
|
|
|
my $st2 = stat($dev2) or next;
|
|
|
|
|
return $dev2 if $st->rdev == $st2->rdev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $dev;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 02:46:27 +00:00
|
|
|
|
push @attrs, "services.xserver.videoDrivers = [ \"$videoDriver\" ];" if $videoDriver;
|
2014-05-08 19:00:06 +00:00
|
|
|
|
|
2013-10-11 15:17:26 +00:00
|
|
|
|
# Generate the swapDevices option from the currently activated swap
|
|
|
|
|
# devices.
|
2018-11-06 16:32:54 +00:00
|
|
|
|
my @swaps = read_file("/proc/swaps", err_mode => 'carp');
|
2013-10-11 14:05:31 +00:00
|
|
|
|
my @swapDevices;
|
2018-11-06 16:32:54 +00:00
|
|
|
|
if (@swaps) {
|
|
|
|
|
shift @swaps;
|
|
|
|
|
foreach my $swap (@swaps) {
|
2019-06-10 18:27:04 +00:00
|
|
|
|
my @fields = split ' ', $swap;
|
|
|
|
|
my $swapFilename = $fields[0];
|
|
|
|
|
my $swapType = $fields[1];
|
|
|
|
|
next unless -e $swapFilename;
|
|
|
|
|
my $dev = findStableDevPath $swapFilename;
|
|
|
|
|
if ($swapType =~ "partition") {
|
2019-12-19 20:03:21 +00:00
|
|
|
|
# zram devices are more likely created by configuration.nix, so
|
|
|
|
|
# ignore them here
|
|
|
|
|
next if ($swapFilename =~ /^\/dev\/zram/);
|
2019-06-10 18:27:04 +00:00
|
|
|
|
push @swapDevices, "{ device = \"$dev\"; }";
|
|
|
|
|
} elsif ($swapType =~ "file") {
|
|
|
|
|
# swap *files* are more likely specified in configuration.nix, so
|
|
|
|
|
# ignore them here.
|
|
|
|
|
} else {
|
|
|
|
|
die "Unsupported swap type: $swapType\n";
|
|
|
|
|
}
|
2018-11-06 16:32:54 +00:00
|
|
|
|
}
|
2013-10-11 14:05:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-10-11 15:17:26 +00:00
|
|
|
|
# Generate the fileSystems option from the currently mounted
|
|
|
|
|
# filesystems.
|
|
|
|
|
sub in {
|
|
|
|
|
my ($d1, $d2) = @_;
|
|
|
|
|
return $d1 eq $d2 || substr($d1, 0, length($d2) + 1) eq "$d2/";
|
|
|
|
|
}
|
2008-01-30 14:16:38 +00:00
|
|
|
|
|
2013-10-11 15:17:26 +00:00
|
|
|
|
my $fileSystems;
|
|
|
|
|
my %fsByDev;
|
2022-07-28 12:34:44 +00:00
|
|
|
|
my $useSwraid = 0;
|
2013-10-11 15:17:26 +00:00
|
|
|
|
foreach my $fs (read_file("/proc/self/mountinfo")) {
|
|
|
|
|
chomp $fs;
|
|
|
|
|
my @fields = split / /, $fs;
|
|
|
|
|
my $mountPoint = $fields[4];
|
2019-02-03 13:33:31 +00:00
|
|
|
|
$mountPoint =~ s/\\040/ /g; # account for mount points with spaces in the name (\040 is the escape character)
|
|
|
|
|
$mountPoint =~ s/\\011/\t/g; # account for mount points with tabs in the name (\011 is the escape character)
|
2013-10-11 15:17:26 +00:00
|
|
|
|
next unless -d $mountPoint;
|
|
|
|
|
my @mountOptions = split /,/, $fields[5];
|
|
|
|
|
|
2013-10-13 13:44:50 +00:00
|
|
|
|
next if !in($mountPoint, $rootDir);
|
|
|
|
|
$mountPoint = substr($mountPoint, length($rootDir)); # strip the root directory (e.g. /mnt)
|
|
|
|
|
$mountPoint = "/" if $mountPoint eq "";
|
|
|
|
|
|
2013-10-11 15:17:26 +00:00
|
|
|
|
# Skip special filesystems.
|
2014-02-19 15:56:25 +00:00
|
|
|
|
next if in($mountPoint, "/proc") || in($mountPoint, "/dev") || in($mountPoint, "/sys") || in($mountPoint, "/run") || $mountPoint eq "/var/lib/nfs/rpc_pipefs";
|
2013-10-11 15:17:26 +00:00
|
|
|
|
|
|
|
|
|
# Skip the optional fields.
|
|
|
|
|
my $n = 6; $n++ while $fields[$n] ne "-"; $n++;
|
|
|
|
|
my $fsType = $fields[$n];
|
|
|
|
|
my $device = $fields[$n + 1];
|
|
|
|
|
my @superOptions = split /,/, $fields[$n + 2];
|
2019-02-03 13:33:31 +00:00
|
|
|
|
$device =~ s/\\040/ /g; # account for devices with spaces in the name (\040 is the escape character)
|
|
|
|
|
$device =~ s/\\011/\t/g; # account for mount points with tabs in the name (\011 is the escape character)
|
2013-10-11 15:17:26 +00:00
|
|
|
|
|
|
|
|
|
# Skip the read-only bind-mount on /nix/store.
|
|
|
|
|
next if $mountPoint eq "/nix/store" && (grep { $_ eq "rw" } @superOptions) && (grep { $_ eq "ro" } @mountOptions);
|
|
|
|
|
|
|
|
|
|
# Maybe this is a bind-mount of a filesystem we saw earlier?
|
|
|
|
|
if (defined $fsByDev{$fields[2]}) {
|
2015-07-13 15:55:49 +00:00
|
|
|
|
# Make sure this isn't a btrfs subvolume.
|
2021-11-20 01:48:59 +00:00
|
|
|
|
my $msg = `@btrfs@ subvol show $rootDir$mountPoint`;
|
2015-07-13 15:55:49 +00:00
|
|
|
|
if ($? != 0 || $msg =~ /ERROR:/s) {
|
2014-08-30 23:30:56 +00:00
|
|
|
|
my $path = $fields[3]; $path = "" if $path eq "/";
|
|
|
|
|
my $base = $fsByDev{$fields[2]};
|
|
|
|
|
$base = "" if $base eq "/";
|
|
|
|
|
$fileSystems .= <<EOF;
|
2013-10-11 15:24:30 +00:00
|
|
|
|
fileSystems.\"$mountPoint\" =
|
2014-05-08 19:02:40 +00:00
|
|
|
|
{ device = \"$base$path\";
|
2013-10-11 15:24:30 +00:00
|
|
|
|
fsType = \"none\";
|
2015-10-21 17:37:14 +00:00
|
|
|
|
options = \[ \"bind\" \];
|
2013-10-11 15:24:30 +00:00
|
|
|
|
};
|
2013-10-11 15:17:26 +00:00
|
|
|
|
|
|
|
|
|
EOF
|
2014-08-30 23:30:56 +00:00
|
|
|
|
next;
|
|
|
|
|
}
|
2013-10-11 15:17:26 +00:00
|
|
|
|
}
|
2013-10-11 15:24:30 +00:00
|
|
|
|
$fsByDev{$fields[2]} = $mountPoint;
|
|
|
|
|
|
|
|
|
|
# We don't know how to handle FUSE filesystems.
|
|
|
|
|
if ($fsType eq "fuseblk" || $fsType eq "fuse") {
|
|
|
|
|
print STDERR "warning: don't know how to emit ‘fileSystem’ option for FUSE filesystem ‘$mountPoint’\n";
|
|
|
|
|
next;
|
|
|
|
|
}
|
2013-10-11 15:17:26 +00:00
|
|
|
|
|
|
|
|
|
# Is this a mount of a loopback device?
|
|
|
|
|
my @extraOptions;
|
|
|
|
|
if ($device =~ /\/dev\/loop(\d+)/) {
|
|
|
|
|
my $loopnr = $1;
|
|
|
|
|
my $backer = read_file "/sys/block/loop$loopnr/loop/backing_file";
|
|
|
|
|
if (defined $backer) {
|
|
|
|
|
chomp $backer;
|
|
|
|
|
$device = $backer;
|
|
|
|
|
push @extraOptions, "loop";
|
2008-01-30 14:16:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-11 15:17:26 +00:00
|
|
|
|
|
2014-08-31 16:18:13 +00:00
|
|
|
|
# Is this a btrfs filesystem?
|
|
|
|
|
if ($fsType eq "btrfs") {
|
2021-11-20 01:48:59 +00:00
|
|
|
|
my ($status, @info) = runCommand("@btrfs@ subvol show $rootDir$mountPoint");
|
2017-10-07 01:31:59 +00:00
|
|
|
|
if ($status != 0 || join("", @info) =~ /ERROR:/) {
|
2015-05-03 09:15:03 +00:00
|
|
|
|
die "Failed to retrieve subvolume info for $mountPoint\n";
|
2014-08-31 16:18:13 +00:00
|
|
|
|
}
|
2017-10-11 00:22:57 +00:00
|
|
|
|
my @ids = join("\n", @info) =~ m/^(?!\/\n).*Subvolume ID:[ \t\n]*([0-9]+)/s;
|
2014-08-30 22:33:44 +00:00
|
|
|
|
if ($#ids > 0) {
|
2014-08-31 16:18:13 +00:00
|
|
|
|
die "Btrfs subvol name for $mountPoint listed multiple times in mount\n"
|
2014-08-30 22:33:44 +00:00
|
|
|
|
} elsif ($#ids == 0) {
|
2017-10-07 01:31:59 +00:00
|
|
|
|
my @paths = join("", @info) =~ m/^([^\n]*)/;
|
2014-08-30 22:33:44 +00:00
|
|
|
|
if ($#paths > 0) {
|
|
|
|
|
die "Btrfs returned multiple paths for a single subvolume id, mountpoint $mountPoint\n";
|
|
|
|
|
} elsif ($#paths != 0) {
|
|
|
|
|
die "Btrfs did not return a path for the subvolume at $mountPoint\n";
|
|
|
|
|
}
|
|
|
|
|
push @extraOptions, "subvol=$paths[0]";
|
2014-08-31 16:18:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 00:41:10 +00:00
|
|
|
|
# is this a stratis fs?
|
|
|
|
|
my $stableDevPath = findStableDevPath $device;
|
|
|
|
|
my $stratisPool;
|
|
|
|
|
if ($stableDevPath =~ qr#/dev/stratis/(.*)/.*#) {
|
|
|
|
|
my $poolName = $1;
|
|
|
|
|
my ($header, @lines) = split "\n", qx/stratis pool list/;
|
|
|
|
|
my $uuidIndex = index $header, 'UUID';
|
|
|
|
|
my ($line) = grep /^$poolName /, @lines;
|
|
|
|
|
$stratisPool = substr $line, $uuidIndex - 32, 36;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 14:16:34 +00:00
|
|
|
|
# Don't emit tmpfs entry for /tmp, because it most likely comes from the
|
2022-12-04 20:44:47 +00:00
|
|
|
|
# boot.tmp.useTmpfs option in configuration.nix (managed declaratively).
|
2019-06-16 14:16:34 +00:00
|
|
|
|
next if ($mountPoint eq "/tmp" && $fsType eq "tmpfs");
|
|
|
|
|
|
2013-10-11 15:17:26 +00:00
|
|
|
|
# Emit the filesystem.
|
|
|
|
|
$fileSystems .= <<EOF;
|
2013-10-11 15:24:30 +00:00
|
|
|
|
fileSystems.\"$mountPoint\" =
|
2023-05-16 00:41:10 +00:00
|
|
|
|
{ device = \"$stableDevPath\";
|
2013-10-11 15:24:30 +00:00
|
|
|
|
fsType = \"$fsType\";
|
2014-02-19 16:13:21 +00:00
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
if (scalar @extraOptions > 0) {
|
2016-05-25 13:34:37 +00:00
|
|
|
|
$fileSystems .= <<EOF;
|
2015-10-21 17:37:14 +00:00
|
|
|
|
options = \[ ${\join " ", map { "\"" . $_ . "\"" } uniq(@extraOptions)} \];
|
2014-02-19 16:13:21 +00:00
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 00:41:10 +00:00
|
|
|
|
if ($stratisPool) {
|
|
|
|
|
$fileSystems .= <<EOF;
|
|
|
|
|
stratis.poolUuid = "$stratisPool";
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 16:13:21 +00:00
|
|
|
|
$fileSystems .= <<EOF;
|
2013-10-11 15:24:30 +00:00
|
|
|
|
};
|
2013-10-11 15:17:26 +00:00
|
|
|
|
|
|
|
|
|
EOF
|
2016-05-25 13:34:37 +00:00
|
|
|
|
|
|
|
|
|
# If this filesystem is on a LUKS device, then add a
|
|
|
|
|
# boot.initrd.luks.devices entry.
|
|
|
|
|
if (-e $device) {
|
|
|
|
|
my $deviceName = basename(abs_path($device));
|
2022-07-28 12:34:44 +00:00
|
|
|
|
my $dmUuid = read_file("/sys/class/block/$deviceName/dm/uuid", err_mode => 'quiet');
|
|
|
|
|
if ($dmUuid =~ /^CRYPT-LUKS/)
|
2016-05-25 13:34:37 +00:00
|
|
|
|
{
|
|
|
|
|
my @slaves = glob("/sys/class/block/$deviceName/slaves/*");
|
|
|
|
|
if (scalar @slaves == 1) {
|
|
|
|
|
my $slave = "/dev/" . basename($slaves[0]);
|
|
|
|
|
if (-e $slave) {
|
|
|
|
|
my $dmName = read_file("/sys/class/block/$deviceName/dm/name");
|
|
|
|
|
chomp $dmName;
|
2019-01-19 20:44:05 +00:00
|
|
|
|
# Ensure to add an entry only once
|
|
|
|
|
my $luksDevice = " boot.initrd.luks.devices.\"$dmName\".device";
|
|
|
|
|
if ($fileSystems !~ /^\Q$luksDevice\E/m) {
|
|
|
|
|
$fileSystems .= "$luksDevice = \"${\(findStableDevPath $slave)}\";\n\n";
|
|
|
|
|
}
|
2016-05-25 13:34:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-28 12:34:44 +00:00
|
|
|
|
if (-e "/sys/class/block/$deviceName/md/uuid") {
|
|
|
|
|
$useSwraid = 1;
|
|
|
|
|
}
|
2016-05-25 13:34:37 +00:00
|
|
|
|
}
|
2008-01-30 14:16:38 +00:00
|
|
|
|
}
|
2022-07-28 12:34:44 +00:00
|
|
|
|
if ($useSwraid) {
|
2023-07-10 18:20:08 +00:00
|
|
|
|
push @attrs, "boot.swraid.enable = true;\n\n";
|
2022-07-28 12:34:44 +00:00
|
|
|
|
}
|
2008-01-30 14:16:38 +00:00
|
|
|
|
|
2013-10-11 15:17:26 +00:00
|
|
|
|
|
|
|
|
|
# Generate the hardware configuration file.
|
|
|
|
|
|
2016-01-25 06:55:42 +00:00
|
|
|
|
sub toNixStringList {
|
2008-01-30 14:16:38 +00:00
|
|
|
|
my $res = "";
|
|
|
|
|
foreach my $s (@_) {
|
|
|
|
|
$res .= " \"$s\"";
|
|
|
|
|
}
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
2016-01-25 06:55:42 +00:00
|
|
|
|
sub toNixList {
|
|
|
|
|
my $res = "";
|
|
|
|
|
foreach my $s (@_) {
|
|
|
|
|
$res .= " $s";
|
|
|
|
|
}
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
2008-01-30 14:16:38 +00:00
|
|
|
|
|
2009-01-25 15:48:59 +00:00
|
|
|
|
sub multiLineList {
|
|
|
|
|
my $indent = shift;
|
2014-05-08 19:00:06 +00:00
|
|
|
|
return " [ ]" if !@_;
|
2016-05-25 12:56:28 +00:00
|
|
|
|
my $res = "\n${indent}[ ";
|
2013-10-11 14:05:31 +00:00
|
|
|
|
my $first = 1;
|
2009-01-25 15:48:59 +00:00
|
|
|
|
foreach my $s (@_) {
|
2013-10-11 14:05:31 +00:00
|
|
|
|
$res .= "$indent " if !$first;
|
|
|
|
|
$first = 0;
|
|
|
|
|
$res .= "$s\n";
|
2009-01-25 15:48:59 +00:00
|
|
|
|
}
|
2013-10-11 14:05:31 +00:00
|
|
|
|
$res .= "$indent]";
|
2009-01-25 15:48:59 +00:00
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 06:55:42 +00:00
|
|
|
|
my $initrdAvailableKernelModules = toNixStringList(uniq @initrdAvailableKernelModules);
|
2019-06-10 19:59:01 +00:00
|
|
|
|
my $initrdKernelModules = toNixStringList(uniq @initrdKernelModules);
|
2016-01-25 06:55:42 +00:00
|
|
|
|
my $kernelModules = toNixStringList(uniq @kernelModules);
|
|
|
|
|
my $modulePackages = toNixList(uniq @modulePackages);
|
2012-03-16 01:57:23 +00:00
|
|
|
|
|
2013-10-23 13:55:27 +00:00
|
|
|
|
my $fsAndSwap = "";
|
|
|
|
|
if (!$noFilesystems) {
|
2016-05-25 13:34:37 +00:00
|
|
|
|
$fsAndSwap = "\n$fileSystems ";
|
2013-10-23 14:00:39 +00:00
|
|
|
|
$fsAndSwap .= "swapDevices =" . multiLineList(" ", @swapDevices) . ";\n";
|
2013-10-23 13:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-20 02:00:46 +00:00
|
|
|
|
my $networkingDhcpConfig = generateNetworkingDhcpConfig();
|
|
|
|
|
|
2013-10-23 14:42:34 +00:00
|
|
|
|
my $hwConfig = <<EOF;
|
2013-10-11 12:44:32 +00:00
|
|
|
|
# Do not modify this file! It was generated by ‘nixos-generate-config’
|
|
|
|
|
# and may be overwritten by future invocations. Please make changes
|
|
|
|
|
# to /etc/nixos/configuration.nix instead.
|
2020-04-20 14:57:17 +00:00
|
|
|
|
{ config, lib, pkgs, modulesPath, ... }:
|
2010-09-25 09:32:37 +00:00
|
|
|
|
|
2008-01-30 14:16:38 +00:00
|
|
|
|
{
|
2013-10-23 14:00:39 +00:00
|
|
|
|
imports =${\multiLineList(" ", @imports)};
|
2010-09-25 09:32:37 +00:00
|
|
|
|
|
2013-10-13 13:41:58 +00:00
|
|
|
|
boot.initrd.availableKernelModules = [$initrdAvailableKernelModules ];
|
2019-06-10 19:59:01 +00:00
|
|
|
|
boot.initrd.kernelModules = [$initrdKernelModules ];
|
2011-03-18 13:52:09 +00:00
|
|
|
|
boot.kernelModules = [$kernelModules ];
|
|
|
|
|
boot.extraModulePackages = [$modulePackages ];
|
2013-10-23 13:55:27 +00:00
|
|
|
|
$fsAndSwap
|
2021-11-20 02:00:46 +00:00
|
|
|
|
$networkingDhcpConfig
|
2013-10-11 15:17:26 +00:00
|
|
|
|
${\join "", (map { " $_\n" } (uniq @attrs))}}
|
2008-01-30 14:16:38 +00:00
|
|
|
|
EOF
|
2013-10-11 12:44:32 +00:00
|
|
|
|
|
2019-09-24 09:41:12 +00:00
|
|
|
|
sub generateNetworkingDhcpConfig {
|
2022-04-29 22:26:46 +00:00
|
|
|
|
# FIXME disable networking.useDHCP by default when switching to networkd.
|
2019-09-24 09:41:12 +00:00
|
|
|
|
my $config = <<EOF;
|
2022-04-29 22:26:46 +00:00
|
|
|
|
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
|
|
|
|
|
# (the default) this is the recommended approach. When using systemd-networkd it's
|
2022-05-06 14:56:47 +00:00
|
|
|
|
# still possible to use this option, but it's recommended to use it in conjunction
|
|
|
|
|
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
|
2022-04-29 22:26:46 +00:00
|
|
|
|
networking.useDHCP = lib.mkDefault true;
|
2019-09-24 09:41:12 +00:00
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
foreach my $path (glob "/sys/class/net/*") {
|
|
|
|
|
my $dev = basename($path);
|
|
|
|
|
if ($dev ne "lo") {
|
2022-04-29 22:26:46 +00:00
|
|
|
|
$config .= " # networking.interfaces.$dev.useDHCP = lib.mkDefault true;\n";
|
2019-09-24 09:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-13 22:42:34 +00:00
|
|
|
|
sub generateXserverConfig {
|
|
|
|
|
my $xserverEnabled = "@xserverEnabled@";
|
|
|
|
|
|
|
|
|
|
my $config = "";
|
|
|
|
|
if ($xserverEnabled eq "1") {
|
|
|
|
|
$config = <<EOF;
|
|
|
|
|
# Enable the X11 windowing system.
|
|
|
|
|
services.xserver.enable = true;
|
|
|
|
|
EOF
|
|
|
|
|
} else {
|
|
|
|
|
$config = <<EOF;
|
|
|
|
|
# Enable the X11 windowing system.
|
|
|
|
|
# services.xserver.enable = true;
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-11 14:05:31 +00:00
|
|
|
|
|
2013-10-23 14:42:34 +00:00
|
|
|
|
if ($showHardwareConfig) {
|
|
|
|
|
print STDOUT $hwConfig;
|
|
|
|
|
} else {
|
2022-03-18 21:02:49 +00:00
|
|
|
|
if ($outDir eq "/etc/nixos") {
|
|
|
|
|
$outDir = "$rootDir$outDir";
|
|
|
|
|
} else {
|
|
|
|
|
$outDir = File::Spec->rel2abs($outDir);
|
|
|
|
|
$outDir =~ s/\/*$//; # remove trailing slashes
|
|
|
|
|
}
|
2013-10-23 14:42:34 +00:00
|
|
|
|
|
|
|
|
|
my $fn = "$outDir/hardware-configuration.nix";
|
2013-10-11 13:35:41 +00:00
|
|
|
|
print STDERR "writing $fn...\n";
|
2013-10-23 14:42:34 +00:00
|
|
|
|
mkpath($outDir, 0, 0755);
|
|
|
|
|
write_file($fn, $hwConfig);
|
|
|
|
|
|
|
|
|
|
# Generate a basic configuration.nix, unless one already exists.
|
|
|
|
|
$fn = "$outDir/configuration.nix";
|
|
|
|
|
if ($force || ! -e $fn) {
|
|
|
|
|
print STDERR "writing $fn...\n";
|
2013-10-11 13:35:41 +00:00
|
|
|
|
|
2016-05-25 12:56:28 +00:00
|
|
|
|
my $bootLoaderConfig = "";
|
2013-10-23 14:42:34 +00:00
|
|
|
|
if (-e "/sys/firmware/efi/efivars") {
|
|
|
|
|
$bootLoaderConfig = <<EOF;
|
2016-06-01 10:51:33 +00:00
|
|
|
|
# Use the systemd-boot EFI boot loader.
|
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
2013-10-11 13:35:41 +00:00
|
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
2018-07-21 21:10:01 +00:00
|
|
|
|
EOF
|
|
|
|
|
} elsif (-e "/boot/extlinux") {
|
|
|
|
|
$bootLoaderConfig = <<EOF;
|
|
|
|
|
# Use the extlinux boot loader. (NixOS wants to enable GRUB by default)
|
|
|
|
|
boot.loader.grub.enable = false;
|
|
|
|
|
# Enables the generation of /boot/extlinux/extlinux.conf
|
|
|
|
|
boot.loader.generic-extlinux-compatible.enable = true;
|
2013-10-11 13:35:41 +00:00
|
|
|
|
EOF
|
2015-07-13 16:08:23 +00:00
|
|
|
|
} elsif ($virt ne "systemd-nspawn") {
|
2013-10-23 14:42:34 +00:00
|
|
|
|
$bootLoaderConfig = <<EOF;
|
2013-10-11 13:35:41 +00:00
|
|
|
|
# Use the GRUB 2 boot loader.
|
|
|
|
|
boot.loader.grub.enable = true;
|
2016-09-13 17:46:53 +00:00
|
|
|
|
# boot.loader.grub.efiSupport = true;
|
|
|
|
|
# boot.loader.grub.efiInstallAsRemovable = true;
|
|
|
|
|
# boot.loader.efi.efiSysMountPoint = "/boot/efi";
|
2013-10-11 13:35:41 +00:00
|
|
|
|
# Define on which hard drive you want to install Grub.
|
2016-09-13 17:46:53 +00:00
|
|
|
|
# boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only
|
2013-10-11 13:35:41 +00:00
|
|
|
|
EOF
|
2013-10-23 14:42:34 +00:00
|
|
|
|
}
|
2013-10-11 13:35:41 +00:00
|
|
|
|
|
2019-09-24 09:41:12 +00:00
|
|
|
|
my $networkingDhcpConfig = generateNetworkingDhcpConfig();
|
|
|
|
|
|
2021-02-13 22:42:34 +00:00
|
|
|
|
my $xserverConfig = generateXserverConfig();
|
|
|
|
|
|
2020-10-11 02:44:36 +00:00
|
|
|
|
(my $desktopConfiguration = <<EOF)=~s/^/ /gm;
|
|
|
|
|
@desktopConfiguration@
|
|
|
|
|
EOF
|
|
|
|
|
|
2013-10-23 14:42:34 +00:00
|
|
|
|
write_file($fn, <<EOF);
|
2019-08-07 16:04:18 +00:00
|
|
|
|
@configuration@
|
2013-10-11 13:35:41 +00:00
|
|
|
|
EOF
|
2020-10-03 08:48:39 +00:00
|
|
|
|
print STDERR "For more hardware-specific settings, see https://github.com/NixOS/nixos-hardware.\n"
|
2013-10-23 14:42:34 +00:00
|
|
|
|
} else {
|
|
|
|
|
print STDERR "warning: not overwriting existing $fn\n";
|
|
|
|
|
}
|
2013-10-11 13:35:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-06 10:57:52 +00:00
|
|
|
|
# workaround for a bug in substituteAll
|