Skip to content

Commit

Permalink
Repository Standardisation - Part 3 - haskell-nix (#4857)
Browse files Browse the repository at this point in the history
Upgraded std version -> renamed "organelle" to "cell block"
Added haskell-nix support
  • Loading branch information
zeme-wana committed Sep 21, 2022
1 parent 410247f commit 313116e
Show file tree
Hide file tree
Showing 70 changed files with 1,024 additions and 486 deletions.
426 changes: 409 additions & 17 deletions __std__/flake.lock

Large diffs are not rendered by default.

76 changes: 36 additions & 40 deletions __std__/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,39 @@
inputs.nixpkgs.follows = "nixpkgs";
};
haskell-nix = {
url = "github:input-output-hk/haskell.nix";
inputs.hackage.follows = "hackage-nix";
url = "github:input-output-hk/haskell.nix/e36a34c4abc02287ec79bf88a0c993f6b66f9945";
};
hackage-nix = {
url = "github:input-output-hk/hackage.nix";
url = "github:input-output-hk/hackage.nix/d2077b0703f10ab08a071669729805d3bfea340d";
flake = false;
};
sphinxcontrib-haddock = {
url = "github:michaelpj/sphinxcontrib-haddock";
flake = false;
};
cardano-repo-tool = {
url = "github:input-output-hk/cardano-repo-tool";
flake = false;
};
gitignore-nix = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
haskell-language-server = {
# Pinned to a release
url = "github:haskell/haskell-language-server?ref=1.7.0.0";
flake = false;
};
# iohk-nix = {
# url = "github:input-output-hk/iohk-nix";
# flake = false;
# };
pre-commit-hooks-nix = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
iohk-nix = {
url = "github:input-output-hk/iohk-nix/6a5b69dc042f521db028fed68799eb460bce05a7";
flake = false;
};
};

# The flake outputs are managed by std.
outputs = inputs:

