diff --git a/default.nix b/default.nix index a0619731..eae45ac8 100644 --- a/default.nix +++ b/default.nix @@ -1,5 +1,6 @@ -# nix-shell --pure --command 'cd src; make' let - nixpkgs = import {}; -in - nixpkgs.callPackage ./shell.nix {} + rev = "cecfd08d13ddef8a79f277e67b8084bd9afa1586"; + url = "https://github.com/edolstra/flake-compat/archive/${rev}.tar.gz"; + flake = import (fetchTarball url) { src = ./.; }; + inNixShell = builtins.getEnv "IN_NIX_SHELL" != ""; +in if inNixShell then flake.shellNix else flake.defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..c53881bd --- /dev/null +++ b/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1599158497, + "narHash": "sha256-lHTfnlSK+hm2yvGuKvGe6+Wc+TJf/h6SNLd0u+K+DdE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fa3fb57d322a7f1bc93f763b10961144b37b9633", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-20.03", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1598466101, + "narHash": "sha256-JPhv+Ay98KMWRVRFlLEK9+eLpvNjhTBGWdFKZsE97ck=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a586a6b966d59f53f45a04f8891fbc017dc09dbe", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..a32f2508 --- /dev/null +++ b/flake.nix @@ -0,0 +1,139 @@ +{ + description = "Category Theory for Programmers"; + + inputs.nixpkgs.url = "nixpkgs/nixos-20.03"; + inputs.utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + inherit (nixpkgs) lib; + + ########################################################################### + # LaTeX Environment + texliveEnv = pkgs.texlive.combine { + inherit (pkgs.texlive) + bookcover + textpos + fgruler + tcolorbox + fvextra + framed + newtx + nowidow + emptypage + wrapfig + subfigure + adjustbox + collectbox + tikz-cd + imakeidx + idxlayout + titlesec + subfiles + lettrine + upquote + libertine + mweights + fontaxes + mdframed + needspace + xifthen + ifnextok + currfile + noindentafter + ifmtarg + scheme-medium + listings + minted + microtype + babel + todonotes + chngcntr + ifplatform + xstring + minifp + titlecaps + enumitem + environ + trimspaces + l3packages + zref + catchfile + import + ; + }; + + ########################################################################### + # Python Environment + + # Pin the Python version and its associated package set in a single place. + python = pkgs.python38; + pythonPkgs = pkgs.python38Packages; + + pygments-style-github = pythonPkgs.buildPythonPackage rec { + pname = "pygments-style-github"; + version = "0.4"; + + doCheck = false; # Hopefully someone else has run the tests. + + src = pythonPkgs.fetchPypi { + inherit pname version; + sha256 = "19zl8l5fyb8z3j8pdlm0zbgag669af66f8gn81ichm3x2hivvjhg"; + }; + + # Anything depending on this derivation is probably also gonna want + # pygments to be available. + propagatedBuildInputs = with pythonPkgs; [ pygments ]; + }; + + pythonEnv = python.withPackages ( + pyPkgs: with pyPkgs; [ + pygments + pygments-style-github + ] + ); + + mkPackageName = edition: + "ctfp${lib.optionalString (edition != null) "-${edition}"}"; + + mkPackage = isShell: edition: pkgs.stdenv.mkDerivation { + name = mkPackageName edition; + src = if isShell then null else self; + + makeFlags = [ + "-C" "src" "OUTPUT_DIR=$(out)" + "GIT_VER=${self.rev or self.lastModifiedDate}" + ]; + + buildFlags = lib.optional (edition != null) edition; + + dontInstall = true; + + FONTCONFIG_FILE = pkgs.makeFontsConf { + fontDirectories = with pkgs; [ inconsolata-lgc libertine libertinus ]; + }; + + buildInputs = with pkgs; [ + # Misc. build tooling. + gnumake + git + python3Packages.virtualenv + which + # LaTeX Environment (with all associated libraries and packages). + texliveEnv + # Python Environment (with all associated libraries and packages). + pythonEnv + ]; + }; + + editions = [ null "scala" "ocaml" ]; + + in { + packages = lib.listToAttrs (map (edition: { + name = mkPackageName edition; + value = mkPackage false edition; + }) editions); + defaultPackage = self.packages.${system}.ctfp; + devShell = mkPackage true null; + }); +} diff --git a/pinned.nix b/pinned.nix deleted file mode 100644 index 042d96a9..00000000 --- a/pinned.nix +++ /dev/null @@ -1,8 +0,0 @@ -# This commit corresponds to a recent (as of 2 August 2020) pin of the 20.03 -# nixpkgs branch. -import ( - builtins.fetchTarball { - url = "https://github.com/nixos/nixpkgs/archive/7dc4385dc7b5b2c0dbfecd774cebbc87ac05c061.tar.gz"; - sha256 = "10xr87ilxypz8fya6q42vsk5rmavv1bjrxhkznr9fvn514am58xb"; - } -) diff --git a/shell.nix b/shell.nix deleted file mode 100644 index d952f1db..00000000 --- a/shell.nix +++ /dev/null @@ -1,106 +0,0 @@ -{ pkgs ? import ./pinned.nix {} }: - -let - ############################################################################# - # LaTeX Environment - texliveEnv = pkgs.texlive.combine { - inherit (pkgs.texlive) - bookcover - textpos - fgruler - tcolorbox - fvextra - framed - newtx - nowidow - emptypage - wrapfig - subfigure - adjustbox - collectbox - tikz-cd - imakeidx - idxlayout - titlesec - subfiles - lettrine - upquote - libertine - mweights - fontaxes - mdframed - needspace - xifthen - ifnextok - currfile - noindentafter - ifmtarg - scheme-medium - listings - minted - microtype - babel - todonotes - chngcntr - ifplatform - xstring - minifp - titlecaps - enumitem - environ - trimspaces - l3packages - zref - catchfile - import - ; - }; - - ############################################################################# - # Python Environment - - # Pin the Python version and its associated package set in a single place. - python = pkgs.python38; - pythonPkgs = pkgs.python38Packages; - - pygments-style-github = pythonPkgs.buildPythonPackage rec { - pname = "pygments-style-github"; - version = "0.4"; - - doCheck = false; # Hopefully someone else has run the tests. - - src = pythonPkgs.fetchPypi { - inherit pname version; - sha256 = "19zl8l5fyb8z3j8pdlm0zbgag669af66f8gn81ichm3x2hivvjhg"; - }; - - # Anything depending on this derivation is probably also gonna want - # pygments to be available. - propagatedBuildInputs = with pythonPkgs; [ pygments ]; - }; - - pythonEnv = python.withPackages ( - pyPkgs: with pyPkgs; [ - pygments - pygments-style-github - ] - ); -in - -pkgs.mkShell { - FONTCONFIG_FILE = pkgs.makeFontsConf { - fontDirectories = with pkgs; [ inconsolata-lgc libertine libertinus ]; - }; - - buildInputs = with pkgs; [ - # Misc. build tooling. - gnumake - git - python3Packages.virtualenv - which - # LaTeX Environment (with all associated libraries and packages). - texliveEnv - # Python Environment (with all associated libraries and packages). - pythonEnv - ]; -} diff --git a/src/Makefile b/src/Makefile index 2b236714..3c6c2da4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,6 +5,7 @@ DIR := $(shell pwd) GIT_VER := $(shell git describe --tags --always --long | tr -d '\n') +OUTPUT_DIR := ../out/$(GIT_VER) OUTPUT = category-theory-for-programmers @@ -54,7 +55,7 @@ $(TOPPDFFILES) : %.pdf : %.tex $(TEXFILES) if which latexmk > /dev/null 2>&1 ;\ then \ latexmk -shell-escape -interaction=nonstopmode -halt-on-error -norc -jobname=ctfp -pdflatex="xelatex %O %S" -pdf $< ;\ - mv ctfp.pdf ../out/$(GIT_VER)/$(subst ctfp,$(OUTPUT),$(subst ctfp-reader,$(OUTPUT),$*)).pdf ;\ + mv ctfp.pdf $(OUTPUT_DIR)/$(subst ctfp,$(OUTPUT),$(subst ctfp-reader,$(OUTPUT),$*)).pdf ;\ else @printf "Error: unable to find latexmk. Is it installed?\n" ;\ fi @@ -64,8 +65,8 @@ version.tex: @printf '}' >> version.tex out-dir: - @printf 'Creating output directory: $(GIT_VER)\n' - mkdir -p ../out/$(GIT_VER) + @printf 'Creating output directory: $(OUTPUT_DIR)\n' + mkdir -p $(OUTPUT_DIR) clean: rm -f *~ *.aux {ctfp-*}.{out,log,pdf,dvi,fls,fdb_latexmk,aux,brf,bbl,idx,ilg,ind,toc,sed}