diff --git a/pkgs/development/interpreters/dhall/build-dhall-directory-package.nix b/pkgs/development/interpreters/dhall/build-dhall-directory-package.nix index 0c182b25d57..7fe1b46e3a5 100644 --- a/pkgs/development/interpreters/dhall/build-dhall-directory-package.nix +++ b/pkgs/development/interpreters/dhall/build-dhall-directory-package.nix @@ -14,12 +14,17 @@ lib.makePackageOverridable , src , # The file to import, relative to the root directory file ? "package.dhall" + # Set to `true` to generate documentation for the package + , document ? false }: - buildDhallPackage { - inherit name dependencies source; + buildDhallPackage + ( { inherit name dependencies source; - code = "${src}/${file}"; - } + code = "${src}/${file}"; + + } + // lib.optionalAttrs document { documentationRoot = src; } + ) ) diff --git a/pkgs/development/interpreters/dhall/build-dhall-github-package.nix b/pkgs/development/interpreters/dhall/build-dhall-github-package.nix index bdb958fb8bd..0978e47754b 100644 --- a/pkgs/development/interpreters/dhall/build-dhall-github-package.nix +++ b/pkgs/development/interpreters/dhall/build-dhall-github-package.nix @@ -12,6 +12,8 @@ lib.makePackageOverridable directory ? "" , # The file to import, relative to the above directory file ? "package.dhall" + # Set to `true` to generate documentation for the package + , document ? false # Arguments passed through to `fetchFromGitHub` , owner @@ -22,29 +24,32 @@ lib.makePackageOverridable , ... }@args: - buildDhallPackage { - inherit name dependencies source; + let + src = fetchFromGitHub ({ + name = "${name}-source"; - code = - let - src = fetchFromGitHub ({ - name = "${name}-source"; + inherit owner repo rev; + } // removeAttrs args [ + "name" + "dependencies" + "document" + "source" + "directory" + "file" + "owner" + "repo" + "rev" + ]); - inherit owner repo rev; - } // removeAttrs args [ - "name" - "dependencies" - "source" - "directory" - "file" - "owner" - "repo" - "rev" - ]); + prefix = lib.optionalString (directory != "") "${directory}/"; - prefix = lib.optionalString (directory != "") "${directory}/"; + in + buildDhallPackage + ( { inherit name dependencies source; - in - "${src}/${prefix}${file}"; - } + code = "${src}/${prefix}${file}"; + } + // lib.optionalAttrs document + { documentationRoot = "${src}/${prefix}"; } + ) ) diff --git a/pkgs/development/interpreters/dhall/build-dhall-package.nix b/pkgs/development/interpreters/dhall/build-dhall-package.nix index 9303244eb88..039c50f0693 100644 --- a/pkgs/development/interpreters/dhall/build-dhall-package.nix +++ b/pkgs/development/interpreters/dhall/build-dhall-package.nix @@ -1,4 +1,4 @@ -{ dhall, haskell, lib, lndir, runCommand, writeText }: +{ dhall, dhall-docs, haskell, lib, lndir, runCommand, writeText }: { name @@ -31,6 +31,12 @@ # space within the Nix store, but if you set the following `source` option to # `true` then the package will also include `source.dhall`. , source ? false + + # Directory to generate documentation for (i.e. as the `--input` option to the + # `dhall-docs` command.) + # + # If `null`, then no documentation is generated. +, documentationRoot ? null }: let @@ -42,8 +48,12 @@ let cache = ".cache"; + data = ".local/share"; + cacheDhall = "${cache}/dhall"; + dataDhall = "${data}/dhall"; + sourceFile = "source.dhall"; in @@ -71,4 +81,10 @@ in echo "missing $SHA_HASH" > $out/binary.dhall ${lib.optionalString (!source) "rm $out/${sourceFile}"} + + ${lib.optionalString (documentationRoot != null) '' + mkdir -p $out/${dataDhall} + + XDG_DATA_HOME=$out/${data} ${dhall-docs}/bin/dhall-docs --input '${documentationRoot}' --output-link $out/docs + ''} '' diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index dd83ab4f9c4..a60e5f6e6fb 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -10310,13 +10310,15 @@ in dhall = haskell.lib.justStaticExecutables haskellPackages.dhall; - dhall-nix = haskell.lib.justStaticExecutables haskellPackages.dhall-nix; - dhall-bash = haskell.lib.justStaticExecutables haskellPackages.dhall-bash; + dhall-docs = haskell.lib.justStaticExecutables haskellPackages.dhall-docs; + + dhall-lsp-server = haskell.lib.justStaticExecutables haskellPackages.dhall-lsp-server; + dhall-json = haskell.lib.justStaticExecutables haskellPackages.dhall-json; - dhall-lsp-server = haskell.lib.justStaticExecutables haskellPackages.dhall-lsp-server; + dhall-nix = haskell.lib.justStaticExecutables haskellPackages.dhall-nix; dhall-text = haskell.lib.justStaticExecutables haskellPackages.dhall-text;