nixos/hidpi: remove

The single option tries to do too much work, which just ends up confusing people.

So:
- don't force the console font, the kernel can figure this out as of #210205
- don't force the systemd-boot mode, it's an awkward mode that's not supported
  on most things and will break flicker-free boot
- add a separate option for the xorg cursor scaling trick and move it under the xorg namespace
- add a general `fonts.optimizeForVeryHighDPI` option that explicitly says what it does
- alias the old option to that
- don't set any of those automatically in nixos-generate-config
This commit is contained in:
K900 2023-03-20 21:22:22 +03:00 committed by Raito Bezarius
parent 49fd723a69
commit 4787ebf7ae
6 changed files with 64 additions and 75 deletions

View file

@ -246,10 +246,10 @@ In addition to numerous new and upgraded packages, this release has the followin
[headscale's example configuration](https://github.com/juanfont/headscale/blob/main/config-example.yaml)
can be directly written as attribute-set in Nix within this option.
- `hardware.video.hidpi` now provides defaults that are consistent with `fontconfig`'s documentation:
- antialiasing and font hinting are disabled, as they have no visible effects at high pixel densities;
- subpixel order isn't set: it was irrelevant with the above disabled, and the module *cannot* know the correct
setting for the user's screen.
- The `hardware.video.hidpi.enable` was renamed to `fonts.optimizeForVeryHighDPI` to be consistent with what it actually does.
They disable by default: antialiasing, hinting and LCD filter for subpixel rendering. They can be overridden if you experience problems with font rendering.
On Xorg, the default cursor is upscaled.
Please see the documentation for the new option to decide if you want to keep it enabled.
- `nixos/lib/make-disk-image.nix` can now mutate EFI variables, run user-provided EFI firmware or variable templates. This is now extensively documented in the NixOS manual.

View file

@ -3,29 +3,7 @@
with lib;
let
# A scalable variant of the X11 "core" cursor
#
# If not running a fancy desktop environment, the cursor is likely set to
# the default `cursor.pcf` bitmap font. This is 17px wide, so it's very
# small and almost invisible on 4K displays.
fontcursormisc_hidpi = pkgs.xorg.fontxfree86type1.overrideAttrs (old:
let
# The scaling constant is 230/96: the scalable `left_ptr` glyph at
# about 23 points is rendered as 17px, on a 96dpi display.
# Note: the XLFD font size is in decipoints.
size = 2.39583 * config.services.xserver.dpi;
sizeString = builtins.head (builtins.split "\\." (toString size));
in
{
postInstall = ''
alias='cursor -xfree86-cursor-medium-r-normal--0-${sizeString}-0-0-p-0-adobe-fontspecific'
echo "$alias" > $out/lib/X11/fonts/Type1/fonts.alias
'';
});
hasHidpi =
config.hardware.video.hidpi.enable &&
config.services.xserver.dpi != null;
cfg = config.fonts;
defaultFonts =
[ pkgs.dejavu_fonts
@ -36,16 +14,12 @@ let
pkgs.noto-fonts-emoji
];
defaultXFonts =
[ (if hasHidpi then fontcursormisc_hidpi else pkgs.xorg.fontcursormisc)
pkgs.xorg.fontmiscmisc
];
in
{
imports = [
(mkRemovedOptionModule [ "fonts" "enableCoreFonts" ] "Use fonts.fonts = [ pkgs.corefonts ]; instead.")
(mkRenamedOptionModule [ "hardware" "video" "hidpi" "enable" ] [ "fonts" "optimizeForVeryHighDPI" ])
];
options = {
@ -69,13 +43,32 @@ in
'';
};
optimizeForVeryHighDPI = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Optimize configuration for very high-density (>200 DPI) displays:
- disable subpixel anti-aliasing
- disable hinting
- automatically upscale the default X11 cursor
'';
};
};
};
config = mkMerge [
{ fonts.fonts = mkIf config.fonts.enableDefaultFonts defaultFonts; }
{ fonts.fonts = mkIf config.services.xserver.enable defaultXFonts; }
{ fonts.fonts = mkIf cfg.enableDefaultFonts defaultFonts; }
(mkIf cfg.optimizeForVeryHighDPI {
services.xserver.upscaleDefaultCursor = mkDefault true;
# Conforms to the recommendation in fonts/fontconfig.nix
# for > 200DPI.
fonts.fontconfig = {
antialias = mkDefault false;
hinting.enable = mkDefault false;
subpixel.lcdfilter = mkDefault "none";
};
})
];
}

