From 830b7336531bb51c9e56d1fab6cd4c522e96f8de Mon Sep 17 00:00:00 2001 From: NullBite Date: Mon, 5 Feb 2024 13:30:37 +0100 Subject: [PATCH] Add google-fonts package to flake --- flake.lock | 18 ++++++++- flake.nix | 6 +++ pkgs/default.nix | 8 ++++ pkgs/google-fonts/default.nix | 70 +++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 pkgs/default.nix create mode 100644 pkgs/google-fonts/default.nix diff --git a/flake.lock b/flake.lock index 60848e7..6b523b6 100644 --- a/flake.lock +++ b/flake.lock @@ -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", diff --git a/flake.nix b/flake.nix index aca3c77..d7aec65 100644 --- a/flake.nix +++ b/flake.nix @@ -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 { diff --git a/pkgs/default.nix b/pkgs/default.nix new file mode 100644 index 0000000..6f39745 --- /dev/null +++ b/pkgs/default.nix @@ -0,0 +1,8 @@ +{ nixpkgs, system, ... }: +let + pkgs = import nixpkgs { inherit system; }; + inherit (pkgs) callPackage; +in +{ + google-fonts = callPackage ./google-fonts { }; +} diff --git a/pkgs/google-fonts/default.nix b/pkgs/google-fonts/default.nix new file mode 100644 index 0000000..bb3fc3a --- /dev/null +++ b/pkgs/google-fonts/default.nix @@ -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 ]; + }; +}