at master 2.9 kB view raw
1{ pkgs, lib, ... }: 2let 3 manImplementations = [ 4 "mandoc" 5 "man-db" 6 ]; 7 8 machineNames = builtins.map machineSafe manImplementations; 9 10 makeConfig = useImpl: { 11 # Note: mandoc currently can't index symlinked section directories. 12 # So if a man section comes from one package exclusively (e. g. 13 # 1p from man-pages-posix and 2 from man-pages), it isn't searchable. 14 environment.systemPackages = [ 15 pkgs.man-pages 16 pkgs.openssl 17 pkgs.libunwind 18 ]; 19 20 documentation = { 21 enable = true; 22 nixos.enable = lib.mkForce true; 23 dev.enable = true; 24 man = { 25 enable = true; 26 generateCaches = true; 27 } 28 // lib.listToAttrs ( 29 builtins.map (impl: { 30 name = impl; 31 value = { 32 enable = useImpl == impl; 33 }; 34 }) manImplementations 35 ); 36 }; 37 }; 38 39 machineSafe = builtins.replaceStrings [ "-" ] [ "_" ]; 40in 41{ 42 name = "man"; 43 meta.maintainers = [ lib.maintainers.sternenseemann ]; 44 45 nodes = lib.listToAttrs ( 46 builtins.map (i: { 47 name = machineSafe i; 48 value = makeConfig i; 49 }) manImplementations 50 ); 51 52 testScript = '' 53 import re 54 start_all() 55 56 def match_man_k(page, section, haystack): 57 """ 58 Check if the man page {page}({section}) occurs in 59 the output of `man -k` given as haystack. Note: 60 This is not super reliable, e. g. it can't deal 61 with man pages that are in multiple sections. 62 """ 63 64 for line in haystack.split("\n"): 65 # man -k can look like this: 66 # page(3) - bla 67 # page (3) - bla 68 # pagea, pageb (3, 3P) - foo 69 # pagea, pageb, pagec(3) - bar 70 pages = line.split("(")[0] 71 sections = re.search("\\([a-zA-Z1-9, ]+\\)", line) 72 if sections is None: 73 continue 74 else: 75 sections = sections.group(0)[1:-1] 76 77 if page in pages and f'{section}' in sections: 78 return True 79 80 return False 81 82 '' 83 + lib.concatMapStrings (machine: '' 84 with subtest("Test direct man page lookups in ${machine}"): 85 # man works 86 ${machine}.succeed("man man > /dev/null") 87 # devman works 88 ${machine}.succeed("man 3 libunwind > /dev/null") 89 # NixOS configuration man page is installed 90 ${machine}.succeed("man configuration.nix > /dev/null") 91 92 with subtest("Test generateCaches via man -k in ${machine}"): 93 expected = [ 94 ("openssl", "ssl", 3), 95 ("unwind", "libunwind", 3), 96 ("user", "useradd", 8), 97 ("user", "userdel", 8), 98 ("mem", "free", 3), 99 ("mem", "free", 1), 100 ] 101 102 for (keyword, page, section) in expected: 103 matches = ${machine}.succeed(f"man -k {keyword}") 104 if not match_man_k(page, section, matches): 105 raise Exception(f"{page}({section}) missing in matches: {matches}") 106 '') machineNames; 107}