From a5618e6187d272b4c498696a53e4bef9df68e45c Mon Sep 17 00:00:00 2001 From: Emilio Perez Date: Sun, 30 Aug 2020 21:39:27 +0100 Subject: [PATCH 1/8] nixos/fontdir: gather more font formats - Fix wrong order in which font indexes are created mkfontdir requires the file fonts.scale to consider scalable fonts, thus, mkfontscale should be run before - Search more font formats, in particular, bit-mapped formats --- nixos/modules/config/fonts/fontdir.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nixos/modules/config/fonts/fontdir.nix b/nixos/modules/config/fonts/fontdir.nix index a6aa84ae8224..45d821e7e883 100644 --- a/nixos/modules/config/fonts/fontdir.nix +++ b/nixos/modules/config/fonts/fontdir.nix @@ -5,14 +5,16 @@ with lib; let x11Fonts = pkgs.runCommand "X11-fonts" { preferLocalBuild = true; } '' + font_formats=('ttf' 'otf' 'pcf' 'pfa' 'pfb' 'bdf') mkdir -p "$out/share/X11-fonts" - find ${toString config.fonts.fonts} \ - \( -name fonts.dir -o -name '*.ttf' -o -name '*.otf' \) \ - -exec ln -sf -t "$out/share/X11-fonts" '{}' \; + for fmt in "''${font_formats[@]}"; do + find ${toString config.fonts.fonts} \ + \( -name '*.'$fmt -o -name '*.'$fmt'.gz' \) \ + -exec ln -sf -t "$out/share/X11-fonts" '{}' \; + done cd "$out/share/X11-fonts" - rm -f fonts.dir fonts.scale fonts.alias - ${pkgs.xorg.mkfontdir}/bin/mkfontdir ${pkgs.xorg.mkfontscale}/bin/mkfontscale + ${pkgs.xorg.mkfontdir}/bin/mkfontdir cat $(find ${pkgs.xorg.fontalias}/ -name fonts.alias) >fonts.alias ''; From a5c0ba40048734cd091d53454f30d853ed1fb3ca Mon Sep 17 00:00:00 2001 From: Emilio Perez Date: Mon, 31 Aug 2020 18:40:34 +0100 Subject: [PATCH 2/8] nixos/fontdir: use regexp to find font files --- nixos/modules/config/fonts/fontdir.nix | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/nixos/modules/config/fonts/fontdir.nix b/nixos/modules/config/fonts/fontdir.nix index 45d821e7e883..098038fa6d21 100644 --- a/nixos/modules/config/fonts/fontdir.nix +++ b/nixos/modules/config/fonts/fontdir.nix @@ -5,13 +5,10 @@ with lib; let x11Fonts = pkgs.runCommand "X11-fonts" { preferLocalBuild = true; } '' - font_formats=('ttf' 'otf' 'pcf' 'pfa' 'pfb' 'bdf') mkdir -p "$out/share/X11-fonts" - for fmt in "''${font_formats[@]}"; do - find ${toString config.fonts.fonts} \ - \( -name '*.'$fmt -o -name '*.'$fmt'.gz' \) \ - -exec ln -sf -t "$out/share/X11-fonts" '{}' \; - done + font_regexp='.*\.\(ttf\|otf\|pcf\|pfa\|pfb\|bdf\)\(\.gz\)?' + find ${toString config.fonts.fonts} -regex "$font_regexp" \ + -exec ln -sf -t "$out/share/X11-fonts" '{}' \; cd "$out/share/X11-fonts" ${pkgs.xorg.mkfontscale}/bin/mkfontscale ${pkgs.xorg.mkfontdir}/bin/mkfontdir From 1fdd3921a2b08a28c850e9da88f1ed67dd07b5cb Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Tue, 1 Sep 2020 10:37:11 +0200 Subject: [PATCH 3/8] nixos/xserver: add option to configure the "Files" section --- nixos/modules/services/x11/xserver.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index 0552095ba955..c8335b697698 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/nixos/modules/services/x11/xserver.nix @@ -136,6 +136,7 @@ let fi done + echo '${cfg.filesSection}' >> $out echo 'EndSection' >> $out echo "$config" >> $out @@ -366,6 +367,13 @@ in ''; }; + filesSection = mkOption { + type = types.lines; + default = ""; + example = ''FontPath "/path/to/my/fonts"''; + description = "Contents of the first Files section of the X server configuration file."; + }; + deviceSection = mkOption { type = types.lines; default = ""; From eda7e23ea4c276e593bb399e552a5701a6e725f1 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Tue, 1 Sep 2020 10:38:59 +0200 Subject: [PATCH 4/8] nixos/fontdir: add the directory to the xserver font paths --- nixos/modules/config/fonts/fontdir.nix | 14 +++++++++----- nixos/modules/services/x11/xserver.nix | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/nixos/modules/config/fonts/fontdir.nix b/nixos/modules/config/fonts/fontdir.nix index 098038fa6d21..52fd2677d13c 100644 --- a/nixos/modules/config/fonts/fontdir.nix +++ b/nixos/modules/config/fonts/fontdir.nix @@ -5,11 +5,11 @@ with lib; let x11Fonts = pkgs.runCommand "X11-fonts" { preferLocalBuild = true; } '' - mkdir -p "$out/share/X11-fonts" + mkdir -p "$out/share/X11/fonts" font_regexp='.*\.\(ttf\|otf\|pcf\|pfa\|pfb\|bdf\)\(\.gz\)?' find ${toString config.fonts.fonts} -regex "$font_regexp" \ - -exec ln -sf -t "$out/share/X11-fonts" '{}' \; - cd "$out/share/X11-fonts" + -exec ln -sf -t "$out/share/X11/fonts" '{}' \; + cd "$out/share/X11/fonts" ${pkgs.xorg.mkfontscale}/bin/mkfontscale ${pkgs.xorg.mkfontdir}/bin/mkfontdir cat $(find ${pkgs.xorg.fontalias}/ -name fonts.alias) >fonts.alias @@ -28,7 +28,7 @@ in default = false; description = '' Whether to create a directory with links to all fonts in - /run/current-system/sw/share/X11-fonts. + /run/current-system/sw/share/X11/fonts. ''; }; @@ -38,9 +38,13 @@ in config = mkIf config.fonts.enableFontDir { + # This is enough to make a symlink because the xserver + # module already links all /share/X11 paths. environment.systemPackages = [ x11Fonts ]; - environment.pathsToLink = [ "/share/X11-fonts" ]; + services.xserver.filesSection = '' + FontPath "${x11Fonts}/share/X11/fonts" + ''; }; diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index c8335b697698..8223c1f1e675 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/nixos/modules/services/x11/xserver.nix @@ -371,7 +371,7 @@ in type = types.lines; default = ""; example = ''FontPath "/path/to/my/fonts"''; - description = "Contents of the first Files section of the X server configuration file."; + description = "Contents of the first Files section of the X server configuration file."; }; deviceSection = mkOption { From c99bd9bedf7291390c28eddb31f8ed2aeec8ea7f Mon Sep 17 00:00:00 2001 From: Emilio Perez Date: Tue, 1 Sep 2020 15:35:13 +0100 Subject: [PATCH 5/8] nixos/fontdir: add group of options for fontDir Renaming enableFontDir to fontDir.enable --- nixos/modules/config/fonts/fontdir.nix | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nixos/modules/config/fonts/fontdir.nix b/nixos/modules/config/fonts/fontdir.nix index 52fd2677d13c..be06991063c6 100644 --- a/nixos/modules/config/fonts/fontdir.nix +++ b/nixos/modules/config/fonts/fontdir.nix @@ -20,10 +20,9 @@ in { options = { + fonts.fontDir = { - fonts = { - - enableFontDir = mkOption { + enable = mkOption { type = types.bool; default = false; description = '' @@ -32,11 +31,11 @@ in ''; }; - }; + }; }; - config = mkIf config.fonts.enableFontDir { + config = mkIf config.fonts.fontDir.enable { # This is enough to make a symlink because the xserver # module already links all /share/X11 paths. @@ -48,4 +47,8 @@ in }; + imports = [ + (mkRenamedOptionModule [ "fonts" "enableFontDir" ] [ "fonts" "fontDir" "enable" ]) + ]; + } From f41f53dc49d4d593bfeb977c05b8a730fd3654dd Mon Sep 17 00:00:00 2001 From: Emilio Perez Date: Tue, 1 Sep 2020 15:38:06 +0100 Subject: [PATCH 6/8] nixos/fontdir: add option to decompress fonts This will let Xwayland use the global font folder as font path --- nixos/modules/config/fonts/fontdir.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nixos/modules/config/fonts/fontdir.nix b/nixos/modules/config/fonts/fontdir.nix index be06991063c6..282f2425b061 100644 --- a/nixos/modules/config/fonts/fontdir.nix +++ b/nixos/modules/config/fonts/fontdir.nix @@ -10,6 +10,9 @@ let find ${toString config.fonts.fonts} -regex "$font_regexp" \ -exec ln -sf -t "$out/share/X11/fonts" '{}' \; cd "$out/share/X11/fonts" + ${optionalString config.fonts.fontDir.decompressFonts '' + ${pkgs.gzip}/bin/gunzip -f *.gz + ''} ${pkgs.xorg.mkfontscale}/bin/mkfontscale ${pkgs.xorg.mkfontdir}/bin/mkfontdir cat $(find ${pkgs.xorg.fontalias}/ -name fonts.alias) >fonts.alias @@ -31,6 +34,14 @@ in ''; }; + decompressFonts = mkOption { + type = types.bool; + default = false; + description = '' + Whether to decompress fonts in + /run/current-system/sw/share/X11/fonts. + ''; + }; }; }; From 52f028f2d9f398e891f4a23056ec9e16c4beb409 Mon Sep 17 00:00:00 2001 From: Emilio Perez Date: Wed, 2 Sep 2020 02:59:58 +0100 Subject: [PATCH 7/8] nixos/xwayland: add new module and allow configuring a default font path - Add option `programs.xwayland.defaultFontPath` - Modify sway to enable Xwayland --- nixos/modules/config/fonts/fontdir.nix | 8 +++-- nixos/modules/module-list.nix | 1 + nixos/modules/programs/sway.nix | 5 +-- nixos/modules/programs/xwayland.nix | 45 ++++++++++++++++++++++++++ pkgs/servers/x11/xorg/xwayland.nix | 6 ++-- 5 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 nixos/modules/programs/xwayland.nix diff --git a/nixos/modules/config/fonts/fontdir.nix b/nixos/modules/config/fonts/fontdir.nix index 282f2425b061..264d73ebafa5 100644 --- a/nixos/modules/config/fonts/fontdir.nix +++ b/nixos/modules/config/fonts/fontdir.nix @@ -4,13 +4,15 @@ with lib; let + cfg = config.fonts.fontDir; + x11Fonts = pkgs.runCommand "X11-fonts" { preferLocalBuild = true; } '' mkdir -p "$out/share/X11/fonts" font_regexp='.*\.\(ttf\|otf\|pcf\|pfa\|pfb\|bdf\)\(\.gz\)?' find ${toString config.fonts.fonts} -regex "$font_regexp" \ -exec ln -sf -t "$out/share/X11/fonts" '{}' \; cd "$out/share/X11/fonts" - ${optionalString config.fonts.fontDir.decompressFonts '' + ${optionalString cfg.decompressFonts '' ${pkgs.gzip}/bin/gunzip -f *.gz ''} ${pkgs.xorg.mkfontscale}/bin/mkfontscale @@ -36,7 +38,7 @@ in decompressFonts = mkOption { type = types.bool; - default = false; + default = config.programs.xwayland.enable; description = '' Whether to decompress fonts in /run/current-system/sw/share/X11/fonts. @@ -46,7 +48,7 @@ in }; }; - config = mkIf config.fonts.fontDir.enable { + config = mkIf cfg.enable { # This is enough to make a symlink because the xserver # module already links all /share/X11 paths. diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 0aacd3e2edab..76263a321383 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -175,6 +175,7 @@ ./programs/xfs_quota.nix ./programs/xonsh.nix ./programs/xss-lock.nix + ./programs/xwayland.nix ./programs/yabar.nix ./programs/zmap.nix ./programs/zsh/oh-my-zsh.nix diff --git a/nixos/modules/programs/sway.nix b/nixos/modules/programs/sway.nix index 364debddb0f1..038d76c6c921 100644 --- a/nixos/modules/programs/sway.nix +++ b/nixos/modules/programs/sway.nix @@ -86,8 +86,7 @@ in { extraPackages = mkOption { type = with types; listOf package; default = with pkgs; [ - swaylock swayidle - xwayland alacritty dmenu + swaylock swayidle alacritty dmenu rxvt-unicode # For backward compatibility (old default terminal) ]; defaultText = literalExample '' @@ -104,6 +103,7 @@ in { Extra packages to be installed system wide. ''; }; + }; config = mkIf cfg.enable { @@ -130,6 +130,7 @@ in { programs.dconf.enable = mkDefault true; # To make a Sway session available if a display manager like SDDM is enabled: services.xserver.displayManager.sessionPackages = [ swayPackage ]; + programs.xwayland.enable = mkDefault true; }; meta.maintainers = with lib.maintainers; [ gnidorah primeos colemickens ]; diff --git a/nixos/modules/programs/xwayland.nix b/nixos/modules/programs/xwayland.nix new file mode 100644 index 000000000000..7e9a424a7150 --- /dev/null +++ b/nixos/modules/programs/xwayland.nix @@ -0,0 +1,45 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.programs.xwayland; + +in + +{ + options.programs.xwayland = { + + enable = mkEnableOption '' + Xwayland X server allows running X programs on a Wayland compositor. + ''; + + defaultFontPath = mkOption { + type = types.str; + default = optionalString config.fonts.fontDir.enable + "/run/current-system/sw/share/X11/fonts"; + description = '' + Default font path. Setting this option causes Xwayland to be rebuilt. + ''; + }; + + package = mkOption { + type = types.path; + description = "The Xwayland package"; + }; + + }; + + config = mkIf cfg.enable { + + # Needed by some applications for fonts and default settings + environment.pathsToLink = [ "/share/X11" ]; + + environment.systemPackages = [ cfg.package ]; + + programs.xwayland.package = pkgs.xwayland.override (oldArgs: { + inherit (cfg) defaultFontPath; + }); + + }; +} diff --git a/pkgs/servers/x11/xorg/xwayland.nix b/pkgs/servers/x11/xorg/xwayland.nix index a60025b79779..e10ba1069f05 100644 --- a/pkgs/servers/x11/xorg/xwayland.nix +++ b/pkgs/servers/x11/xorg/xwayland.nix @@ -1,4 +1,6 @@ -{ stdenv, wayland, wayland-protocols, xorgserver, xkbcomp, xkeyboard_config, epoxy, libxslt, libunwind, makeWrapper, egl-wayland }: +{ stdenv, wayland, wayland-protocols, xorgserver, xkbcomp, xkeyboard_config +, epoxy, libxslt, libunwind, makeWrapper, egl-wayland +, defaultFontPath ? "" }: with stdenv.lib; @@ -19,7 +21,7 @@ xorgserver.overrideAttrs (oldAttrs: { "--disable-xquartz" "--disable-xwin" "--enable-glamor" - "--with-default-font-path=" + "--with-default-font-path=${defaultFontPath}" "--with-xkb-bin-directory=${xkbcomp}/bin" "--with-xkb-path=${xkeyboard_config}/etc/X11/xkb" "--with-xkb-output=$(out)/share/X11/xkb/compiled" From 9f8aad2ca6e8fe683448172625db5a47c88ff5f0 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Fri, 4 Sep 2020 22:15:51 +0200 Subject: [PATCH 8/8] nixos/doc: document fonts.enableFontDir changes --- nixos/doc/manual/release-notes/rl-2103.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nixos/doc/manual/release-notes/rl-2103.xml b/nixos/doc/manual/release-notes/rl-2103.xml index df39c6f64509..1d00c8976756 100644 --- a/nixos/doc/manual/release-notes/rl-2103.xml +++ b/nixos/doc/manual/release-notes/rl-2103.xml @@ -63,6 +63,14 @@ systemd-journal2gelf no longer parses json and expects the receiving system to handle it. How to achieve this with Graylog is described in this GitHub issue. + + + The option has been renamed to + . The path of font directory + has also been changed to /run/current-system/sw/share/X11/fonts, + for consistency with other X11 resources. + +