Skip to content

Commit 4fb6aed

Browse files
committed
Go the other way around again and use path instead of string
1 parent 3bef7dc commit 4fb6aed

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

documentation/docs/integration/flake-parts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ A complete example looks like this:
3030
packages.default = pkgs.hello;
3131
3232
# (3) point mkdocs-flake to your mkdocs root folder
33-
documentation.mkdocs-root = "./docs";
33+
documentation.mkdocs-root = ./docs;
3434
3535
# (4) Build the docs:
3636
# `nix build .#documentation`

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
];
102102
};
103103

104-
documentation.mkdocs-root = "./documentation";
104+
documentation.mkdocs-root = ./documentation;
105105

106106
packages = {
107107
default = config.packages.mkdocs;

modules/documentation.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ let
44
cfg = config.documentation;
55

66
strict = lib.optionalString cfg.strict "--strict";
7-
docsRoot = flakeSelf + "/" + cfg.mkdocs-root;
87
in
98

109
{
1110
options.documentation = {
1211
mkdocs-root = lib.mkOption {
13-
type = lib.types.nullOr lib.types.str;
12+
type = lib.types.nullOr lib.types.path;
1413
default = null;
1514
example = "./documentation";
1615
description = "Path to your mkdocs documentation project with mkdocs.yml. Relative from your flake.nix.";
@@ -33,7 +32,7 @@ in
3332

3433
config = lib.mkIf (cfg.mkdocs-root != null) {
3534
packages.documentation = pkgs.runCommand "mkdocs-flake-documentation" {} ''
36-
cd ${docsRoot}
35+
cd ${cfg.mkdocs-root}
3736
${cfg.mkdocs-package}/bin/mkdocs build ${strict} --site-dir $out
3837
'';
3938

@@ -42,9 +41,10 @@ in
4241
program = pkgs.writeShellScriptBin "mkdocs-watch" ''
4342
set -euo pipefail
4443
if ! test -f mkdocs.yml; then
45-
if test -f "${cfg.mkdocs-root}/mkdocs.yml"; then
46-
echo "Your documentation is in ${cfg.mkdocs-root}. Switching into that folder."
47-
cd "${cfg.mkdocs-root}"
44+
rel_path=${lib.path.removePrefix (/. + (builtins.unsafeDiscardStringContext flakeSelf.outPath)) cfg.mkdocs-root}
45+
if test -f "$rel_path/mkdocs.yml"; then
46+
echo "Your documentation is in $rel_path. Switching into that folder."
47+
cd "$rel_path"
4848
else
4949
echo "Can't find mkdocs.yml. Is your flake's `documentation.mkdocs-root` set correctly?"
5050
fi

0 commit comments

Comments
 (0)