# The growOn function accepts a first argument defining the organelles.
# The growOn function accepts a first argument defining the cell blocks.
inputs.std.growOn
{

Expand All @@ -80,15 +76,15 @@
# Common tools and functions shared across multiple cells
cellsFrom = ./nix;

# Each cell contains arbitrary "organelles".
# Each organelle must be either:
# A nix file named after the organelle
# A directory named after the organelle and containing a default.nix
# Organelles have types.
# Not all cells have the same organelles.
# All organelles belong in a cell.
# Each cell contains arbitrary "cell blocks".
# Each cell block must be either:
# A nix file named after the cell block
# A directory named after the cell block and containing a default.nix
# Cell blocks have types.
# Not all cells have the same cell blocks.
# All cell blocks belong in a cell.
#
# In this repository we have five organelles, listed below with their type:
# In this repository we have five cell blocks, listed below with their type:
# devshells :: devshells
# Development shells available via nix develop
# packages :: installables
Expand All @@ -98,16 +94,16 @@
# scripts :: functions
# Bash scripts simplifying or automating a variety of tasks
# Generally these are available as commands inside the development shell
# These are very repository specific, and are not exposed to the flake
# These are very repository specific but are exposed to the flake nonetheless
# library :: functions
# Functions and non-derivation values (e.g. attrs of derivations) shared
# across the current cell.
# These are very repository specific, and are not exposed to the flake
# Everything that is not a derivation goes here
# Includes functions, attrsets and simple literal values shared across cells
# These are not exposed to the flake
#
# std provides a TUI to interact with the organelles.
# Available interactions are determined by the organelle's type.
# std provides a TUI to interact with the cell blocks.
# Available interactions are determined by the cell block's type.
# Because this repository does not yet use the TUI, the type is mostly irrelevant.
organelles = [
cellBlocks = [
(inputs.std.devshells "devshells")
(inputs.std.installables "packages")
(inputs.std.functions "devshellProfiles")
Expand All @@ -117,21 +113,21 @@
}

# The growOn function will then accept an arbitrary number of "soil" attrs.
# This is where we translate cells and organelles into a standard nix flake
# This is where we translate cells and cell blocks into a standard nix flake
# outputs attrs.
#
# This is where we also decide which cells and which organelles will
# This is where we also decide which cells and which cell blocks will
# make it into the flake. To exclude stuff from the flake, we simply
# do not "harvest" it.
#
# The attrs will be recursively merged in the order in which they appear.
{
# Here we say that we want the devshells organelle of the doc cell
# Here we say that we want the devshells cell block of the doc cell
# (which contains a number of shell-able derivations) to be exposed
# by the flake and accessible via nix develop.
devShells = inputs.std.harvest inputs.self [ "doc" "devshells" ];

# Here we say that we want the packages organelle of the doc cell
# Here we say that we want the packages cell block of the doc cell
# (which contains a number of buildable derivations) to be exposed
# by the flake and accessible via nix build (or nix run).
packages = inputs.std.harvest inputs.self [ "doc" "packages" ];
Expand Down Expand Up @@ -173,7 +169,7 @@
# inputs.cells
# Provides access to all cells.
# Remember that a cell is named after its folder.
# The full format is inputs.cells.<cell>.<organelle>.value
# The full format is inputs.cells.<cell>.<cell-block>.value
# e.g.: inputs.cells.doc.packages.read-the-docs-site
# e.g.: inputs.cells.toolchain.devshellsProfiles.common
# e.g.: inputs.cells.haskell.devshells.haskell-shell
Expand All @@ -184,8 +180,8 @@
# e.g.: inputs.nixpkgs
# e.g.: inputs.sphinxcontrib-haddock
#
# cell.*organelle*
# The cell value gives access to all its organelles:
# cell.*cell block*
# The cell value gives access to all its cell blocks:
# e.g.: cell.scripts.serve-read-the-docs-site (only works for code in /nix/scripts)
# Alternatively: inputs.cells.doc.scripts.serve-read-the-docs-site (works everywhere)
# e.g.: cell.packages.repo-root.nix (only works for code in /nix/toolchain)
Expand All @@ -198,20 +194,20 @@
# This is currently applied *without exception*.
#
# This means that every single nix file in this repository is either:
# - A default.nix organelle importing and thus grouping all files in its folder
# - A default.nix cell block importing and thus grouping all files in its folder
# - A file evaluating to a single derivation
#
# Further, we enforce that the nix fragment name be equal to the file name.
# This means that if one looks at the fully expanded structure of the cellsFrom folder,
# one will conclude that there are exactly as many fragments as there are nix files
# (excluding the default.nix files, which again merely act as a grouper for the organelle).
# (excluding the default.nix files, which again merely act as a grouper for the cell block).
#
# Finally this means that for each nix file "some-fragment.nix", one can run:
# nix (develop|build|run) .#some-fragment
# That is unless the relevant organelle was not exposed by the flake.
# That is unless the relevant cell block was not exposed by the flake.
#
# Also note that while virtually all nix files evaluate to derivations, some
# (like the ones in the library organelle) actually evaluate to functions.
# (like the ones in the library cell block) actually evaluate to functions.
# So it is more accurate to say that the convention is to export one
# (non-attribute-set!) nix value per nix file.

Expand All @@ -223,7 +219,7 @@
# - /doc is the cell name
# - /doc is accessible via cell.* from { inputs, cell } (while inside /nix/doc)
# - /doc is accessible via inputs.cells.doc (everywhere)
# - /packages is the organelle name
# - /packages is the cell block name
# - /packages is accessible via cell.packages (while inside /nix/doc)
# - /packages is accessible via inputs.cells.doc.packages (everywhere)
# - /eutxo-paper.nix contains a *single derivation*
Expand All @@ -237,7 +233,7 @@
# - /toolchain is the cell name
# - /toolchain is accessible via cell.* from { inputs, cell } (while inside /nix/toolchain)
# - /toolchain is accessible via inputs.cells.toolchain (everywhere)
# - /packages is the organelle name
# - /packages is the cell block name
# - /packages is accessible via cell.packages (while inside /nix/toolchain)
# - /packages is accessible via inputs.cells.toolchain.packages (everywhere)
# - /default.nix imports every file in its directory
Expand Down
4 changes: 2 additions & 2 deletions __std__/nix/doc/devshells/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ inputs, cell }@organelle:
{ inputs, cell }@block:
{
doc-shell = import ./doc-shell.nix organelle;
doc-shell = import ./doc-shell.nix block;
}
14 changes: 8 additions & 6 deletions __std__/nix/doc/library/build-latex-doc.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{ inputs, cell }:

let
inherit (inputs.nixpkgs) lib;
inherit (inputs.cells.toolchain.library) pkgs;
in

{ name, description, src, texFiles ? null, withAgda ? false, agdaFile ? "" }:

cell.library.build-latex {
Expand All @@ -12,12 +14,12 @@ cell.library.build-latex {

src = cell.library.filter-latex-sources src;

buildInputs = lib.optionals withAgda [
inputs.cells.toolchain.packages.agda-with-stdlib
buildInputs = pkgs.lib.optionals withAgda [
inputs.cells.plutus.packages.agda-with-stdlib
];

texInputs = {
inherit (inputs.nixpkgs.texlive)
inherit (pkgs.texlive)
acmart
bibtex biblatex
collection-bibtexextra
Expand All @@ -30,11 +32,11 @@ cell.library.build-latex {
scheme-small;
};

preBuild = lib.optionalString withAgda ''
preBuild = pkgs.lib.optionalString withAgda ''
agda --latex ${agdaFile} --latex-dir .
'';

meta = with lib; {
meta = with pkgs.lib; {
inherit description;
license = licenses.asl20;
};
Expand Down
10 changes: 6 additions & 4 deletions __std__/nix/doc/library/build-latex.nix
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
{ inputs, cell }:

let texlive = inputs.nixpkgs.texlive; in
let
inherit (inputs.cells.toolchain.library) pkgs;
in

# Build a latex derivation using latexmk.
{ texFiles ? [ ]
, # The specific tex files to build, will try and build all of them if absent
texInputs ? { inherit (texlive) scheme-small; }
texInputs ? { inherit (pkgs.texlive) scheme-small; }
, # Tex dependencies as an attrset
buildInputs ? [ ]
, # Additional build inputs
...
}@attrs:
let
tex = texlive.combine (texInputs // { inherit (texlive) latexmk; });
tex = pkgs.texlive.combine (texInputs // { inherit (pkgs.texlive) latexmk; });

# mkDerivation doesn't like having this as an attr, and we don't need to pass it through
filteredAttrs = builtins.removeAttrs attrs [ "texInputs" ];

buildDir = ".nix-build";
in
inputs.nixpkgs.stdenv.mkDerivation (filteredAttrs // {
pkgs.stdenv.mkDerivation (filteredAttrs // {

buildInputs = [ tex ] ++ buildInputs;

Expand Down
8 changes: 4 additions & 4 deletions __std__/nix/doc/library/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ inputs, cell }@organelle:
{ inputs, cell }@block:
{
build-latex-doc = import ./build-latex-doc.nix organelle;
build-latex-doc = import ./build-latex-doc.nix block;

build-latex = import ./build-latex.nix organelle;
build-latex = import ./build-latex.nix block;

filter-latex-sources = import ./filter-latex-sources.nix organelle;
filter-latex-sources = import ./filter-latex-sources.nix block;
}


2 changes: 1 addition & 1 deletion __std__/nix/doc/library/filter-latex-sources.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# This also includes files for cases where agda sources are being compiled.
{ inputs, cell }:

src: inputs.nixpkgs.lib.sourceFilesBySuffices src
src: inputs.cells.toolchain.library.pkgs.lib.sourceFilesBySuffices src
[ ".tex" ".bib" ".cls" ".bst" ".pdf" ".png" ".agda" ".agda-lib" ".lagda" ]
16 changes: 9 additions & 7 deletions __std__/nix/doc/packages/combined-plutus-haddock.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

{ inputs, cell }:

# TODO(std) need haskell-nix for this

let
toHaddock =
inputs.cells.toolchain.library.haskell-nix.haskellLib.collectComponents'
"library"
inputs.cells.plutus.packages.all-components-with-haddock;

inherit (inputs.cells.toolchain.library.haskell-nix) haskellLib;

toHaddock = haskellLib.collectComponents' "library"
(haskellLib.selectProjectPackages inputs.cells.plutus.library.plutus-project.hsPkgs);

in

inputs.cells.toolchain.library.combine-haddock {

ghc = inputs.cells.plutus.packages.ghc;

hspkgs = builtins.attrValues toHaddock;

prologue = inputs.nixpkgs.writeTextFile {
prologue = inputs.cells.toolchain.library.pkgs.writeTextFile {
name = "prologue";
text = ''
= Combined documentation for all the public Plutus libraries
Expand Down
28 changes: 14 additions & 14 deletions __std__/nix/doc/packages/default.nix
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{ inputs, cell }@organelle:
{ inputs, cell }@block:
{
read-the-docs-site = import ./read-the-docs-site.nix organelle;
read-the-docs-site = import ./read-the-docs-site.nix block;

system-f-in-agda-paper = import ./system-f-in-agda-paper.nix organelle;
system-f-in-agda-paper = import ./system-f-in-agda-paper.nix block;

eutxo-paper = import ./eutxo-paper.nix organelle;
eutxo-paper = import ./eutxo-paper.nix block;

utxoma-paper = import ./utxoma-paper.nix organelle;
utxoma-paper = import ./utxoma-paper.nix block;

eutxoma-paper = import ./eutxoma-paper.nix organelle;
eutxoma-paper = import ./eutxoma-paper.nix block;

unraveling-recursion-paper = import ./unraveling-recursion-paper.nix organelle;
unraveling-recursion-paper = import ./unraveling-recursion-paper.nix block;

plutus-core-spec = import ./plutus-core-spec.nix organelle;
plutus-core-spec = import ./plutus-core-spec.nix block;

multi-currency-notes = import ./multi-currency-notes.nix organelle;
multi-currency-notes = import ./multi-currency-notes.nix block;

extended-utxo-spec = import ./extended-utxo-spec.nix organelle;
extended-utxo-spec = import ./extended-utxo-spec.nix block;

lazy-machine-notes = import ./lazy-machine-notes.nix organelle;
lazy-machine-notes = import ./lazy-machine-notes.nix block;

plutus-report = import ./plutus-report.nix organelle;
plutus-report = import ./plutus-report.nix block;

cost-model-notes = import ./cost-model-notes.nix organelle;
cost-model-notes = import ./cost-model-notes.nix block;

combined-plutus-haddock = import ./combined-plutus-haddock.nix organelle;
combined-plutus-haddock = import ./combined-plutus-haddock.nix block;
}
14 changes: 10 additions & 4 deletions __std__/nix/doc/packages/read-the-docs-site.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{ inputs, cell }:

let
inherit (inputs.cells.toolchain.library) pkgs;
in

inputs.nixpkgs.stdenv.mkDerivation {
pkgs.stdenv.mkDerivation {
name = "read-the-docs-site";

src = inputs.nixpkgs.lib.sourceFilesBySuffices
src = pkgs.lib.sourceFilesBySuffices
(inputs.self + /doc)
[ ".py" ".rst" ".hs" ".png" ".svg" ".bib" ".csv" ".css" ];

Expand All @@ -14,9 +17,12 @@ inputs.nixpkgs.stdenv.mkDerivation {

dontInstall = true;

# TODO(std) needs haskell-nix
buildPhase = ''
echo FIXME > $out && exit 0
# FIXME
# https://input-output.atlassian.net/browse/PLT-789
# https://hydra.iohk.io/build/18701775/nixlog/1
mkdir -p $out
exit 0
cp -aR ${cell.packages.combined-plutus-haddock}/share/doc haddock
# -n gives warnings on missing link targets, -W makes warnings into errors
Expand Down

0 comments on commit 313116e

Please sign in to comment.