Format nix files

This commit is contained in:
Michael Smith 2024-08-19 23:42:25 +02:00
parent d0194a555b
commit 18ad437872
5 changed files with 402 additions and 366 deletions

View File

@ -3,8 +3,7 @@
lib, lib,
inputs, inputs,
... ...
}: }: {
{
imports = [ imports = [
../../modules/installer ../../modules/installer
]; ];

View File

@ -133,13 +133,13 @@
"org/gnome/shell/extensions/arcmenu" = { "org/gnome/shell/extensions/arcmenu" = {
menu-layout = "Windows"; menu-layout = "Windows";
pinned-apps = lib.gvariant.mkArray [ pinned-apps = lib.gvariant.mkArray [
[ (lib.gvariant.mkDictionaryEntry "id" "firefox.desktop") ] [(lib.gvariant.mkDictionaryEntry "id" "firefox.desktop")]
[ (lib.gvariant.mkDictionaryEntry "id" "org.gnome.Geary.desktop") ] [(lib.gvariant.mkDictionaryEntry "id" "org.gnome.Geary.desktop")]
[ (lib.gvariant.mkDictionaryEntry "id" "org.gnome.Calendar.desktop") ] [(lib.gvariant.mkDictionaryEntry "id" "org.gnome.Calendar.desktop")]
[ (lib.gvariant.mkDictionaryEntry "id" "org.gnome.Nautilus.desktop") ] [(lib.gvariant.mkDictionaryEntry "id" "org.gnome.Nautilus.desktop")]
[ (lib.gvariant.mkDictionaryEntry "id" "writer.desktop") ] [(lib.gvariant.mkDictionaryEntry "id" "writer.desktop")]
[ (lib.gvariant.mkDictionaryEntry "id" "calc.desktop") ] [(lib.gvariant.mkDictionaryEntry "id" "calc.desktop")]
[ (lib.gvariant.mkDictionaryEntry "id" "impress.desktop") ] [(lib.gvariant.mkDictionaryEntry "id" "impress.desktop")]
]; ];
}; };
}; };

View File

@ -1,12 +1,19 @@
{ config, lib, options, pkgs, inputs, modulesPath, ... }:
with lib;
let
calamares-nixos-autostart = pkgs.makeAutostartItem { name = "io.calamares.calamares"; package = pkgs.calamares-nixos; };
calamares-extensions-desk-os = pkgs.callPackage ../../packages/calamares-extensions {};
in
{ {
config,
lib,
options,
pkgs,
inputs,
modulesPath,
...
}:
with lib; let
calamares-nixos-autostart = pkgs.makeAutostartItem {
name = "io.calamares.calamares";
package = pkgs.calamares-nixos;
};
calamares-extensions-desk-os = pkgs.callPackage ../../packages/calamares-extensions {};
in {
imports = [ imports = [
./iso-image.nix ./iso-image.nix
(modulesPath + "/profiles/all-hardware.nix") (modulesPath + "/profiles/all-hardware.nix")
@ -17,7 +24,7 @@ in
# boot.loader.timeout = lib.mkForce 0; # boot.loader.timeout = lib.mkForce 0;
# Adds terminus_font for people with HiDPI displays # Adds terminus_font for people with HiDPI displays
console.packages = options.console.packages.default ++ [ pkgs.terminus_font ]; console.packages = options.console.packages.default ++ [pkgs.terminus_font];
# FIXME(m): Disable squashfs compression during development # FIXME(m): Disable squashfs compression during development
isoImage.squashfsCompression = null; isoImage.squashfsCompression = null;
@ -33,7 +40,7 @@ in
# An installation media cannot tolerate a host config defined file # An installation media cannot tolerate a host config defined file
# system layout on a fresh machine, before it has been formatted. # system layout on a fresh machine, before it has been formatted.
swapDevices = mkImageMediaOverride [ ]; swapDevices = mkImageMediaOverride [];
fileSystems = mkImageMediaOverride config.lib.isoFileSystems; fileSystems = mkImageMediaOverride config.lib.isoFileSystems;
boot.postBootCommands = '' boot.postBootCommands = ''
@ -114,7 +121,7 @@ in
]; ];
# Support choosing from any locale # Support choosing from any locale
i18n.supportedLocales = [ "all" ]; i18n.supportedLocales = ["all"];
isoImage.edition = "gnome"; isoImage.edition = "gnome";
@ -136,7 +143,7 @@ in
sleep-inactive-battery-type='nothing' sleep-inactive-battery-type='nothing'
''; '';
extraGSettingsOverridePackages = [ pkgs.gnome.gnome-settings-daemon ]; extraGSettingsOverridePackages = [pkgs.gnome.gnome-settings-daemon];
enable = true; enable = true;
}; };

View File

