Repository navigation
Expand file tree
/
Copy pathmandoc.nix
More file actions
126 lines (116 loc) · 3.38 KB
/
Copy pathmandoc.nix
File metadata and controls
126 lines (116 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
{
config,
lib,
pkgs,
mkFormatterModule,
...
}:
let
cfg = config.programs.mandoc;
checksReferences = cfg.level == "style";
manuals = pkgs.runCommandLocal "mandoc-manuals" { } ''
mkdir "$out"
${lib.concatMapStrings (
package:
let
directory = "${lib.getMan package}/share/man";
in
''
if [[ ! -d ${directory} ]]; then
echo "${lib.getName package} has no manuals in ${directory}" >&2
exit 1
fi
cp -rL --no-preserve=mode --update=none ${directory}/. "$out"
''
) cfg.manuals}
${lib.getExe' pkgs.buildPackages.mandoc "makewhatis"} "$out"
'';
in
{
meta.maintainers = [ "karaolidis" ];
imports = [
(mkFormatterModule {
name = "mandoc";
mainProgram = "mandoc";
args = [
"-T"
"lint"
];
includes = [ "*.[1-9]" ];
})
];
options.programs.mandoc = {
level = lib.mkOption {
description = ''
Minimum level of messages to report and fail on.
'';
type = lib.types.enum [
"style"
"warning"
"error"
"unsupp"
];
default = "warning";
};
manuals = lib.mkOption {
description = ''
Packages whose manuals `.Xr` cross-references may point to.
'';
type = lib.types.listOf lib.types.package;
default = [ ];
example = lib.literalExpression "[ pkgs.man-pages ]";
};
manpath = lib.mkOption {
description = ''
Directories, relative to the project root, whose manuals `.Xr` cross-references may
point to, either directly inside them or in `man<section>` subdirectories.
'';
type = lib.types.listOf lib.types.str;
default = [ ];
example = [ "man" ];
};
};
config = lib.mkIf cfg.enable {
settings.formatter.mandoc =
lib.warnIf (!checksReferences && (cfg.manuals != [ ] || cfg.manpath != [ ]))
"programs.mandoc: `manuals` and `manpath` only take effect at level \"style\"."
(
{
options = [
"-W"
cfg.level
];
}
// lib.optionalAttrs checksReferences {
command = pkgs.writeShellApplication {
name = "mandoc-lint";
runtimeInputs = with pkgs; [
coreutils
findutils
];
text = ''
tree=$(mktemp -d)
trap 'rm -rf "$tree"' EXIT
manpath=(${lib.escapeShellArgs cfg.manpath})
for directory in "''${manpath[@]}"; do
if [[ ! -d $directory ]]; then
echo "mandoc-lint: no such directory: $directory" >&2
exit 1
fi
while IFS= read -r -d "" page; do
[[ ''${page##*/} =~ \.([1-9][^.]*)(\.gz)?$ ]] || continue
section="$tree/man''${BASH_REMATCH[1]}"
mkdir -p "$section"
cp --update=none "$page" "$section/"
done < <(find -L "$directory" -maxdepth 2 -type f -print0 | sort -z)
done
${lib.getExe' cfg.package "makewhatis"} "$tree"
${lib.getExe' cfg.package "mandoc"} -M "$tree${
lib.optionalString (cfg.manuals != [ ]) ":${manuals}"
}" "$@"
'';
};
}
);
};
}