From 587fad82e8315cea705cfdcae1328e0da3756555 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Mon, 15 Jul 2024 19:53:04 +0000 Subject: [PATCH] remove flake-utils, clean up --- flake.lock | 41 +++--- flake.nix | 326 +++++++++++++++++------------------------ nix/buildLocalFont.nix | 58 ++++++++ 3 files changed, 211 insertions(+), 214 deletions(-) create mode 100644 nix/buildLocalFont.nix diff --git a/flake.lock b/flake.lock index 83324d4..fe5c957 100644 --- a/flake.lock +++ b/flake.lock @@ -5,9 +5,7 @@ "nixpkgs": [ "nixpkgs" ], - "utils": [ - "flake-utils" - ] + "utils": "utils" }, "locked": { "lastModified": 1720584070, @@ -23,24 +21,6 @@ "url": "https://git.mildlyfunctional.gay/artemist/packages.git" } }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1721066811, @@ -59,7 +39,6 @@ "root": { "inputs": { "artemist": "artemist", - "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } }, @@ -77,6 +56,24 @@ "repo": "default", "type": "github" } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 95c5d25..8874cc8 100644 --- a/flake.nix +++ b/flake.nix @@ -1,11 +1,9 @@ { description = "Various fonts I've found online"; inputs = { - flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:nixos/nixpkgs"; artemist = { url = "git+https://git.mildlyfunctional.gay/artemist/packages.git"; - inputs.utils.follows = "flake-utils"; inputs.nixpkgs.follows = "nixpkgs"; }; }; @@ -14,183 +12,137 @@ { self, nixpkgs, - flake-utils, artemist, }: with nixpkgs.lib; + let + forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed; + makePkgs = + system: + import nixpkgs { + inherit system; + overlays = [ + self.overlays.default + artemist.overlays.default + ]; + config.allowUnfree = true; + }; + localFonts = [ + { + # Popular font, used on NYC Subway + name = "Akzidenz-Grotesk Pro"; + dir = ./Akzidenz-Grotesk-Pro; + license = licenses.unfree; + author = "Berthold Type Foundry"; + } + { + # Font used on DSB departure boards + name = "AtB"; + dir = ./AtB; + license = licenses.unfree; + author = "Kontrapunkt"; + } + { + # Brussels-specific font + name = "Brusseline"; + dir = ./Brusseline; + license = licenses.unfree; + author = "Eric de Berranger"; + } + { + # Free handwriting font + name = "Caveat"; + files = [ ./Caveat.ttf ]; + license = licenses.ofl; + author = "Pablo Impallari and Alexi Vanyashin"; + } + { + # Twitter custom font, based on GT America + name = "Chirp"; + dir = ./Chirp; + license = licenses.unfree; + author = "Grilli Type Foundry"; + } + { + # Deutsche Bahn website font + name = "DB Screen"; + dir = ./DB-Screen; + license = licenses.unfree; + author = "URW Type Foundry"; + } + { + # Font with a large number of invented scripts + name = "Fairfax HD"; + dir = ./Fairfax-HD; + license = licenses.ofl; + author = "Kreative Software"; + } + { + # Popular font, used on Amtrak + name = "Frutiger"; + dir = ./Frutiger; + license = licenses.unfree; + author = "Adrian Frutiger"; + } + { + # Discord custom font + name = "gg sans"; + dir = ./ggsans; + license = licenses.unfree; + author = "Colophon Foundry"; + } + { + # Several related fonts used for London Underground: + # * Johnston 100: Extension of original Johnston + # * New Johnston: Modification of original Johnston + # * P22 Underground: Version sold to public + name = "Johnston"; + dir = ./Johnston; + license = licenses.unfree; + author = "Edward Johnston et al"; + } + { + # Mysterious all-uppercase hand-style font for MIVB/STIB + name = "MIVB STIB"; + dir = ./MIVB; + license = licenses.unfree; + author = "unknown"; + } + { + # Also called "NR Brunel, used on UK railways in 2010s + name = "New Brunel"; + dir = ./New-Brunel; + license = licenses.unfree; + author = "David Quay"; + } + { + # Modern expansion of machine-readable font + name = "OCR-B"; + files = [ ./OCR-B-Regular.otf ]; + license = licenses.cc-by-40; + author = "Matthew Anderson"; + } + { + # Custom font used for RATP services in Parism + name = "Parisine"; + dir = ./Parisine; + license = licenses.unfree; + author = "Jean-François Porchez"; + } + { + # Font used on DSB website, similar to signage + name = "Via"; + dir = ./Via; + license = licenses.unfree; + author = "Kontrapunkt"; + } + ]; + in { overlays.default = ( final: prev: let - localFonts = [ - { - # Popular font, used on NYC Subway - name = "Akzidenz-Grotesk Pro"; - dir = ./Akzidenz-Grotesk-Pro; - license = licenses.unfree; - author = "Berthold Type Foundry"; - } - { - # Font used on DSB departure boards - name = "AtB"; - dir = ./AtB; - license = licenses.unfree; - author = "Kontrapunkt"; - } - { - # Brussels-specific font - name = "Brusseline"; - dir = ./Brusseline; - license = licenses.unfree; - author = "Eric de Berranger"; - } - { - # Free handwriting font - name = "Caveat"; - files = [ ./Caveat.ttf ]; - license = licenses.ofl; - author = "Pablo Impallari and Alexi Vanyashin"; - } - { - # Twitter custom font, based on GT America - name = "Chirp"; - dir = ./Chirp; - license = licenses.unfree; - author = "Grilli Type Foundry"; - } - { - # Deutsche Bahn website font - name = "DB Screen"; - dir = ./DB-Screen; - license = licenses.unfree; - author = "URW Type Foundry"; - } - { - # Font with a large number of invented scripts - name = "Fairfax HD"; - dir = ./Fairfax-HD; - license = licenses.ofl; - author = "Kreative Software"; - } - { - # Popular font, used on Amtrak - name = "Frutiger"; - dir = ./Frutiger; - license = licenses.unfree; - author = "Adrian Frutiger"; - } - { - # Discord custom font - name = "gg sans"; - dir = ./ggsans; - license = licenses.unfree; - author = "Colophon Foundry"; - } - { - # Several related fonts used for London Underground: - # * Johnston 100: Extension of original Johnston - # * New Johnston: Modification of original Johnston - # * P22 Underground: Version sold to public - name = "Johnston"; - dir = ./Johnston; - license = licenses.unfree; - author = "Edward Johnston et al"; - } - { - # Mysterious all-uppercase hand-style font for MIVB/STIB - name = "MIVB STIB"; - dir = ./MIVB; - license = licenses.unfree; - author = "unknown"; - } - { - # Also called "NR Brunel, used on UK railways in 2010s - name = "New Brunel"; - dir = ./New-Brunel; - license = licenses.unfree; - author = "David Quay"; - } - { - # Modern expansion of machine-readable font - name = "OCR-B"; - files = [ ./OCR-B-Regular.otf ]; - license = licenses.cc-by-40; - author = "Matthew Anderson"; - } - { - # Custom font used for RATP services in Parism - name = "Parisine"; - dir = ./Parisine; - license = licenses.unfree; - author = "Jean-François Porchez"; - } - { - # Font used on DSB website, similar to signage - name = "Via"; - dir = ./Via; - license = licenses.unfree; - author = "Kontrapunkt"; - } - ]; - buildLocalFont = - { - name, - files ? [ ], - dir ? null, - license, - author, - }: - let - types = { - ttf = "truetype"; - otf = "opentype"; - }; - - pathEndsWith = - suffix: path: - let - str = toString path; - sufLen = stringLength suffix; - sLen = stringLength str; - in - sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str; - - copyType = - extension: pathName: - let - filteredFiles = filter (pathEndsWith ("." + extension)) files; - filename = file: lists.last (strings.splitString "/" (toString file)); - in - (optionalString (filteredFiles != [ ]) '' - mkdir -p $out/share/fonts/${pathName} - '') - + concatStringsSep "\n" ( - map (file: "cp -v ${file} $out/share/fonts/${pathName}/${filename file}") filteredFiles - ); - - copyTypeDir = extension: pathName: '' - if [ -n "$(shopt -s nullglob; echo ${dir}/*.${extension})" ]; then - mkdir -p $out/share/fonts/${pathName} - cp -v -t $out/share/fonts/${pathName} ${dir}/*.${extension} - fi - ''; - - in - final.stdenvNoCC.mkDerivation { - inherit name; - dontUnpack = true; - installPhase = - mapAttrsToList copyType types - ++ optional (dir != null) (mapAttrsToList copyTypeDir types); - - passthru.font = true; - meta = { - inherit license; - platforms = platforms.all; - maintainers = [ maintainers.artemist ]; - description = "${name} font by ${author}"; - }; - }; + buildLocalFont = final.callPackage ./nix/buildLocalFont.nix { }; in { extraFonts = listToAttrs ( @@ -204,25 +156,14 @@ }; } ); - } - // flake-utils.lib.eachDefaultSystem ( - system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ - self.overlays.default - artemist.overlays.default - ]; - config.allowUnfree = true; - }; - in - { - packages = builtins.listToAttrs ( + + packages = forAllSystems ( + system: + builtins.listToAttrs ( map (name: { inherit name; - value = pkgs.${name} // { + value = (makePkgs system).${name} // { type = "derivation"; name = "dummy-attrset"; }; @@ -231,8 +172,9 @@ "extraFonts" "appleFonts" ] - ); - formatter = pkgs.nixfmt-rfc-style; - } - ); + ) + ); + + formatter = forAllSystems (system: (makePkgs system).nixfmt-rfc-style); + }; } diff --git a/nix/buildLocalFont.nix b/nix/buildLocalFont.nix new file mode 100644 index 0000000..96c91a3 --- /dev/null +++ b/nix/buildLocalFont.nix @@ -0,0 +1,58 @@ +{ lib, stdenvNoCC }: +{ + name, + files ? [ ], + dir ? null, + license, + author, +}: +let + types = { + ttf = "truetype"; + otf = "opentype"; + }; + + pathEndsWith = + suffix: path: + let + str = toString path; + sufLen = lib.stringLength suffix; + sLen = lib.stringLength str; + in + sufLen <= sLen && suffix == lib.substring (sLen - sufLen) sufLen str; + + copyType = + extension: pathName: + let + filteredFiles = lib.filter (pathEndsWith ("." + extension)) files; + filename = file: lib.lists.last (lib.strings.splitString "/" (toString file)); + in + (lib.optionalString (filteredFiles != [ ]) '' + mkdir -p $out/share/fonts/${pathName} + '') + + lib.concatStringsSep "\n" ( + map (file: "cp -v ${file} $out/share/fonts/${pathName}/${filename file}") filteredFiles + ); + + copyTypeDir = extension: pathName: '' + if [ -n "$(shopt -s nullglob; echo ${dir}/*.${extension})" ]; then + mkdir -p $out/share/fonts/${pathName} + cp -v -t $out/share/fonts/${pathName} ${dir}/*.${extension} + fi + ''; +in +stdenvNoCC.mkDerivation { + inherit name; + dontUnpack = true; + installPhase = + lib.mapAttrsToList copyType types + ++ lib.optional (dir != null) (lib.mapAttrsToList copyTypeDir types); + + passthru.font = true; + meta = with lib; { + inherit license; + platforms = platforms.all; + maintainers = [ maintainers.artemist ]; + description = "${name} font by ${author}"; + }; +}