@ -1,89 +1,88 @@
# This module creates a bootable ISO image containing the given NixOS # This module creates a bootable ISO image containing the given NixOS
# configuration. The derivation for the ISO image will be placed in # configuration. The derivation for the ISO image will be placed in
# config.system.build.isoImage. # config.system.build.isoImage.
{
{ config, lib, pkgs, ... }: config,
lib,
with lib; pkgs,
...
let }:
/** with lib; let
* Given a list of `options`, concats the result of mapping each options /*
* to a menuentry for use in grub.
* *
* * defaults: {name, image, params, initrd} * Given a list of `options`, concats the result of mapping each options
* * options: [ option... ] * to a menuentry for use in grub.
* * option: {name, params, class} *
*/ * * defaults: {name, image, params, initrd}
menuBuilderGrub2 = * * options: [ option... ]
defaults: options: lib.concatStrings * * option: {name, params, class}
*/
menuBuilderGrub2 = defaults: options:
lib.concatStrings
( (
map map
(option: '' (option: ''
menuentry '${defaults.name} ${ menuentry '${defaults.name} ${
# Name appended to menuentry defaults to params if no specific name given. # Name appended to menuentry defaults to params if no specific name given.
option.name or (optionalString (option ? params) "(${option.params})") option.name or (optionalString (option ? params) "(${option.params})")
}' ${optionalString (option ? class) " --class ${option.class}"} { }' ${optionalString (option ? class) " --class ${option.class}"} {
# Fallback to UEFI console for boot, efifb sometimes has difficulties. # Fallback to UEFI console for boot, efifb sometimes has difficulties.
terminal_output console terminal_output console
linux ${defaults.image} \''${isoboot} ${defaults.params} ${ linux ${defaults.image} \''${isoboot} ${defaults.params} ${
option.params or "" option.params or ""
} }
initrd ${defaults.initrd} initrd ${defaults.initrd}
} }
'') '')
options options
) );
;
/** /*
* Builds the default options. *
*/ * Builds the default options.
*/
buildMenuGrub2 = buildMenuAdditionalParamsGrub2 ""; buildMenuGrub2 = buildMenuAdditionalParamsGrub2 "";
targetArch = targetArch =
if config.boot.loader.grub.forcei686 then if config.boot.loader.grub.forcei686
"ia32" then "ia32"
else else pkgs.stdenv.hostPlatform.efiArch;
pkgs.stdenv.hostPlatform.efiArch;
/** /*
* Given params to add to `params`, build a set of default options. *
* Use this one when creating a variant (e.g. hidpi) * Given params to add to `params`, build a set of default options.
*/ * Use this one when creating a variant (e.g. hidpi)
buildMenuAdditionalParamsGrub2 = additional: */
let buildMenuAdditionalParamsGrub2 = additional: let
finalCfg = { finalCfg = {
name = "${config.isoImage.prependToMenuLabel}${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel}"; name = "${config.isoImage.prependToMenuLabel}${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel}";
params = "init=${config.system.build.toplevel}/init ${additional} ${toString config.boot.kernelParams}"; params = "init=${config.system.build.toplevel}/init ${additional} ${toString config.boot.kernelParams}";
image = "/boot/${config.system.boot.loader.kernelFile}"; image = "/boot/${config.system.boot.loader.kernelFile}";
initrd = "/boot/initrd"; initrd = "/boot/initrd";
}; };
in in
menuBuilderGrub2 menuBuilderGrub2
finalCfg finalCfg
[ [
{ class = "installer"; } {class = "installer";}
] ];
;
# Timeout in syslinux is in units of 1/10 of a second. # Timeout in syslinux is in units of 1/10 of a second.
# null means max timeout (35996, just under 1h in 1/10 seconds) # null means max timeout (35996, just under 1h in 1/10 seconds)
# 0 means disable timeout # 0 means disable timeout
syslinuxTimeout = if config.boot.loader.timeout == null then syslinuxTimeout =
35996 if config.boot.loader.timeout == null
else then 35996
config.boot.loader.timeout * 10; else config.boot.loader.timeout * 10;
# Timeout in grub is in seconds. # Timeout in grub is in seconds.
# null means max timeout (infinity) # null means max timeout (infinity)
# 0 means disable timeout # 0 means disable timeout
grubEfiTimeout = if config.boot.loader.timeout == null then grubEfiTimeout =
-1 if config.boot.loader.timeout == null
else then -1
config.boot.loader.timeout; else config.boot.loader.timeout;
# The configuration file for syslinux. # The configuration file for syslinux.
@ -122,23 +121,28 @@ let
APPEND ${toString config.boot.loader.grub.memtest86.params} APPEND ${toString config.boot.loader.grub.memtest86.params}
''; '';
isolinuxCfg = concatStringsSep "\n" isolinuxCfg =
([ baseIsolinuxCfg ] ++ optional config.boot.loader.grub.memtest86.enable isolinuxMemtest86Entry); concatStringsSep "\n"
([baseIsolinuxCfg] ++ optional config.boot.loader.grub.memtest86.enable isolinuxMemtest86Entry);
refindBinary = if targetArch == "x64" || targetArch == "aa64" then "refind_${targetArch}.efi" else null; refindBinary =
if targetArch == "x64" || targetArch == "aa64"
then "refind_${targetArch}.efi"
else null;
# Setup instructions for rEFInd. # Setup instructions for rEFInd.
refind = refind =
if refindBinary != null then if refindBinary != null
'' then ''
# Adds rEFInd to the ISO. # Adds rEFInd to the ISO.
cp -v ${pkgs.refind}/share/refind/${refindBinary} $out/EFI/boot/ cp -v ${pkgs.refind}/share/refind/${refindBinary} $out/EFI/boot/
'' ''
else else "# No refind for ${targetArch}";
"# No refind for ${targetArch}"
;
grubPkgs = if config.boot.loader.grub.forcei686 then pkgs.pkgsi686Linux else pkgs; grubPkgs =
if config.boot.loader.grub.forcei686
then pkgs.pkgsi686Linux
else pkgs;
grubMenuCfg = '' grubMenuCfg = ''
# #
@ -181,234 +185,239 @@ let
fi fi
${ # When there is a theme configured, use it, otherwise use the background image. ${ # When there is a theme configured, use it, otherwise use the background image.
if config.isoImage.grubTheme != null then '' if config.isoImage.grubTheme != null
# Sets theme. then ''
set theme=(\$root)/EFI/boot/grub-theme/theme.txt # Sets theme.
# Load theme fonts set theme=(\$root)/EFI/boot/grub-theme/theme.txt
$(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (\$root)/EFI/boot/grub-theme/%P\n") # Load theme fonts
'' else '' $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (\$root)/EFI/boot/grub-theme/%P\n")
if background_image (\$root)/EFI/boot/efi-background.png; then ''
# Black background means transparent background when there else ''
# is a background image set... This seems undocumented :( if background_image (\$root)/EFI/boot/efi-background.png; then
set color_normal=black/black # Black background means transparent background when there
set color_highlight=white/blue # is a background image set... This seems undocumented :(
else set color_normal=black/black
# Falls back again to proper colors. set color_highlight=white/blue
set menu_color_normal=cyan/blue else
set menu_color_highlight=white/blue # Falls back again to proper colors.
fi set menu_color_normal=cyan/blue
''} set menu_color_highlight=white/blue
fi
''
}
''; '';
# The EFI boot image. # The EFI boot image.
# Notes about grub: # Notes about grub:
# * Yes, the grubMenuCfg has to be repeated in all submenus. Otherwise you # * Yes, the grubMenuCfg has to be repeated in all submenus. Otherwise you
# will get white-on-black console-like text on sub-menus. *sigh* # will get white-on-black console-like text on sub-menus. *sigh*
efiDir = pkgs.runCommand "efi-directory" { efiDir =
nativeBuildInputs = [ pkgs.buildPackages.grub2_efi ]; pkgs.runCommand "efi-directory" {
strictDeps = true; nativeBuildInputs = [pkgs.buildPackages.grub2_efi];
} '' strictDeps = true;
mkdir -p $out/EFI/boot/ } ''
mkdir -p $out/EFI/boot/
# Add a marker so GRUB can find the filesystem. # Add a marker so GRUB can find the filesystem.
touch $out/EFI/nixos-installer-image touch $out/EFI/nixos-installer-image
# ALWAYS required modules. # ALWAYS required modules.
MODULES=( MODULES=(
# Basic modules for filesystems and partition schemes # Basic modules for filesystems and partition schemes
"fat" "fat"
"iso9660" "iso9660"
"part_gpt" "part_gpt"
"part_msdos" "part_msdos"
# Basic stuff # Basic stuff
"normal" "normal"
"boot" "boot"
"linux" "linux"
"configfile" "configfile"
"loopback" "loopback"
"chain" "chain"
"halt" "halt"
# Allows rebooting into firmware setup interface # Allows rebooting into firmware setup interface
"efifwsetup" "efifwsetup"
# EFI Graphics Output Protocol # EFI Graphics Output Protocol
"efi_gop" "efi_gop"
# User commands # User commands
"ls" "ls"
# System commands # System commands
"search" "search"
"search_label" "search_label"
"search_fs_uuid" "search_fs_uuid"
"search_fs_file" "search_fs_file"
"echo" "echo"
# We're not using it anymore, but we'll leave it in so it can be used # We're not using it anymore, but we'll leave it in so it can be used
# by user, with the console using "C" # by user, with the console using "C"
"serial" "serial"
# Graphical mode stuff # Graphical mode stuff
"gfxmenu" "gfxmenu"
"gfxterm" "gfxterm"
"gfxterm_background" "gfxterm_background"
"gfxterm_menu" "gfxterm_menu"
"test" "test"
"loadenv" "loadenv"
"all_video" "all_video"
"videoinfo" "videoinfo"
# File types for graphical mode # File types for graphical mode
"png" "png"
) )
echo "Building GRUB with modules:" echo "Building GRUB with modules:"
for mod in ''${MODULES[@]}; do for mod in ''${MODULES[@]}; do
echo " - $mod"
done
# Modules that may or may not be available per-platform.
echo "Adding additional modules:"
for mod in efi_uga; do
if [ -f ${grubPkgs.grub2_efi}/lib/grub/${grubPkgs.grub2_efi.grubTarget}/$mod.mod ]; then
echo " - $mod" echo " - $mod"
MODULES+=("$mod") done
fi
done
# Make our own efi program, we can't rely on "grub-install" since it seems to # Modules that may or may not be available per-platform.
# probe for devices, even with --skip-fs-probe. echo "Adding additional modules:"
grub-mkimage \ for mod in efi_uga; do
--directory=${grubPkgs.grub2_efi}/lib/grub/${grubPkgs.grub2_efi.grubTarget} \ if [ -f ${grubPkgs.grub2_efi}/lib/grub/${grubPkgs.grub2_efi.grubTarget}/$mod.mod ]; then
-o $out/EFI/boot/boot${targetArch}.efi \ echo " - $mod"
-p /EFI/boot \ MODULES+=("$mod")
-O ${grubPkgs.grub2_efi.grubTarget} \ fi
''${MODULES[@]} done
cp ${grubPkgs.grub2_efi}/share/grub/unicode.pf2 $out/EFI/boot/
cat <<EOF > $out/EFI/boot/grub.cfg # Make our own efi program, we can't rely on "grub-install" since it seems to
# probe for devices, even with --skip-fs-probe.
grub-mkimage \
--directory=${grubPkgs.grub2_efi}/lib/grub/${grubPkgs.grub2_efi.grubTarget} \
-o $out/EFI/boot/boot${targetArch}.efi \
-p /EFI/boot \
-O ${grubPkgs.grub2_efi.grubTarget} \
''${MODULES[@]}
cp ${grubPkgs.grub2_efi}/share/grub/unicode.pf2 $out/EFI/boot/
set textmode=${boolToString (config.isoImage.forceTextMode)} cat <<EOF > $out/EFI/boot/grub.cfg
set timeout=${toString grubEfiTimeout}
clear set textmode=${boolToString (config.isoImage.forceTextMode)}
# This message will only be viewable on the default (UEFI) console. set timeout=${toString grubEfiTimeout}
echo ""
echo "Loading graphical boot menu..."
echo ""
echo "Press 't' to use the text boot menu on this console..."
echo ""
${grubMenuCfg}
hiddenentry 'Text mode' --hotkey 't' {
loadfont (\$root)/EFI/boot/unicode.pf2
set textmode=true
terminal_output console
}
hiddenentry 'GUI mode' --hotkey 'g' {
$(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (\$root)/EFI/boot/grub-theme/%P\n")
set textmode=false
terminal_output gfxterm
}
# If the parameter iso_path is set, append the findiso parameter to the kernel
# line. We need this to allow the nixos iso to be booted from grub directly.
if [ \''${iso_path} ] ; then
set isoboot="findiso=\''${iso_path}"
fi
#
# Menu entries
#
${buildMenuGrub2}
submenu "HiDPI, Quirks and Accessibility" --class hidpi --class submenu {
${grubMenuCfg}
submenu "Suggests resolution @720p" --class hidpi-720p {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "video=1280x720@60"}
}
submenu "Suggests resolution @1080p" --class hidpi-1080p {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "video=1920x1080@60"}
}
# If we boot into a graphical environment where X is autoran
# and always crashes, it makes the media unusable. Allow the user
# to disable this.
submenu "Disable display-manager" --class quirk-disable-displaymanager {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "systemd.mask=display-manager.service"}
}
# Some laptop and convertibles have the panel installed in an
# inconvenient way, rotated away from the keyboard.
# Those entries makes it easier to use the installer.
submenu "" {return}
submenu "Rotate framebuffer Clockwise" --class rotate-90cw {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "fbcon=rotate:1"}
}
submenu "Rotate framebuffer Upside-Down" --class rotate-180 {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "fbcon=rotate:2"}
}
submenu "Rotate framebuffer Counter-Clockwise" --class rotate-90ccw {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "fbcon=rotate:3"}
}
# As a proof of concept, mainly. (Not sure it has accessibility merits.)
submenu "" {return}
submenu "Use black on white" --class accessibility-blakconwhite {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "vt.default_red=0xFF,0xBC,0x4F,0xB4,0x56,0xBC,0x4F,0x00,0xA1,0xCF,0x84,0xCA,0x8D,0xB4,0x84,0x68 vt.default_grn=0xFF,0x55,0xBA,0xBA,0x4D,0x4D,0xB3,0x00,0xA0,0x8F,0xB3,0xCA,0x88,0x93,0xA4,0x68 vt.default_blu=0xFF,0x58,0x5F,0x58,0xC5,0xBD,0xC5,0x00,0xA8,0xBB,0xAB,0x97,0xBD,0xC7,0xC5,0x68"}
}
# Serial access is a must!
submenu "" {return}
submenu "Serial console=ttyS0,115200n8" --class serial {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "console=ttyS0,115200n8"}
}
}
${lib.optionalString (refindBinary != null) ''
# GRUB apparently cannot do "chainloader" operations on "CD".
if [ "\$root" != "cd0" ]; then
menuentry 'rEFInd' --class refind {
# Force root to be the FAT partition
# Otherwise it breaks rEFInd's boot
search --set=root --no-floppy --fs-uuid 1234-5678
chainloader (\$root)/EFI/boot/${refindBinary}
}
fi
''}
menuentry 'Firmware Setup' --class settings {
fwsetup
clear clear
# This message will only be viewable on the default (UEFI) console.
echo "" echo ""
echo "If you see this message, your EFI system doesn't support this feature." echo "Loading graphical boot menu..."
echo "" echo ""
echo "Press 't' to use the text boot menu on this console..."
echo ""
${grubMenuCfg}
hiddenentry 'Text mode' --hotkey 't' {
loadfont (\$root)/EFI/boot/unicode.pf2
set textmode=true
terminal_output console
}
hiddenentry 'GUI mode' --hotkey 'g' {
$(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (\$root)/EFI/boot/grub-theme/%P\n")
set textmode=false
terminal_output gfxterm
}
# If the parameter iso_path is set, append the findiso parameter to the kernel
# line. We need this to allow the nixos iso to be booted from grub directly.
if [ \''${iso_path} ] ; then
set isoboot="findiso=\''${iso_path}"
fi
#
# Menu entries
#
${buildMenuGrub2}
submenu "HiDPI, Quirks and Accessibility" --class hidpi --class submenu {
${grubMenuCfg}
submenu "Suggests resolution @720p" --class hidpi-720p {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "video=1280x720@60"}
}
submenu "Suggests resolution @1080p" --class hidpi-1080p {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "video=1920x1080@60"}
}
# If we boot into a graphical environment where X is autoran
# and always crashes, it makes the media unusable. Allow the user
# to disable this.
submenu "Disable display-manager" --class quirk-disable-displaymanager {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "systemd.mask=display-manager.service"}
}
# Some laptop and convertibles have the panel installed in an
# inconvenient way, rotated away from the keyboard.
# Those entries makes it easier to use the installer.
submenu "" {return}
submenu "Rotate framebuffer Clockwise" --class rotate-90cw {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "fbcon=rotate:1"}
}
submenu "Rotate framebuffer Upside-Down" --class rotate-180 {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "fbcon=rotate:2"}
}
submenu "Rotate framebuffer Counter-Clockwise" --class rotate-90ccw {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "fbcon=rotate:3"}
}
# As a proof of concept, mainly. (Not sure it has accessibility merits.)
submenu "" {return}
submenu "Use black on white" --class accessibility-blakconwhite {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "vt.default_red=0xFF,0xBC,0x4F,0xB4,0x56,0xBC,0x4F,0x00,0xA1,0xCF,0x84,0xCA,0x8D,0xB4,0x84,0x68 vt.default_grn=0xFF,0x55,0xBA,0xBA,0x4D,0x4D,0xB3,0x00,0xA0,0x8F,0xB3,0xCA,0x88,0x93,0xA4,0x68 vt.default_blu=0xFF,0x58,0x5F,0x58,0xC5,0xBD,0xC5,0x00,0xA8,0xBB,0xAB,0x97,0xBD,0xC7,0xC5,0x68"}
}
# Serial access is a must!
submenu "" {return}
submenu "Serial console=ttyS0,115200n8" --class serial {
${grubMenuCfg}
${buildMenuAdditionalParamsGrub2 "console=ttyS0,115200n8"}
}
}
${lib.optionalString (refindBinary != null) ''
# GRUB apparently cannot do "chainloader" operations on "CD".
if [ "\$root" != "cd0" ]; then
menuentry 'rEFInd' --class refind {
# Force root to be the FAT partition
# Otherwise it breaks rEFInd's boot
search --set=root --no-floppy --fs-uuid 1234-5678
chainloader (\$root)/EFI/boot/${refindBinary}
}
fi
''}
menuentry 'Firmware Setup' --class settings {
fwsetup
clear
echo ""
echo "If you see this message, your EFI system doesn't support this feature."
echo ""
}
menuentry 'Shutdown' --class shutdown {
halt
}
EOF
grub-script-check $out/EFI/boot/grub.cfg
${refind}
'';
efiImg =
pkgs.runCommand "efi-image_eltorito" {
nativeBuildInputs = [pkgs.buildPackages.mtools pkgs.buildPackages.libfaketime pkgs.buildPackages.dosfstools];
strictDeps = true;
} }
menuentry 'Shutdown' --class shutdown {
halt
}
EOF
grub-script-check $out/EFI/boot/grub.cfg
${refind}
'';
efiImg = pkgs.runCommand "efi-image_eltorito" {
nativeBuildInputs = [ pkgs.buildPackages.mtools pkgs.buildPackages.libfaketime pkgs.buildPackages.dosfstools ];
strictDeps = true;
}
# Be careful about determinism: du --apparent-size, # Be careful about determinism: du --apparent-size,
# dates (cp -p, touch, mcopy -m, faketime for label), IDs (mkfs.vfat -i) # dates (cp -p, touch, mcopy -m, faketime for label), IDs (mkfs.vfat -i)
'' ''
@ -443,12 +452,8 @@ let
# Verify the FAT partition. # Verify the FAT partition.
fsck.vfat -vn "$out" fsck.vfat -vn "$out"
''; # */ ''; # */
in {
in
{
options = { options = {
isoImage.isoName = mkOption { isoImage.isoName = mkOption {
default = "${config.isoImage.isoBaseName}.iso"; default = "${config.isoImage.isoBaseName}.iso";
type = lib.types.str; type = lib.types.str;
@ -475,12 +480,13 @@ in
}; };
isoImage.squashfsCompression = mkOption { isoImage.squashfsCompression = mkOption {
default = with pkgs.stdenv.hostPlatform; "xz -Xdict-size 100% " default = with pkgs.stdenv.hostPlatform;
+ lib.optionalString isx86 "-Xbcj x86" "xz -Xdict-size 100% "
# Untested but should also reduce size for these platforms + lib.optionalString isx86 "-Xbcj x86"
+ lib.optionalString isAarch "-Xbcj arm" # Untested but should also reduce size for these platforms
+ lib.optionalString (isPower && is32bit && isBigEndian) "-Xbcj powerpc" + lib.optionalString isAarch "-Xbcj arm"
+ lib.optionalString (isSparc) "-Xbcj sparc"; + lib.optionalString (isPower && is32bit && isBigEndian) "-Xbcj powerpc"
+ lib.optionalString isSparc "-Xbcj sparc";
type = lib.types.nullOr lib.types.str; type = lib.types.nullOr lib.types.str;
description = '' description = ''
Compression settings to use for the squashfs nix store. Compression settings to use for the squashfs nix store.
@ -578,9 +584,9 @@ in
isoImage.efiSplashImage = mkOption { isoImage.efiSplashImage = mkOption {
default = pkgs.fetchurl { default = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/NixOS/nixos-artwork/a9e05d7deb38a8e005a2b52575a3f59a63a4dba0/bootloader/efi-background.png"; url = "https://raw.githubusercontent.com/NixOS/nixos-artwork/a9e05d7deb38a8e005a2b52575a3f59a63a4dba0/bootloader/efi-background.png";
sha256 = "18lfwmp8yq923322nlb9gxrh5qikj1wsk6g5qvdh31c4h5b1538x"; sha256 = "18lfwmp8yq923322nlb9gxrh5qikj1wsk6g5qvdh31c4h5b1538x";
}; };
description = '' description = ''
The splash image to use in the EFI bootloader. The splash image to use in the EFI bootloader.
''; '';
@ -588,9 +594,9 @@ in
isoImage.splashImage = mkOption { isoImage.splashImage = mkOption {
default = pkgs.fetchurl { default = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/NixOS/nixos-artwork/a9e05d7deb38a8e005a2b52575a3f59a63a4dba0/bootloader/isolinux/bios-boot.png"; url = "https://raw.githubusercontent.com/NixOS/nixos-artwork/a9e05d7deb38a8e005a2b52575a3f59a63a4dba0/bootloader/isolinux/bios-boot.png";
sha256 = "1wp822zrhbg4fgfbwkr7cbkr4labx477209agzc0hr6k62fr6rxd"; sha256 = "1wp822zrhbg4fgfbwkr7cbkr4labx477209agzc0hr6k62fr6rxd";
}; };
description = '' description = ''
The splash image to use in the legacy-boot bootloader. The splash image to use in the legacy-boot bootloader.
''; '';
@ -674,44 +680,52 @@ in
If text mode is required off-handedly (e.g. for serial use) you can use the `T` key, after being prompted, to use text mode for the current boot. If text mode is required off-handedly (e.g. for serial use) you can use the `T` key, after being prompted, to use text mode for the current boot.
''; '';
}; };
}; };
# store them in lib so we can mkImageMediaOverride the # store them in lib so we can mkImageMediaOverride the
# entire file system layout in installation media (only) # entire file system layout in installation media (only)
config.lib.isoFileSystems = { config.lib.isoFileSystems = {
"/" = mkImageMediaOverride "/" =
mkImageMediaOverride
{ {
fsType = "tmpfs"; fsType = "tmpfs";
options = [ "mode=0755" ]; options = ["mode=0755"];
}; };
# Note that /dev/root is a symlink to the actual root device # Note that /dev/root is a symlink to the actual root device
# specified on the kernel command line, created in the stage 1 # specified on the kernel command line, created in the stage 1
# init script. # init script.
"/iso" = mkImageMediaOverride "/iso" =
{ device = "/dev/root"; mkImageMediaOverride
{
device = "/dev/root";
neededForBoot = true; neededForBoot = true;
noCheck = true; noCheck = true;
}; };
# In stage 1, mount a tmpfs on top of /nix/store (the squashfs # In stage 1, mount a tmpfs on top of /nix/store (the squashfs
# image) to make this a live CD. # image) to make this a live CD.
"/nix/.ro-store" = mkImageMediaOverride "/nix/.ro-store" =
{ fsType = "squashfs"; mkImageMediaOverride
{
fsType = "squashfs";
device = "/iso/nix-store.squashfs"; device = "/iso/nix-store.squashfs";
options = [ "loop" ]; options = ["loop"];
neededForBoot = true; neededForBoot = true;
}; };
"/nix/.rw-store" = mkImageMediaOverride "/nix/.rw-store" =
{ fsType = "tmpfs"; mkImageMediaOverride
options = [ "mode=0755" ]; {
fsType = "tmpfs";
options = ["mode=0755"];
neededForBoot = true; neededForBoot = true;
}; };
"/nix/store" = mkImageMediaOverride "/nix/store" =
{ fsType = "overlay"; mkImageMediaOverride
{
fsType = "overlay";
device = "overlay"; device = "overlay";
options = [ options = [
"lowerdir=/nix/.ro-store" "lowerdir=/nix/.ro-store"
@ -741,8 +755,7 @@ in
length = stringLength config.isoImage.volumeID; length = stringLength config.isoImage.volumeID;
howmany = toString length; howmany = toString length;
toomany = toString (length - 32); toomany = toString (length - 32);
in in "isoImage.volumeID ${config.isoImage.volumeID} is ${howmany} characters. That is ${toomany} characters longer than the limit of 32.";
"isoImage.volumeID ${config.isoImage.volumeID} is ${howmany} characters. That is ${toomany} characters longer than the limit of 32.";
} }
]; ];
@ -750,9 +763,9 @@ in
# here and it causes a cyclic dependency. # here and it causes a cyclic dependency.
boot.loader.grub.enable = false; boot.loader.grub.enable = false;
environment.systemPackages = [ grubPkgs.grub2 grubPkgs.grub2_efi ] environment.systemPackages =
++ optional (config.isoImage.makeBiosBootable) pkgs.syslinux [grubPkgs.grub2 grubPkgs.grub2_efi]
; ++ optional (config.isoImage.makeBiosBootable) pkgs.syslinux;
# In stage 1 of the boot, mount the CD as the root FS by label so # In stage 1 of the boot, mount the CD as the root FS by label so
# that we don't need to know its device. We pass the label of the # that we don't need to know its device. We pass the label of the
@ -762,70 +775,86 @@ in
# UUID of the USB stick. It would be nicer to write # UUID of the USB stick. It would be nicer to write
# `root=/dev/disk/by-label/...' here, but UNetbootin doesn't # `root=/dev/disk/by-label/...' here, but UNetbootin doesn't
# recognise that. # recognise that.
boot.kernelParams = boot.kernelParams = [
[ "root=LABEL=${config.isoImage.volumeID}" "root=LABEL=${config.isoImage.volumeID}"
"boot.shell_on_fail" "boot.shell_on_fail"
]; ];
fileSystems = config.lib.isoFileSystems; fileSystems = config.lib.isoFileSystems;
boot.initrd.availableKernelModules = [ "squashfs" "iso9660" "uas" "overlay" ]; boot.initrd.availableKernelModules = ["squashfs" "iso9660" "uas" "overlay"];
boot.initrd.kernelModules = [ "loop" "overlay" ]; boot.initrd.kernelModules = ["loop" "overlay"];
# Closures to be copied to the Nix store on the CD, namely the init # Closures to be copied to the Nix store on the CD, namely the init
# script and the top-level system configuration directory. # script and the top-level system configuration directory.
isoImage.storeContents = isoImage.storeContents =
[ config.system.build.toplevel ] ++ [config.system.build.toplevel]
optional config.isoImage.includeSystemBuildDependencies ++ optional config.isoImage.includeSystemBuildDependencies
config.system.build.toplevel.drvPath; config.system.build.toplevel.drvPath;
# Individual files to be included on the CD, outside of the Nix # Individual files to be included on the CD, outside of the Nix
# store on the CD. # store on the CD.
isoImage.contents = isoImage.contents =
[ [
{ source = config.boot.kernelPackages.kernel + "/" + config.system.boot.loader.kernelFile; {
source = config.boot.kernelPackages.kernel + "/" + config.system.boot.loader.kernelFile;
target = "/boot/" + config.system.boot.loader.kernelFile; target = "/boot/" + config.system.boot.loader.kernelFile;
} }
{ source = config.system.build.initialRamdisk + "/" + config.system.boot.loader.initrdFile; {
source = config.system.build.initialRamdisk + "/" + config.system.boot.loader.initrdFile;
target = "/boot/" + config.system.boot.loader.initrdFile; target = "/boot/" + config.system.boot.loader.initrdFile;
} }
{ source = pkgs.writeText "version" config.system.nixos.label; {
source = pkgs.writeText "version" config.system.nixos.label;
target = "/version.txt"; target = "/version.txt";
} }
] ++ optionals (config.isoImage.makeBiosBootable) [ ]
{ source = config.isoImage.splashImage; ++ optionals (config.isoImage.makeBiosBootable) [
{
source = config.isoImage.splashImage;
target = "/isolinux/background.png"; target = "/isolinux/background.png";
} }
{ source = pkgs.substituteAll { {
source = pkgs.substituteAll {
name = "isolinux.cfg"; name = "isolinux.cfg";
src = pkgs.writeText "isolinux.cfg-in" isolinuxCfg; src = pkgs.writeText "isolinux.cfg-in" isolinuxCfg;
bootRoot = "/boot"; bootRoot = "/boot";
}; };
target = "/isolinux/isolinux.cfg"; target = "/isolinux/isolinux.cfg";
} }
{ source = "${pkgs.syslinux}/share/syslinux"; {
source = "${pkgs.syslinux}/share/syslinux";
target = "/isolinux"; target = "/isolinux";
} }
] ++ optionals config.isoImage.makeEfiBootable [ ]
{ source = efiImg; ++ optionals config.isoImage.makeEfiBootable [
{
source = efiImg;
target = "/boot/efi.img"; target = "/boot/efi.img";
} }
{ source = "${efiDir}/EFI"; {
source = "${efiDir}/EFI";
target = "/EFI"; target = "/EFI";
} }
{ source = (pkgs.writeTextDir "grub/loopback.cfg" "source /EFI/boot/grub.cfg") + "/grub"; {
source = (pkgs.writeTextDir "grub/loopback.cfg" "source /EFI/boot/grub.cfg") + "/grub";
target = "/boot/grub"; target = "/boot/grub";
} }
{ source = config.isoImage.efiSplashImage; {
source = config.isoImage.efiSplashImage;
target = "/EFI/boot/efi-background.png"; target = "/EFI/boot/efi-background.png";
} }
] ++ optionals (config.boot.loader.grub.memtest86.enable && config.isoImage.makeBiosBootable) [ ]
{ source = "${pkgs.memtest86plus}/memtest.bin"; ++ optionals (config.boot.loader.grub.memtest86.enable && config.isoImage.makeBiosBootable) [
{
source = "${pkgs.memtest86plus}/memtest.bin";
target = "/boot/memtest.bin"; target = "/boot/memtest.bin";
} }
] ++ optionals (config.isoImage.grubTheme != null) [ ]
{ source = config.isoImage.grubTheme; ++ optionals (config.isoImage.grubTheme != null) [
{
source = config.isoImage.grubTheme;
target = "/EFI/boot/grub-theme"; target = "/EFI/boot/grub-theme";
} }
]; ];
@ -834,36 +863,38 @@ in
# Create the ISO image. # Create the ISO image.
system.build.isoImage = pkgs.callPackage "${toString pkgs.path}/nixos/lib/make-iso9660-image.nix" ({ system.build.isoImage = pkgs.callPackage "${toString pkgs.path}/nixos/lib/make-iso9660-image.nix" ({
inherit (config.isoImage) isoName compressImage volumeID contents; inherit (config.isoImage) isoName compressImage volumeID contents;
bootable = config.isoImage.makeBiosBootable; bootable = config.isoImage.makeBiosBootable;
bootImage = "/isolinux/isolinux.bin"; bootImage = "/isolinux/isolinux.bin";
syslinux = if config.isoImage.makeBiosBootable then pkgs.syslinux else null; syslinux =
squashfsContents = config.isoImage.storeContents; if config.isoImage.makeBiosBootable
squashfsCompression = config.isoImage.squashfsCompression; then pkgs.syslinux
} // optionalAttrs (config.isoImage.makeUsbBootable && config.isoImage.makeBiosBootable) { else null;
usbBootable = true; squashfsContents = config.isoImage.storeContents;
isohybridMbrImage = "${pkgs.syslinux}/share/syslinux/isohdpfx.bin"; squashfsCompression = config.isoImage.squashfsCompression;
} // optionalAttrs config.isoImage.makeEfiBootable { }
efiBootable = true; // optionalAttrs (config.isoImage.makeUsbBootable && config.isoImage.makeBiosBootable) {
efiBootImage = "boot/efi.img"; usbBootable = true;
}); isohybridMbrImage = "${pkgs.syslinux}/share/syslinux/isohdpfx.bin";
}
// optionalAttrs config.isoImage.makeEfiBootable {
efiBootable = true;
efiBootImage = "boot/efi.img";
});
boot.postBootCommands = boot.postBootCommands = ''
'' # After booting, register the contents of the Nix store on the
# After booting, register the contents of the Nix store on the # CD in the Nix database in the tmpfs.
# CD in the Nix database in the tmpfs. ${config.nix.package.out}/bin/nix-store --load-db < /nix/store/nix-path-registration
${config.nix.package.out}/bin/nix-store --load-db < /nix/store/nix-path-registration
# nixos-rebuild also requires a "system" profile and an # nixos-rebuild also requires a "system" profile and an
# /etc/NIXOS tag. # /etc/NIXOS tag.
touch /etc/NIXOS touch /etc/NIXOS
${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system
''; '';
# Add vfat support to the initrd to enable people to copy the # Add vfat support to the initrd to enable people to copy the
# contents of the CD to a bootable USB stick. # contents of the CD to a bootable USB stick.
boot.initrd.supportedFilesystems = [ "vfat" ]; boot.initrd.supportedFilesystems = ["vfat"];
}; };
} }

View File

@ -1,5 +1,4 @@
{ stdenv }: {stdenv}:
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "calamares-extensions-desk-os"; pname = "calamares-extensions-desk-os";
version = "0.0.1"; version = "0.0.1";