From ed81b6848ef56d8f22f68bda73163445deb674f6 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 15 Jan 2017 20:56:18 +0100 Subject: [PATCH] manual: add module This module is capable of producing a bastardized NixOS configuration manual with Home Manager configuration options instead. --- modules/default.nix | 3 ++ modules/manual.nix | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 modules/manual.nix diff --git a/modules/default.nix b/modules/default.nix index 57f5c5c2..7f5f48b5 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -7,6 +7,7 @@ let modules = [ ./home-environment.nix + ./manual.nix ./programs/bash.nix ./programs/beets.nix ./programs/eclipse.nix @@ -29,10 +30,12 @@ let ./systemd.nix ./xresources.nix ./xsession.nix + ]; pkgsModule = { config._module.args.pkgs = lib.mkForce pkgs; + config._module.args.baseModules = modules; }; module = lib.evalModules { diff --git a/modules/manual.nix b/modules/manual.nix new file mode 100644 index 00000000..0a947914 --- /dev/null +++ b/modules/manual.nix @@ -0,0 +1,68 @@ +{ config, lib, pkgs, baseModules, ... }: + +with lib; + +let + + /* For the purpose of generating docs, evaluate options with each derivation + in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}". + It isn't perfect, but it seems to cover a vast majority of use cases. + Caveat: even if the package is reached by a different means, + the path above will be shown and not e.g. `${config.services.foo.package}`. */ + nixosManual = import { + inherit pkgs config; + version = "0.1"; + revision = "release-0.1"; + options = + let + scrubbedEval = evalModules { + modules = [ { nixpkgs.system = pkgs.stdenv.system; } ] ++ baseModules; + args = (config._module.args) // { modules = [ ]; }; + specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; }; + }; + scrubDerivations = namePrefix: pkgSet: mapAttrs + (name: value: + let wholeName = "${namePrefix}.${name}"; in + if isAttrs value then + scrubDerivations wholeName value + // (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; }) + else value + ) + pkgSet; + in scrubbedEval.options; + }; + + homeEnvironmentManPages = pkgs.runCommand "home-environment-manpages" { + allowedReferences = [ "out" ]; + } '' + install -v -D -m444 \ + ${nixosManual.manpages}/share/man/man5/configuration.nix.5 \ + $out/share/man/man5/home-configuration.nix.5 + ''; + +in + +{ + options = { + manual.manpages.enable = mkOption { + type = types.bool; + default = true; + example = false; + description = '' + Whether to install the configuration manual page. The manual can + be reached by man home-configuration.nix. + + When looking at the manual page pretend that all references to + NixOS stuff are actually references to Home Manager stuff. + Thanks! + ''; + }; + }; + + config = mkIf config.manual.manpages.enable { + # To fix error during manpage build. + meta.doc = builtins.toFile "nothingness" ""; + + home.packages = [ homeEnvironmentManPages ]; + }; +}