From 821b4f0d152855850705881ffd0def4c49bbcbe9 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 9 Apr 2021 16:01:42 +0200 Subject: [PATCH] rplot: patch scales and fontconfig --- garlic/pp/rplot.nix | 121 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 4 deletions(-) diff --git a/garlic/pp/rplot.nix b/garlic/pp/rplot.nix index 12b3b47..35609a2 100644 --- a/garlic/pp/rplot.nix +++ b/garlic/pp/rplot.nix @@ -3,7 +3,16 @@ , rWrapper , rPackages , fontconfig +, dejavu_fonts +, liberation_ttf +, noto-fonts +, makeFontsConf +, makeFontsCache , jq +, fetchFromGitHub +, writeText +, runCommand +, glibcLocales }: { @@ -16,19 +25,123 @@ with stdenv.lib; let - customR = rWrapper.override { - packages = with rPackages; [ tidyverse viridis egg ] ++ extraRPackages; + scalesPatched = with rPackages; buildRPackage { + name = "scales"; + src = fetchFromGitHub { + owner = "mikmart"; + repo = "scales"; + #ref = "label-bytes"; + rev = "fa7d91c765b6b5d2f682c7c22e0478d96c2ea76c"; + sha256 = "10dsyxp9pxzdmg04xpnrxqhc4qfhbkr3jhx8whfr7z27wgfrr1n3"; + }; + propagatedBuildInputs = [ farver labeling lifecycle munsell R6 RColorBrewer viridisLite ]; + nativeBuildInputs = [ farver labeling lifecycle munsell R6 RColorBrewer viridisLite ]; }; + customR = rWrapper.override { + packages = with rPackages; [ scalesPatched tidyverse viridis egg + Cairo extrafont ] ++ extraRPackages; + }; + + myFonts = [ + dejavu_fonts + #noto-fonts + #liberation_ttf + ]; + + cacheConf = + let + cache = makeFontsCache { fontDirectories = myFonts; }; + in + writeText "fc-00-nixos-cache.conf" '' + + + + + ${concatStringsSep "\n" (map (font: "${font}") myFonts)} + ${optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' + + ${cache} + ''} + + ''; + + # default fonts configuration file + # priority 52 + defaultFontsConf = + let genDefault = fonts: name: + optionalString (fonts != []) '' + + ${name} + + ${concatStringsSep "" + (map (font: '' + ${font} + '') fonts)} + + + ''; + in + writeText "fc-52-nixos-default-fonts.conf" '' + + + + + ${genDefault [ "DejaVu Sans" ] "sans-serif"} + ${genDefault [ "DejaVu Serif" ] "serif"} + ${genDefault [ "DejaVu Sans Mono" ] "monospace"} + ${genDefault [ "Noto Color Emoji"] "emoji"} + + ''; + + fontConfPath = + let + fixedConf = runCommand "fonts-fixed.conf" { + preferLocalBuild = true; + } '' + head --lines=-2 ${fontconfig.out}/etc/fonts/fonts.conf >> $out + + cat >> $out << 'EOF' + + conf.d + EOF + + tail -2 ${fontconfig.out}/etc/fonts/fonts.conf >> $out + ''; + in + runCommand "fontconfig-conf" { + preferLocalBuild = true; + } '' + dst=$out/etc/fonts/conf.d + mkdir -p $dst + # fonts.conf + ln -s ${fixedConf} $dst/../fonts.conf + + # fontconfig default config files + ln -s ${fontconfig.out}/etc/fonts/conf.d/*.conf \ + $dst/ + + # 00-nixos-cache.conf + ln -s ${cacheConf} $dst/00-nixos-cache.conf + + # 52-nixos-default-fonts.conf + ln -s ${defaultFontsConf} $dst/52-nixos-default-fonts.conf + ''; + in stdenv.mkDerivation { name = "plot"; - buildInputs = [ customR jq ]; + buildInputs = [ customR jq fontconfig glibcLocales ]; preferLocalBuild = true; dontPatchShebangs = true; phases = [ "installPhase" ]; installPhase = '' - export FONTCONFIG_PATH=${fontconfig.out}/etc/fonts + export FONTCONFIG_PATH=${fontConfPath}/etc/fonts/ + export LANG=en_US.UTF-8 + mkdir -p $out cd $out dataset="${dataset}"