From 1a0dff2289a459052b513ff29ce811ad0ec2bd26 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sun, 22 Oct 2023 21:47:26 +0200 Subject: [PATCH] nix: refactor Nix flake files (#323) --- .prettierignore | 1 + flake.lock | 136 +++++++++++++----------- flake.nix | 276 ++++++++++++++++++++++++------------------------ 3 files changed, 213 insertions(+), 200 deletions(-) diff --git a/.prettierignore b/.prettierignore index c47d4a1..ecd3d1e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,3 +4,4 @@ /docs/ /build/ CHANGELOG.md +flake.lock diff --git a/flake.lock b/flake.lock index 9bf9edf..46da292 100644 --- a/flake.lock +++ b/flake.lock @@ -1,63 +1,79 @@ { - "nodes": { - "flake-parts": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib" - }, - "locked": { - "lastModified": 1680392223, - "narHash": "sha256-n3g7QFr85lDODKt250rkZj2IFS3i4/8HBU2yKHO3tqw=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "dcc36e45d054d7bb554c9cdab69093debd91a0b5", - "type": "github" - }, - "original": { - "id": "flake-parts", - "type": "indirect" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1680942619, - "narHash": "sha256-kpCW1IegAZfEjCVJW7IPN/hEtRL/9dxaFFYiHS5qVAk=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "6f95dd4fd050daf017cae2dfeb1cea1ec0e4c1a1", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-lib": { - "locked": { - "dir": "lib", - "lastModified": 1680213900, - "narHash": "sha256-cIDr5WZIj3EkKyCgj/6j3HBH4Jj1W296z7HTcWj1aMA=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "e3652e0735fbec227f342712f180f4f21f0594f2", - "type": "github" - }, - "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs" - } - } + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1696343447, + "narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4", + "type": "github" + }, + "original": { + "id": "flake-parts", + "type": "indirect" + } }, - "root": "root", - "version": 7 + "nixpkgs": { + "locked": { + "lastModified": 1697915759, + "narHash": "sha256-WyMj5jGcecD+KC8gEs+wFth1J1wjisZf8kVZH13f1Zo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "51d906d2341c9e866e48c2efcaac0f2d70bfd43e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1696019113, + "narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "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" + } + } + }, + "root": "root", + "version": 7 } diff --git a/flake.nix b/flake.nix index fb016d5..bbf2348 100644 --- a/flake.nix +++ b/flake.nix @@ -2,141 +2,128 @@ description = "Category Theory for Programmers"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.systems.url = "github:nix-systems/default"; - outputs = inputs @ { - self, - flake-parts, - nixpkgs, - }: - flake-parts.lib.mkFlake {inherit inputs;} { - systems = [ - "x86_64-linux" - "x86_64-darwin" - "aarch64-linux" - "aarch64-darwin" - ]; + outputs = inputs@{ self, flake-parts, nixpkgs, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = import inputs.systems; - perSystem = { - config, - pkgs, - system, - ... - }: let - inherit (nixpkgs) lib; + perSystem = { config, pkgs, system, lib, ... }: + let + pkgs = nixpkgs.legacyPackages.${system}; - pkgs = nixpkgs.legacyPackages.${system}; + ######################################################################## + # LaTeX Font + inconsolata-lgc-latex = pkgs.stdenvNoCC.mkDerivation { + name = "inconsolata-lgc-latex"; + pname = "inconsolata-lgc-latex"; - ######################################################################## - # LaTeX Font - inconsolata-lgc-latex = pkgs.stdenvNoCC.mkDerivation { - name = "inconsolata-lgc-latex"; - pname = "inconsolata-lgc-latex"; + src = pkgs.inconsolata-lgc; - src = pkgs.inconsolata-lgc; + dontConfigure = true; + sourceRoot = "."; - dontConfigure = true; - sourceRoot = "."; + installPhase = '' + runHook preInstall - installPhase = '' - runHook preInstall + find $src -name '*.ttf' -exec install -m644 -Dt $out/fonts/truetype/public/inconsolata-lgc/ {} \; + find $src -name '*.otf' -exec install -m644 -Dt $out/fonts/opentype/public/inconsolata-lgc/ {} \; - find $src -name '*.ttf' -exec install -m644 -Dt $out/fonts/truetype/public/inconsolata-lgc/ {} \; - find $src -name '*.otf' -exec install -m644 -Dt $out/fonts/opentype/public/inconsolata-lgc/ {} \; + runHook postInstall + ''; - runHook postInstall - ''; - - tlType = "run"; - }; - - ######################################################################## - # LaTeX Environment - texliveEnv = pkgs.texlive.combine { - inherit - (pkgs.texlive) - adjustbox - alegreya - babel - bookcover - catchfile - chngcntr - collectbox - currfile - emptypage - enumitem - environ - fgruler - fontaxes - framed - fvextra - idxlayout - ifmtarg - ifnextok - ifplatform - imakeidx - import - inconsolata - l3packages - lettrine - libertine - libertinus-fonts - listings - mdframed - microtype - minifp - minted - mweights - needspace - newtx - noindentafter - nowidow - scheme-medium - subfigure - subfiles - textpos - tcolorbox - tikz-cd - titlecaps - titlesec - todonotes - trimspaces - upquote - wrapfig - xifthen - xpatch - xstring - zref - ; - - inconsolata-lgc-latex = { - pkgs = [inconsolata-lgc-latex]; + tlType = "run"; }; - }; - commonAttrs = { - nativeBuildInputs = [ - texliveEnv - ( - pkgs.python3.withPackages (p: [p.pygments p.pygments-style-github]) - ) - pkgs.which - ]; - }; + ######################################################################## + # LaTeX Environment + texliveEnv = pkgs.texlive.combine { + inherit + (pkgs.texlive) + adjustbox + alegreya + babel + bookcover + catchfile + chngcntr + collectbox + currfile + emptypage + enumitem + environ + fgruler + fontaxes + framed + fvextra + idxlayout + ifmtarg + ifnextok + ifplatform + imakeidx + import + inconsolata + l3packages + lettrine + libertine + libertinus-fonts + listings + mdframed + microtype + minifp + minted + mweights + needspace + newtx + noindentafter + nowidow + scheme-medium + subfigure + subfiles + textpos + tcolorbox + tikz-cd + titlecaps + titlesec + todonotes + trimspaces + upquote + wrapfig + xifthen + xpatch + xstring + zref + ; - mkLatex = variant: edition: let - maybeVariant = lib.optionalString (variant != null) "-${variant}"; - maybeEdition = lib.optionalString (edition != null) "-${edition}"; - variantStr = - if variant == null - then "reader" - else variant; - basename = "ctfp-${variantStr}${maybeEdition}"; - version = self.shortRev or self.lastModifiedDate; - suffix = maybeVariant + maybeEdition; - fullname = "ctfp${suffix}"; - in - pkgs.stdenvNoCC.mkDerivation (commonAttrs - // { + inconsolata-lgc-latex = { + pkgs = [ inconsolata-lgc-latex ]; + }; + }; + + commonAttrs = { + nativeBuildInputs = [ + texliveEnv + ( + pkgs.python3.withPackages (p: [ p.pygments p.pygments-style-github ]) + ) + pkgs.which + ]; + }; + + mkLatex = variant: edition: + let + maybeVariant = lib.optionalString (variant != null) "-${variant}"; + maybeEdition = lib.optionalString (edition != null) "-${edition}"; + variantStr = + if variant == null + then "reader" + else variant; + basename = "ctfp-${variantStr}${maybeEdition}"; + version = self.shortRev or self.lastModifiedDate; + suffix = maybeVariant + maybeEdition; + fullname = "ctfp${suffix}"; + in + pkgs.stdenvNoCC.mkDerivation (commonAttrs + // { inherit basename version; name = basename; @@ -161,34 +148,43 @@ runHook postBuild ''; - installPhase = "install -m 0644 -vD ctfp.pdf \"$out/${fullname}.pdf\""; + installPhase = " + runHook preInstall + + install -m 0644 -vD ctfp.pdf \"$out/${fullname}.pdf\" + + runHook postInstall + "; passthru.packageName = fullname; }); - editions = [null "scala" "ocaml" "reason"]; - variants = [null "print"]; - in rec { - formatter = pkgs.alejandra; + editions = [ null "scala" "ocaml" "reason" ]; + variants = [ null "print" ]; + in + { + formatter = pkgs.nixpkgs-fmt; - packages = lib.listToAttrs (lib.concatMap (variant: - map (edition: rec { - name = value.packageName; - value = mkLatex variant edition; - }) - editions) - variants); + packages = lib.listToAttrs (lib.concatMap + (variant: + map + (edition: rec { + value = mkLatex variant edition; + name = value.packageName; + }) + editions) + variants); - # nix develop . - devShells.default = pkgs.mkShellNoCC (commonAttrs - // { + # nix develop . + devShells.default = pkgs.mkShellNoCC (commonAttrs + // { nativeBuildInputs = commonAttrs.nativeBuildInputs - ++ [ + ++ [ pkgs.git pkgs.gnumake ]; }); - }; + }; }; }