Add google-fonts package to flake

This commit is contained in:
NullBite 2024-02-05 13:30:37 +01:00
parent 808c759f89
commit 830b733653
Signed by: nullbite
GPG Key ID: 6C4D545385D4925A
4 changed files with 101 additions and 1 deletions

18
flake.lock generated
View File

@ -152,7 +152,8 @@
"nix-wsl": "nix-wsl",
"nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable",
"pkg-android-tools": "pkg-android-tools"
"pkg-android-tools": "pkg-android-tools",
"systems": "systems_2"
}
},
"systems": {
@ -169,6 +170,21 @@
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View File

@ -6,6 +6,9 @@
# ^^^^^^^^^^^^^ this part is optional
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# this seems to be a popular way to declare systems
systems.url = "github:nix-systems/default";
home-manager = {
url = "github:nix-community/home-manager/release-23.11";
inputs.nixpkgs.follows = "nixpkgs";
@ -51,6 +54,8 @@
inherit username mobileTimeZone self;
};
# funciton to generate packages for each system
eachSystem = lib.genAttrs (import inputs.systems);
# This function produces a module that adds the home-manager module to the
# system and configures the given module to the user's Home Manager
@ -138,6 +143,7 @@
# (extraS|s)pecialArgs to pass variables
nixosModules = (import ./modules/nixos) moduleInputs;
homeManagerModules = (import ./modules/home-manager) moduleInputs;
packages = eachSystem (system: import ./pkgs { inherit nixpkgs system; });
nixosConfigurations = {
slab = mkSystem {

8
pkgs/default.nix Normal file
View File

@ -0,0 +1,8 @@
{ nixpkgs, system, ... }:
let
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) callPackage;
in
{
google-fonts = callPackage ./google-fonts { };
}

View File

@ -0,0 +1,70 @@
{ lib
, stdenvNoCC
, fetchFromGitHub
, fonts ? []
}:
stdenvNoCC.mkDerivation {
pname = "google-fonts";
version = "unstable-2023-10-20";
# Adobe Blank is split out in a separate output,
# because it causes crashes with `libfontconfig`.
# It has an absurd number of symbols
outputs = [ "out" "adobeBlank" ];
src = fetchFromGitHub {
owner = "google";
repo = "fonts";
rev = "990be3ed8f77e31c26bf07b148d6a74b8e6241cf";
sha256 = "sha256-ffLXzaniHkWxGQpvlJpiO6/SAdbI3FONgTaq8Xu+WY0=";
};
postPatch = ''
# These directories need to be removed because they contain
# older or duplicate versions of fonts also present in other
# directories. This causes non-determinism in the install since
# the installation order of font files with the same name is not
# fixed.
rm -rv ofl/cabincondensed \
ofl/signikanegative \
ofl/signikanegativesc \
ofl/*_todelist \
axisregistry/tests/data
if find . -name "*.ttf" | sed 's|.*/||' | sort | uniq -c | sort -n | grep -v '^.*1 '; then
echo "error: duplicate font names"
exit 1
fi
'';
dontBuild = true;
# The font files are in the fonts directory and use three naming schemes:
# FamilyName-StyleName.ttf, FamilyName[param1,param2,...].ttf, and
# FamilyName.ttf. This installs all fonts if fonts is empty and otherwise
# only the specified fonts by FamilyName.
fonts = map (font: builtins.replaceStrings [" "] [""] font) fonts;
installPhase = ''
adobeBlankDest=$adobeBlank/share/fonts/truetype
install -m 444 -Dt $adobeBlankDest ofl/adobeblank/AdobeBlank-Regular.ttf
rm -r ofl/adobeblank
dest=$out/share/fonts/truetype
'' + (if fonts == [] then ''
find . -name '*.ttf' -exec install -m 444 -Dt $dest '{}' +
'' else ''
for font in $fonts; do
find . \( -name "$font-*.ttf" -o -name "$font[*.ttf" -o -name "$font.ttf" \) -exec install -m 444 -Dt $dest '{}' +
done
'');
meta = with lib; {
homepage = "https://fonts.google.com";
description = "Font files available from Google Fonts";
license = with licenses; [ asl20 ofl ufl ];
platforms = platforms.all;
hydraPlatforms = [];
maintainers = with maintainers; [ manveru ];
sourceProvenance = [ sourceTypes.binaryBytecode ];
};
}