View file

@ -1,25 +0,0 @@
{ lib, pkgs, config, ...}:
with lib;
{
options.hardware.video.hidpi.enable = mkEnableOption (lib.mdDoc "Font/DPI configuration optimized for HiDPI displays");
config = mkIf config.hardware.video.hidpi.enable {
console.font = lib.mkDefault "${pkgs.terminus_font}/share/consolefonts/ter-v32n.psf.gz";
# Needed when typing in passwords for full disk encryption
console.earlySetup = mkDefault true;
boot.loader.systemd-boot.consoleMode = mkDefault "1";
# Disable font anti-aliasing, hinting, and sub-pixel rendering by default
# See recommendations in fonts/fontconfig.nix
fonts.fontconfig = {
antialias = mkDefault false;
hinting.enable = mkDefault false;
subpixel.lcdfilter = mkDefault "none";
};
# TODO Find reasonable defaults X11 & wayland
};
}

View file

@ -518,21 +518,6 @@ EOF
}
}
# For lack of a better way to determine it, guess whether we should use a
# bigger font for the console from the display mode on the first
# framebuffer. A way based on the physical size/actual DPI reported by
# the monitor would be nice, but I don't know how to do this without X :)
my $fb_modes_file = "/sys/class/graphics/fb0/modes";
if (-f $fb_modes_file && -r $fb_modes_file) {
my $modes = read_file($fb_modes_file);
$modes =~ m/([0-9]+)x([0-9]+)/;
my $console_width = $1, my $console_height = $2;
if ($console_width > 1920) {
push @attrs, "# high-resolution display";
push @attrs, 'hardware.video.hidpi.enable = lib.mkDefault true;';
}
}
# Generate the hardware configuration file.

View file

@ -95,7 +95,6 @@
./hardware/video/bumblebee.nix
./hardware/video/capture/mwprocapture.nix
./hardware/video/displaylink.nix
./hardware/video/hidpi.nix
./hardware/video/nvidia.nix
./hardware/video/switcheroo-control.nix
./hardware/video/uvcvideo/default.nix

View file

@ -138,6 +138,26 @@ let
concatMapStringsSep "\n" (line: prefix + line) (splitString "\n" str);
indent = prefixStringLines " ";
# A scalable variant of the X11 "core" cursor
#
# If not running a fancy desktop environment, the cursor is likely set to
# the default `cursor.pcf` bitmap font. This is 17px wide, so it's very
# small and almost invisible on 4K displays.
fontcursormisc_hidpi = pkgs.xorg.fontxfree86type1.overrideAttrs (old:
let
# The scaling constant is 230/96: the scalable `left_ptr` glyph at
# about 23 points is rendered as 17px, on a 96dpi display.
# Note: the XLFD font size is in decipoints.
size = 2.39583 * cfg.dpi;
sizeString = builtins.head (builtins.split "\\." (toString size));
in
{
postInstall = ''
alias='cursor -xfree86-cursor-medium-r-normal--0-${sizeString}-0-0-p-0-adobe-fontspecific'
echo "$alias" > $out/lib/X11/fonts/Type1/fonts.alias
'';
});
in
{
@ -576,6 +596,15 @@ in
Whether to terminate X upon server reset.
'';
};
upscaleDefaultCursor = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Upscale the default X cursor to be more visible on high-density displays.
Requires `config.services.xserver.dpi` to be set.
'';
};
};
};
@ -627,6 +656,10 @@ in
+ "${toString (length primaryHeads)} heads set to primary: "
+ concatMapStringsSep ", " (x: x.output) primaryHeads;
})
{
assertion = cfg.upscaleDefaultCursor -> cfg.dpi != null;
message = "Specify `config.services.xserver.dpi` to upscale the default cursor.";
}
];
environment.etc =
@ -851,6 +884,10 @@ in
'';
fonts.enableDefaultFonts = mkDefault true;
fonts.fonts = [
(if cfg.upscaleDefaultCursor then fontcursormisc_hidpi else pkgs.xorg.fontcursormisc)
pkgs.xorg.fontmiscmisc
];
};