first try to provide fonts as flake.

master
Denis Knauf 2023-06-17 00:20:53 +02:00
parent a9382f295f
commit 5963940d6b
4 changed files with 179 additions and 0 deletions

90
fetchfont.nix Normal file
View File

@ -0,0 +1,90 @@
# vim: set noet sw=2 ts=2 sts=2:
{lib, nixpkgs, sfnt2woff-zopfli, ...}:
{src ? null , srcs ? null, name ? "", pname ? "", version ? ""}:
let
name_ =
if "" != name
then name
else "${pname}-v${version}";
in stdenv.mkDerivation ({
name = name_;
nativeBuildInputs = with nixpkgs; [ sfnt2woff-zopfli unzip coreutils fontconfig woff2 ];
unpackPhase = ''
source_dir="$TMPDIR/src"
mkdir "$source_dir"
cd "$source_dir"
for s in $src $srcs
do
case "$s" in
*.zip|*.tar|*.tar.gz|*.tgz|*.tar.xz|*.txz|*.tar.bz2|*.tbz2)
unpackFile "$s"
;;
*)
cp -pr --reflink=auto -- "$s" "$(stripHash "$s")"
;;
esac
done
'';
buildPhase = ''
set -e
build_dir="$TMPDIR/build"
mkdir "$build_dir"
find "$source_dir" \( -name \*.otf -or -name \*.ttf -or -name \*.woff -or -name \*.woff2 \) -exec cp \{\} "$build_dir" \;
cd "$build_dir"
for s in *.otf *.ttf
do
bn="''${s%.otf}"
bn="''${bn%.ttf}"
if ! [ -e "$bn.woff" ]
then
echo "sfnt2woff-zopfli $s => $bn.woff"
sfnt2woff-zopfli "$s"
fi
if ! [ -e "$bn.woff2" ]
then
echo "woff2_compress $s => $bn.woff2"
woff2_compress "$s"
fi
done
for s in *.otf *.ttf *.woff
do
fc="`dirname "$s"`/`basename "$s"`.fc"
echo "fc-scan $s"
LANG=C LC_NUMERIC=C fc-scan --format 'family=%{family}
fullname=%{fullname}
postscriptname=%{postscriptname}
variable=%{variable}
slant=%{slant}
style=%{style}
weight=%{weight}
width=%{width}
' "$s" > "$fc"
done
for s in *.woff2
do
o="`dirname "$s"`/`basename "$s" .woff2`.woff.fc"
fc="`dirname "$s"`/`basename "$s"`.fc"
cp "$o" "$fc"
done
'';
installPhase = ''
cd "$TMPDIR"
mkdir -p $out/share/{doc/${name_},fonts/{opentype,truetype,WOFF,WOFF2}{,/.fc}}
find "$build_dir" -name \*.otf -exec cp \{\} $out/share/fonts/opentype \;
find "$build_dir" -name \*.ttf -exec cp \{\} $out/share/fonts/truetype \;
find "$build_dir" -name \*.woff -exec cp \{\} $out/share/fonts/WOFF \;
find "$build_dir" -name \*.woff2 -exec cp \{\} $out/share/fonts/WOFF2 \;
find "$build_dir" -name \*.otf.fc -exec cp \{\} $out/share/fonts/opentype/.fc \;
find "$build_dir" -name \*.ttf.fc -exec cp \{\} $out/share/fonts/truetype/.fc \;
find "$build_dir" -name \*.woff.fc -exec cp \{\} $out/share/fonts/WOFF/.fc \;
find "$build_dir" -name \*.woff2.fc -exec cp \{\} $out/share/fonts/WOFF2/.fc \;
find "$source_dir" -name \*.txt -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.md -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.adoc -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.html -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.css -exec cp \{\} $out/share/doc/${name_} \;
'';
} // (if null != src then { src = src; } else { srcs = srcs; }));

18
flake.nix Normal file
View File

@ -0,0 +1,18 @@
# vim: set noet sw=2 ts=2 sts=2:
{
description = "fonts";
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-23.05-small;
outputs = { self, nixpkgs }:
let
sfnt2woff-zopfli = callPackage ./sfnt2woff-zopfli.nix {};
fetchfont = callPackage ./fetchfont.nix {sfnt2woff-zopfli = sfnt2woff-zopfli; };
fonts = callPackage ./fonts.nix {fetchfont = fetchfont; };
in
fetchfont = fetchfont;
defaultPackage.x86_64-linux =
with import nixpkgs { system = "x86_64-linux"; };
fonts // { sfnt2woff-zopfli = sfnt2woff-zopfli; };
};
}

