Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fromJsonSchema to nix options

Converts json schema to nix options. Aims to enable fast creation of nix modules which provide options for all config keys of a tool.

Usage

  1. Define options for a module or wrapper using this library.

    {
      inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
        wrappers.url = "github:lassulus/wrappers";
        fromJsonSchema.url = "github:friedow/fromJsonSchema";
      };
    
      outputs =
        {
          nixpkgs,
          fromJsonSchema,
          wrappers,
          ...
        }:
        {
          wrapperModules.markdownlint = wrappers.lib.wrapModule (
            { config, ... }:
            let
              jsonFmt = config.pkgs.formats.json { };
              jsonSchema = builtins.fromJSON (
                builtins.readFile (
                  builtins.fetchurl {
                    url = "https://raw.githubusercontent.com/DavidAnson/markdownlint/main/schema/markdownlint-config-schema.json";
                    sha256 = "04wbgrzl3d6mdnvqi8142gz69006hjvrwhd7gvkx7wyqqkw9rpj4";
                  }
                )
              );
            in
            {
              options = {
                settings = (fromJsonSchema.lib.fromJsonSchema jsonSchema).options;
              };
              config = {
                package = nixpkgs.lib.mkDefault config.pkgs.markdownlint-cli;
                flags."--config-file" = jsonFmt.generate "markdownlint.json" config.settings;
              };
            }
          );
        };
    }
  2. Enjoy auto generated nix options based on the json schema.

    nix eval .#wrapperModules.markdownlint

About

Converts json schema to nix options.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages