about summary refs log tree commit diff stats
path: root/importers/nixos-options.nix
blob: 3c0a18e917f55b104ef01eb4da93eed0dfed4da6 (plain)
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
{ nixpkgs ? <nixpkgs>
, pkgs ? import nixpkgs { }
, system ? builtins.currentSystem
, stateVersion ? pkgs.lib.version
, ...
}:
let
  inherit (pkgs) lib;
  inherit (lib) hasPrefix removePrefix;

  nixos = pkgs.nixos ({ lib, ... }: {
    nixpkgs.hostPlatform = system;
    system.stateVersion = lib.versions.majorMinor stateVersion;
  });

  inherit (nixos.config.system.nixos) revision;

  gitHubDeclaration = user: repo: ref: subpath:
    # Default to `master` if we don't know what revision the system
    # configuration is using (custom nixpkgs, etc.).
    let urlRef = if ref != null then ref else "master";
    in {
      url = "https://github.com/${user}/${repo}/blob/${urlRef}/${subpath}";
      name = "<${repo}/${subpath}>";
    };

  doc = pkgs.nixosOptionsDoc {
    inherit (nixos) options;
    transformOptions = opt: opt // {
      declarations =
        map
          (decl:
            if hasPrefix (toString nixpkgs) (toString decl)
            then
              gitHubDeclaration "NixOS" "nixpkgs" revision
                (removePrefix "/"
                  (removePrefix (toString nixpkgs) (toString decl)))
            else if decl == "lib/modules.nix" then
              gitHubDeclaration "NixOS" "nixpkgs" revision decl
            else decl)
          opt.declarations;
    };
  };
in
doc.optionsJSON