51
fonts.nix Normal file
View File

@ -0,0 +1,51 @@
# vim: set noet sw=2 ts=2 sts=2:
{lib, nixpkgs, fetchfont, ...}:
with nixpkgs; {
libre_barcode =
fetchfont rec {
pname = "LibreBarcode";
version = "1.008";
src = fetchurl { name = "${pname}-${version}.zip"; hash = "sha256-47ntjMcZR4j5ybGU2UAA5t4FTPvyAvTiDSKYGEdRDQU="; url = "https://github.com/graphicore/librebarcode/releases/download/v${version}/${pname}_v${version}.zip"; };
};
fira_code =
fetchfont rec {
pname = "FiraCode";
version = "6.2";
src = fetchurl { name = "${pname}-${version}.zip"; hash = "sha256-CUmRW6jrJNif2T0Qp/9iP0KDDXxf/D7L+WDk7K0+Pnk="; url = "https://github.com/tonsky/FiraCode/releases/download/${version}/Fira_Code_v${version}.zip"; };
};
fira_mono =
fetchfont rec {
pname = "FiraMono";
version = "4.202";
src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-2GJpZXOH8UTXe6EgERJPMPQj9wZy4VdtwW+Ri7Ft3+Q="; url = "https://github.com/mozilla/Fira/archive/refs/tags/${version}.tar.gz"; };
};
alegreya =
fetchfont rec {
pname = "Alegreya";
version = "2.008";
src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-RNrL48S2DCA7HWDwpV6/bBOYI/g/0jT5sHjs58sVZ24="; url = "https://github.com/huertatipografica/${pname}/archive/refs/tags/v${version}.tar.gz"; };
};
alegreya_sans =
fetchfont rec {
pname = "Alegreya-Sans";
version = "2.008";
src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-6lRVctSeGOZ11rcqZ1TaNE4kucrMPSt2wesr+a5zpAI="; url = "https://github.com/huertatipografica/${pname}/archive/refs/tags/v${version}.tar.gz"; };
};
inconsolata =
fetchfont rec {
pname = "Inconsolata";
version = "3.000";
src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-8tjYumyqeFqWbvF5loIqsUupHsQjQxop4bbEsUvEzaU="; url = "https://github.com/googlefonts/${pname}/archive/refs/tags/v${version}.tar.gz"; };
};
rubik_dirt =
fetchfont rec {
pname = "RubikDirt";
version = "2";
srcs = let baseurl = "https://github.com/NaN-xyz/Rubik-Filtered/raw/7f47b7f79f903e1d6af9883da43a84928e02b816/dirt/fonts";
in [
(fetchurl { name = "${pname}-Regular.ttf"; hash = "sha256-nePZKOQ0pH7IXXWQEsig6/6rCGAHbupOOYmkfF4hMSM="; url = "${baseurl}/ttf/${pname}-Regular.ttf"; })
(fetchurl { name = "${pname}-Regular.woff2"; hash = "sha256-xh1jUaN5FRaU/omXT7U9T9Qhu+Cl/YddAJnSpgCOqYk="; url = "${baseurl}/webfonts/${pname}-Regular.woff2"; })
];
};
};
};

20
sfnt2woff-zopfli.nix Normal file
View File

@ -0,0 +1,20 @@
# vim: set noet sw=2 ts=2 sts=2:
{lib, nixpkgs, ...}:
with nixpkgs;
stdenv.mkDerivation rec{
pname = "sfnt2woff-zopfli";
version = "1.3.1";
recursiveHash = true;
src = fetchFromGitHub {
owner = "bramstein";
repo = pname;
rev = "v${version}";
name = "${pname}-${version}";
sha256 = "wMB5B7kpARsZEXKF7XTdQP0+zbz97WS9GTI16hIQtxo=";
};
buildInputs = [ zlib ];
installPhase = ''
mkdir -p $out/bin
cp sfnt2woff-zopfli $out/bin
'';
};