{ config, lib, pkgs, ... }: let cfg = config.programs._st; toString = x: if lib.isBool x then (if x then "true" else "false") else builtins.toString x; # http://freedesktop.org/software/fontconfig/fontconfig-user.html generateFontConfigString = name: attrs: name + lib.optionalString (attrs != {}) ( ":" + lib.concatStringsSep ":" ( lib.mapAttrsToList (key: value: "${key}=${toString value}") attrs ) ) ; themed-st = pkgs.stdenv.mkDerivation { name = "themed-st"; dontUnpack = true; buildInputs = [ pkgs.makeWrapper ]; installPhase = '' mkdir -p $out/bin makeWrapper ${pkgs.st}/bin/st $out/bin/st \ --add-flags '-f"${generateFontConfigString cfg.font.name cfg.font.attrs}"' ''; }; in { options.programs._st = { enable = lib.mkEnableOption "enables theming st with home manager"; font = { name = lib.mkOption { type = lib.types.str; example = "JetBrainsMonoNL Nerd Font Mono"; default = "monospace"; }; attrs = lib.mkOption { type = lib.types.attrs; default = {}; example = { size = 12; antialias = true; autohint = true; }; }; }; }; config = lib.mkIf cfg.enable { home.packages = [ themed-st ]; }; }