From 80c347ef1ca5a2a1bb32ebf6fd183266c415792a Mon Sep 17 00:00:00 2001 From: Jacob Birkett Date: Sat, 10 Feb 2024 13:36:03 -0700 Subject: [PATCH] Clean up the Nix flake, recommended practices, provide overlay (#6) * flake: update description * flake: add alejandra as formatter * flake: format nix code * flake: make systems overrideable * flake: replace forAllSystems with eachSystem * flake: inherit lib at top level * flake: move usages of with to smallest scopes * flake: introduce overlay * flake: package: remove needless unpackPase override * flake: devShell: replace buildInputs with packages * chore: move alejandra to pre-commit-hook * chore: inherit from nixpkgs.lib not nixpkgs * chore: remove some lets add others * chore: change mkShell back to buildInputs --------- Co-authored-by: Daylin Morgan --- .pre-commit-config.yaml | 5 +++ flake.lock | 18 +++++++- flake.nix | 96 +++++++++++++++++++++-------------------- 3 files changed, 71 insertions(+), 48 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9dd7cea..7f3e77d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,3 +12,8 @@ repos: - id: ruff-format - id: ruff args: [ --fix ] + - repo: https://github.com/kamadorueda/alejandra + rev: 3.0.0 + hooks: + # Requires Alejandra to be previously installed in the system + - id: alejandra-system diff --git a/flake.lock b/flake.lock index f707b1c..770a058 100644 --- a/flake.lock +++ b/flake.lock @@ -18,7 +18,23 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 55d720f..149b3d1 100644 --- a/flake.nix +++ b/flake.nix @@ -1,58 +1,60 @@ { - description = "brain"; - inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + description = "A script to patch the MonoLisa font with Nerd Fonts glyphs."; - outputs = inputs @ { + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = { self, nixpkgs, + systems, }: let - inherit (nixpkgs.lib) genAttrs; - forAllSystems = f: - genAttrs - ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"] - (system: f nixpkgs.legacyPackages.${system}); + inherit (nixpkgs.lib) genAttrs makeBinPath; + eachSystem = fn: + genAttrs (import systems) + (system: + fn system + (import nixpkgs { + localSystem.system = system; + overlays = [self.overlays.default]; + })); in { - packages = forAllSystems ( - pkgs: - with pkgs; { - default = stdenv.mkDerivation { - name = "monolisa-nerdfont-patch"; - src = ./.; - nativeBuildInputs = [ makeWrapper ]; - buildInputs = [ - fontforge - python3 - ]; - unpackPhase = ":"; - buildPhase = ":"; - installPhase = '' - mkdir -p $out/bin - install -m755 -D ${./patch-monolisa} $out/bin/monolisa-nerdfont-patch - install -m755 -D ${./font-patcher} $out/bin/font-patcher - cp -r ${./bin} $out/bin/bin - cp -r ${./src} $out/bin/src - ''; - postFixup = '' - wrapProgram $out/bin/monolisa-nerdfont-patch \ - --set PATH ${lib.makeBinPath [ - fontforge - ]} + overlays = { + default = final: _prev: let + pkgs = final; + in { + monolisa-nerdfont-patch = pkgs.stdenv.mkDerivation { + name = "monolisa-nerdfont-patch"; + src = ./.; + nativeBuildInputs = with pkgs; [makeWrapper]; + buildInputs = with pkgs; [fontforge python3]; + buildPhase = ":"; + installPhase = '' + mkdir -p $out/bin + install -m755 -D ${./patch-monolisa} $out/bin/monolisa-nerdfont-patch + install -m755 -D ${./font-patcher} $out/bin/font-patcher + cp -r ${./bin} $out/bin/bin + cp -r ${./src} $out/bin/src ''; + postFixup = '' + wrapProgram $out/bin/monolisa-nerdfont-patch \ + --set PATH ${makeBinPath (with final; [fontforge])} + ''; + }; }; - } - ); + }; - devShells = forAllSystems ( - pkgs: - with pkgs; { - default = mkShell { - buildInputs = [ - fontforge - python3 - pre-commit - ]; - }; - } - ); + packages = eachSystem (system: pkgs: { + default = self.packages.${system}.monolisa-nerdfont-patch; + monolisa-nerdfont-patch = pkgs.monolisa-nerdfont-patch; + }); + + devShells = eachSystem (_: pkgs: { + default = pkgs.mkShell { + buildInputs = with pkgs; [fontforge python3 pre-commit]; + }; + }); }; }