mirror of
https://github.com/sadan4/dotfiles.git
synced 2025-03-31 04:31:55 -04:00
start on fonts
This commit is contained in:
parent
3ce82782d8
commit
2201e3cd0d
3 changed files with 86 additions and 0 deletions
|
@ -18,6 +18,7 @@
|
|||
../../common/systemModules/kde.nix
|
||||
../../common/systemModules/tailscale.nix
|
||||
../../common/systemModules/gaming.nix
|
||||
../../common/systemModules/fonts
|
||||
../../common/systemModules/crypt.nix
|
||||
../../common/systemModules/printing.nix
|
||||
../../common/systemModules/stylix.nix
|
||||
|
|
85
common/systemModules/fonts/default.nix
Normal file
85
common/systemModules/fonts/default.nix
Normal file
|
@ -0,0 +1,85 @@
|
|||
{ pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
|
||||
mergeDefaults = (
|
||||
fontPathOrObj:
|
||||
if builtins.typeOf fontPathOrObj == "path" then
|
||||
mergeDefaults { src = fontPathOrObj; }
|
||||
else if builtins.typeOf fontPathOrObj == "set" then
|
||||
rec {
|
||||
name =
|
||||
if builtins.hasAttr "name" fontPathOrObj then
|
||||
fontPathOrObj.name
|
||||
else
|
||||
head (builtins.split "." (tail (builtins.split "/" (pathToStr fontPathOrObj.src))));
|
||||
description = "A font ${name}";
|
||||
}
|
||||
// fontPathOrObj
|
||||
else
|
||||
throw "Unknown type ${builtins.typeOf fontPathOrObj}, expected either a path or a set"
|
||||
);
|
||||
|
||||
head = list: builtins.elemAt list 0;
|
||||
tail = list: builtins.elemAt list (builtins.length list - 1);
|
||||
|
||||
pathToStr = (path: "${path}");
|
||||
|
||||
listToStr = (list: "[ ${lib.strings.concatStrings (lib.strings.intersperse ", " list)} ]");
|
||||
|
||||
mkFontInstaller =
|
||||
type:
|
||||
{
|
||||
name,
|
||||
src,
|
||||
description,
|
||||
}:
|
||||
pkgs.stdenvNoCC.mkDerivation {
|
||||
inherit src name;
|
||||
meta = {
|
||||
inherit description;
|
||||
};
|
||||
dontUnpack = true;
|
||||
dontConfigure = true;
|
||||
installPhase = ''
|
||||
mkdir -p $out/share/fonts
|
||||
cp -R $src $out/share/fonts/${type}
|
||||
'';
|
||||
};
|
||||
|
||||
fontFormatMap = {
|
||||
"otf" = mkFontInstaller "opentype";
|
||||
"ttf" = mkFontInstaller "truetype";
|
||||
"error" =
|
||||
{ src, ... }:
|
||||
throw "Invalid Font extension, got ${src}, while only ${
|
||||
listToStr (builtins.filter (key: key != "error") (builtins.attrNames fontFormatMap))
|
||||
} are supported";
|
||||
};
|
||||
|
||||
getFontInstaller =
|
||||
fontObj:
|
||||
(
|
||||
fontPath:
|
||||
fontFormatMap."${(fontExt: if builtins.hasAttr fontExt fontFormatMap then fontExt else "error") (
|
||||
tail (builtins.split "\\." (pathToStr fontPath))
|
||||
)}"
|
||||
)
|
||||
fontObj.src;
|
||||
|
||||
mkFontPackages =
|
||||
fontPathOrObj: (fontAsObj: getFontInstaller fontAsObj fontAsObj) (mergeDefaults fontPathOrObj);
|
||||
in
|
||||
{
|
||||
environment = {
|
||||
# I love typescript
|
||||
# Path | (({ name?: string; src: Path; } | { name: string; src: Derivation; }) & { description?: string; })
|
||||
systemPackages = lib.map mkFontPackages [
|
||||
./futura.otf
|
||||
];
|
||||
};
|
||||
fonts = {
|
||||
enableGhostscriptFonts = true;
|
||||
enableDefaultPackages = true;
|
||||
};
|
||||
}
|
BIN
common/systemModules/fonts/futura.otf
Normal file
BIN
common/systemModules/fonts/futura.otf
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue