From 71de5479bc625aa101f72a24b056b687b0630a9a Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 5 May 2024 21:31:40 +0200 Subject: feat: link to nixpkgs on github for declarations --- importers/nixos-options.nix | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'importers/nixos-options.nix') diff --git a/importers/nixos-options.nix b/importers/nixos-options.nix index 894f05e..3c0a18e 100644 --- a/importers/nixos-options.nix +++ b/importers/nixos-options.nix @@ -1,17 +1,45 @@ -{ pkgs ? import { } +{ nixpkgs ? +, pkgs ? import nixpkgs { } , system ? builtins.currentSystem , stateVersion ? pkgs.lib.version , ... }: let inherit (pkgs) lib; - nixos = pkgs.nixos ({ lib, pkgs, config, ... }: { + 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 -- cgit 1.4.1