77 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
| { stdenv, fetchzip, lib
 | |
| # To select only certain fonts, put a list of strings to `fonts`: every key in
 | |
| # ./shas.nix is an optional font
 | |
| , fonts ? [ ] }:
 | |
| 
 | |
| let
 | |
|   version = "version-20241013";
 | |
|   fontsShas = import ./shas.nix;
 | |
|   knownFonts = builtins.attrNames fontsShas;
 | |
|   selectedFonts = if (fonts == [ ]) then
 | |
|     knownFonts
 | |
|   else
 | |
|     let unknown = lib.subtractLists knownFonts fonts;
 | |
|     in if (unknown != [ ]) then
 | |
|       throw "Unknown font(s): ${lib.concatStringsSep " " unknown}"
 | |
|     else
 | |
|       fonts;
 | |
| 
 | |
|   # Filter the fonts by selectedFonts list
 | |
|   filteredFonts =
 | |
|     builtins.filter (fontName: builtins.elem fontName selectedFonts)
 | |
|     (builtins.attrNames fontsShas);
 | |
| 
 | |
|   # Function to generate a list of srcs that look like
 | |
|   #   [
 | |
|   #   (fetchurl {
 | |
|   #     name = "namezzxs"
 | |
|   #     url = "";
 | |
|   #     sha256 = "sha256-abc123...";
 | |
|   #   })
 | |
|   #   (fetchurl {
 | |
|   #     name = "namezzxy"
 | |
|   #     url = "";
 | |
|   #     sha256 = "sha256-def456...";
 | |
|   #   })
 | |
|   # ]
 | |
|   generateUrls = fontAttrs: fontName:
 | |
|     builtins.map (variant:
 | |
|       let sha = fontAttrs.${variant};
 | |
|       in fetchzip {
 | |
|         name = "${fontName}-${variant}";
 | |
|         url = "https://smc.org.in/downloads/fonts/${fontName}/${variant}.zip";
 | |
|         sha256 = sha;
 | |
|         stripRoot = false;
 | |
|       }) (builtins.attrNames fontAttrs);
 | |
| 
 | |
|   # Generate srcs for the filtered fonts
 | |
|   srcs = builtins.concatLists
 | |
|     (builtins.map (fontName: generateUrls fontsShas.${fontName} fontName)
 | |
|       filteredFonts);
 | |
| 
 | |
| in stdenv.mkDerivation (finalAttrs: {
 | |
|   inherit version;
 | |
|   inherit srcs;
 | |
|   pname = "smc-fonts";
 | |
|   sourceRoot = ".";
 | |
|   buildPhase = ''
 | |
|     echo "selected fonts are ${toString selectedFonts}"
 | |
|     ls *.otf *.ttf
 | |
|   '';
 | |
|   installPhase = ''
 | |
|     find -name \*.otf -exec mkdir -p $out/share/fonts/opentype/SMCFonts \; -exec mv {} $out/share/fonts/opentype/SMCFonts \;
 | |
|     find -name \*.ttf -exec mkdir -p $out/share/fonts/truetype/SMCFonts \; -exec mv {} $out/share/fonts/truetype/SMCFonts \;
 | |
|   '';
 | |
| 
 | |
|   meta = with lib; {
 | |
|     description = "Malayalam typefaces made by smc.org.in";
 | |
|     longDescription = ''
 | |
|       Swathanthra Malayalam Computing (SMC) is a free software collective engaged in the development, localization, standardization and popularization of various Free and Open Source Software in the Malayalam language. This derivation builds all fonts made by SMC.
 | |
|     '';
 | |
|     homepage = "https://smc.org.in/";
 | |
|     license = licenses.ofl;
 | |
|     platforms = platforms.all;
 | |
|     maintainers = with maintainers; [ aashiks ];
 | |
|   };
 | |
| })
 |