devshell icon indicating copy to clipboard operation
devshell copied to clipboard

Generate the Go datastructure

Open zimbatm opened this issue 5 years ago • 2 comments

It would be good to be able to generate the Go struct from the Nix module to guarantee that they stay in sync.

The schema defined in mkDevShell/options.nix is the canonical version and devshell/config.go needs to be kept in sync with it. To avoid unnecessary discrepancy, it would be great if the latter could be derived from the former.

zimbatm avatar Oct 09 '20 07:10 zimbatm

Breadcrumb:

  • https://github.com/dave/jennifer/
  • https://github.com/aloder/tojen

(this might be a precursor to taking this issue, or not... no commitment at this time possible)

blaggacao avatar Nov 25 '20 20:11 blaggacao

Another option to add here is rycee/nmd.

I'm using it to convert modules nix to markdown files and document some modules

Something like this:

# simplified from https://github.com/cruel-intentions/devshell-files/blob/master/modules/docs.nix
let
  modules = [
    ./myModulePath.nix
    {
      _module.check = false;
      _module.args.pkgs = lib.mkForce (nmd.scrubDerivations "pkgs" pkgs);
    }
  ];
  docs = mnd.buildModulesDocs {
    channelName     = "";
    docBook         = {};
    mkModuleUrl     = path: path;
    moduleRootPaths = [ ./. ];
    modules         = modules;
  };
in (import ./docs/markdown.nix) docs.optionsDocs
# simplified from https://github.com/cruel-intentions/devshell-files/blob/master/modules/docs/markdown.nix
moduleDocs:
let
  optionToMd = opt:
    ''
      ## ${opt.name}
    
      ${opt.description}
      #### type
      ${opt.type}

      ${opt.example}

      ${opt.default}
    '';
in builtins.concatStringsSep "\n" (builtins.map optionToMd moduleDocs)

hugosenari avatar Apr 10 '22 19:04 hugosenari