# Demo flake for: deriving a JSON schema for a contract type's default # provider's non-contract-instance options, by way of the # `providers..module` option set introduced on the `contracts-automated` # branch of nixpkgs. # # Usage: # nix run . # JSON schema covering, per contract type, the # # `default` and the per-instance provider's config. { description = "Contract-provider JSON schema demo"; inputs = { nixpkgs.url = "github:kiaragrouwstra/nixpkgs/contracts-automated"; # `nested-attrs-of` branch adds `nestedAttrsOf` -> `attrsOf` mapping and # `default` annotation passthrough to clan-core's lib/jsonschema. clan-core = { url = "git+https://git.clan.lol/kiara/clan-core.git?ref=nested-attrs-of"; flake = false; }; }; outputs = { self, nixpkgs, clan-core }: let systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; forAllSystems = nixpkgs.lib.genAttrs systems; result = forAllSystems ( system: import ./demo.nix { nixpkgs = nixpkgs.outPath; clanJsonschema = "${clan-core}/lib/jsonschema"; } ); in { packages = forAllSystems ( system: let pkgs = nixpkgs.legacyPackages.${system}; in { default = pkgs.writeShellApplication { name = "schema"; runtimeInputs = [ pkgs.jq ]; text = '' jq . <<'EOF' ${builtins.toJSON result.${system}.schema} EOF ''; }; } ); apps = forAllSystems (system: { default = { type = "app"; program = "${self.packages.${system}.default}/bin/schema"; }; }); }; }