Skip to content

Commit 5c3709f

Browse files
committed
Merge branch 'master' of github.com:mlabs-haskell/flake-lang.nix into szg251/sync-rust-flake
2 parents 8d4b375 + 2025416 commit 5c3709f

File tree

24 files changed

+3469
-418
lines changed

24 files changed

+3469
-418
lines changed

docs/build.nix

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,95 @@
1-
_: {
1+
{ flake-parts-lib, inputs, ... }: {
22
perSystem = { pkgs, config, ... }:
3-
{
4-
devShells.dev-docs = pkgs.mkShell {
5-
name = "docs-env";
6-
packages = [ pkgs.mdbook ];
7-
shellHook = config.settings.shell.hook;
8-
};
93

10-
packages.lambda-buffers-book = pkgs.stdenv.mkDerivation {
11-
src = ./.;
12-
name = "lambda-buffers-book";
13-
buildInputs = [ pkgs.mdbook ];
14-
buildPhase = ''
15-
cp ${config.packages.lambda-buffers-api-docs}/api.md api.md;
16-
mdbook build . --dest-dir $out
17-
'';
4+
# Note(jaredponn): What is going on here to generate the documentation?
5+
# Since flake-parts is using the module system and nixos also uses the
6+
# module system, we copy how they generate documentation:
7+
# - The nix function which builds the documentation
8+
# https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/make-options-doc/default.nix
9+
# - The file where they actually build the documentation
10+
# https://github.com/NixOS/nixpkgs/blob/master/doc/default.nix
11+
let
12+
# TODO(jaredponn): make this a module option or something so someone
13+
# can set this somewhere else...
14+
rootSrcUrl = "https://github.com/mlabs-haskell/flake-lang.nix/blob/master";
15+
eval =
16+
# pkgs.lib.evalModules
17+
flake-parts-lib.evalFlakeModule
18+
{ inherit inputs; }
19+
{
20+
imports =
21+
[
22+
../flake-lang/build.nix
23+
];
24+
};
25+
optionsDoc = pkgs.nixosOptionsDoc {
26+
inherit (eval) options;
27+
documentType = "none";
28+
revision = "none";
29+
# We only want to include the options provided by us (there's a
30+
# bunch of extra garbage provided by flake-parts).
31+
# So, we set the attribute `.visible` to `false` for all options
32+
# which are not defined in `*.lib.*` (where we recall `*.lib.* is
33+
# our stuff)
34+
transformOptions =
35+
opt:
36+
if
37+
# Either `lib` is the first thing, or it's in some nested attribute
38+
builtins.match ''^(.*\.)?lib(\..+)?$'' opt.name != null
39+
then opt
40+
//
41+
{
42+
# Need to do some work s.t. we refer to the
43+
# actual github repo instead of the nix
44+
# store
45+
declarations =
46+
builtins.map
47+
(decl:
48+
let matches = builtins.match ''${builtins.toString ./..}/(.*)'' decl;
49+
in if matches != null
50+
then
51+
let matched = builtins.elemAt matches 0;
52+
in
53+
{
54+
# TODO(jaredponn):
55+
# What about
56+
# weird URLS?
57+
# shouldn't we
58+
# escape the
59+
# URL in a
60+
# reasonable
61+
# sense?
62+
url = "${rootSrcUrl}/${matched}";
63+
name = matched;
64+
}
65+
else decl
66+
)
67+
opt.declarations;
68+
}
69+
else opt // { visible = false; };
1870
};
1971

72+
in
73+
{
74+
75+
packages = {
76+
# Useful for debugging.
77+
docs-raw-json = optionsDoc.optionsJSON;
78+
docs-raw-common-mark = optionsDoc.optionsCommonMark;
79+
80+
# Documentation
81+
docs = pkgs.runCommand
82+
"flake-lang-docs"
83+
{ nativeBuildInputs = [ pkgs.pandoc ]; }
84+
''
85+
pandoc ${pkgs.lib.escapeShellArg config.packages.docs-raw-common-mark} \
86+
--metadata title="flake-lang.nix" \
87+
--standalone \
88+
--output index.html
89+
90+
mkdir -p "$out"
91+
mv index.html "$out"
92+
'';
93+
};
2094
};
2195
}

examples/build.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ _:
77
[
88
./haskell-flake-project/build.nix
99
./rust-flake-project/build.nix
10+
./typescript-flake-project/build.nix
11+
./typescript-flake-project-with-extra-dependency/build.nix
1012
];
1113
}

flake-lang/build.nix

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
lib = lib.mkOption {
2121
type = lib.types.lazyAttrsOf (lib.types.lazyAttrsOf (lib.types.functionTo lib.types.attrs));
2222
default = { };
23-
description = ''
24-
Nix functions to help create flakes for languages.
25-
26-
TODO(jaredponn): document this better.
27-
'';
23+
visible = false;
2824
};
2925
};
3026
perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, pkgsForCtl, pkgsForHaskellNix, pkgsForRust, ... }: {
@@ -34,10 +30,10 @@
3430
type = lib.types.functionTo lib.types.attrs;
3531
default = import ./flake-purescript.nix pkgsForCtl;
3632
readOnly = true;
37-
description = ''
33+
description = lib.mdDoc ''
3834
TODO(jaredponn): write down documentation here
3935
'';
40-
example = ''
36+
example = lib.mdDoc ''
4137
TODO(jaredponn): write down an example here
4238
'';
4339
};
@@ -46,10 +42,10 @@
4642
type = lib.types.functionTo lib.types.attrs;
4743
default = import ./flake-rust.nix pkgsForRust;
4844
readOnly = true;
49-
description = ''
45+
description = lib.mdDoc ''
5046
TODO(jaredponn): write down documentation here
5147
'';
52-
example = ''
48+
example = lib.mdDoc ''
5349
TODO(jaredponn): write down an example here
5450
'';
5551
};
@@ -58,10 +54,10 @@
5854
type = lib.types.functionTo lib.types.attrs;
5955
default = import ./flake-haskell.nix pkgsForHaskellNix;
6056
readOnly = true;
61-
description = ''
57+
description = lib.mdDoc ''
6258
TODO(jaredponn): write down documentation here
6359
'';
64-
example = ''
60+
example = lib.mdDoc ''
6561
TODO(jaredponn): write down an example here
6662
'';
6763
};
@@ -70,10 +66,10 @@
7066
type = lib.types.functionTo lib.types.attrs;
7167
default = import ./flake-haskell-plutus.nix inputs.cardano-haskell-packages pkgsForHaskellNix;
7268
readOnly = true;
73-
description = ''
69+
description = lib.mdDoc ''
7470
TODO(jaredponn): write down documentation here
7571
'';
76-
example = ''
72+
example = lib.mdDoc ''
7773
TODO(jaredponn): write down an example here
7874
'';
7975
};
@@ -82,10 +78,10 @@
8278
type = lib.types.functionTo lib.types.attrs;
8379
default = import ./flake-typescript.nix pkgs;
8480
readOnly = true;
85-
description = ''
81+
description = lib.mdDoc ''
8682
TODO(jaredponn): write down documentation here
8783
'';
88-
example = ''
84+
example = lib.mdDoc ''
8985
TODO(jaredponn): write down an example here
9086
'';
9187
};

0 commit comments

Comments
 (0)