From ec773dcade98651e2298c79372aff121f1768589 Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Sun, 25 Jun 2023 13:36:15 +0300 Subject: [PATCH] switch from dream2nix to buildNpmPackage --- json2md/flake.lock | 360 +------------------------------------ json2md/flake.nix | 181 ++++++++----------- json2md/{src => }/index.js | 2 - json2md/package.json | 2 +- 4 files changed, 85 insertions(+), 460 deletions(-) rename json2md/{src => }/index.js (92%) diff --git a/json2md/flake.lock b/json2md/flake.lock index 5df7ec0cb..dcccb74e4 100644 --- a/json2md/flake.lock +++ b/json2md/flake.lock @@ -1,141 +1,5 @@ { "nodes": { - "all-cabal-json": { - "flake": false, - "locked": { - "lastModified": 1687668044, - "narHash": "sha256-rCXGVPVdPhibwAlPUXkySoyLzc+FgpY4/OaoY7qLAJ0=", - "owner": "nix-community", - "repo": "all-cabal-json", - "rev": "baf94bd8d2e9d8cdbda08e8e5cebb7e8a3e1a476", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "hackage", - "repo": "all-cabal-json", - "type": "github" - } - }, - "crane": { - "flake": false, - "locked": { - "lastModified": 1681175776, - "narHash": "sha256-7SsUy9114fryHAZ8p1L6G6YSu7jjz55FddEwa2U8XZc=", - "owner": "ipetkov", - "repo": "crane", - "rev": "445a3d222947632b5593112bb817850e8a9cf737", - "type": "github" - }, - "original": { - "owner": "ipetkov", - "ref": "v0.12.1", - "repo": "crane", - "type": "github" - } - }, - "devshell": { - "flake": false, - "locked": { - "lastModified": 1653917170, - "narHash": "sha256-FyxOnEE/V4PNEcMU62ikY4FfYPo349MOhMM97HS0XEo=", - "owner": "numtide", - "repo": "devshell", - "rev": "fc7a3e3adde9bbcab68af6d1e3c6eb738e296a92", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "dream2nix": { - "inputs": { - "all-cabal-json": "all-cabal-json", - "crane": "crane", - "devshell": "devshell", - "drv-parts": "drv-parts", - "flake-compat": "flake-compat", - "flake-parts": "flake-parts", - "flake-utils-pre-commit": "flake-utils-pre-commit", - "ghc-utils": "ghc-utils", - "gomod2nix": "gomod2nix", - "mach-nix": "mach-nix", - "nix-pypi-fetcher": "nix-pypi-fetcher", - "nixpkgs": "nixpkgs", - "nixpkgsV1": "nixpkgsV1", - "poetry2nix": "poetry2nix", - "pre-commit-hooks": "pre-commit-hooks", - "pruned-racket-catalog": "pruned-racket-catalog" - }, - "locked": { - "lastModified": 1687429612, - "narHash": "sha256-lVQlsVmWLQt+bgckBjiKxcqq2Jx1RYxyI3zmtdQ5Acs=", - "owner": "nix-community", - "repo": "dream2nix", - "rev": "6b750b01385718a6a84231d3c5451308978fa7de", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "dream2nix", - "rev": "6b750b01385718a6a84231d3c5451308978fa7de", - "type": "github" - } - }, - "dream2nix_": { - "inputs": { - "dream2nix": "dream2nix" - }, - "locked": { - "dir": "source-flake/dream2nix", - "lastModified": 1687684794, - "narHash": "sha256-2g1ykzuZJRqx3fttzA/bUP9Y15wQ9nkzXLnHEZvxYH4=", - "owner": "deemp", - "repo": "flakes", - "rev": "d70a69615a748991f2be61eef06f926c53321c93", - "type": "github" - }, - "original": { - "dir": "source-flake/dream2nix", - "owner": "deemp", - "repo": "flakes", - "type": "github" - } - }, - "drv-parts": { - "inputs": { - "flake-compat": [ - "dream2nix_", - "dream2nix", - "flake-compat" - ], - "flake-parts": [ - "dream2nix_", - "dream2nix", - "flake-parts" - ], - "nixpkgs": [ - "dream2nix_", - "dream2nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1686841148, - "narHash": "sha256-IgQbs5v0hIRt0DT9szry35VV+ajvaCjtc9SNWmsDGbQ=", - "owner": "davhau", - "repo": "drv-parts", - "rev": "db0acec6cffff6f29f08f5e2a014949a5fbd877c", - "type": "github" - }, - "original": { - "owner": "davhau", - "repo": "drv-parts", - "type": "github" - } - }, "drv-tools": { "inputs": { "flake-utils": [ @@ -167,44 +31,6 @@ "type": "github" } }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": [ - "dream2nix_", - "dream2nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1685662779, - "narHash": "sha256-cKDDciXGpMEjP1n6HlzKinN0H+oLmNpgeCTzYnsA2po=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "71fb97f0d875fd4de4994dfb849f2c75e17eb6c3", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, "flake-utils": { "inputs": { "systems": "systems" @@ -223,21 +49,6 @@ "type": "github" } }, - "flake-utils-pre-commit": { - "locked": { - "lastModified": 1644229661, - "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "flake-utils_": { "inputs": { "flake-utils": "flake-utils" @@ -296,102 +107,25 @@ "type": "github" } }, - "ghc-utils": { - "flake": false, - "locked": { - "lastModified": 1684427171, - "narHash": "sha256-4MZZe3+QdXMI3GlP7dkthFDqi9oHq2AgN4pHw8Wf3N0=", - "ref": "refs/heads/master", - "rev": "fe03c79b057d80880b60bd9ca77455c73cea028b", - "revCount": 1134, - "type": "git", - "url": "https://gitlab.haskell.org/bgamari/ghc-utils" - }, - "original": { - "type": "git", - "url": "https://gitlab.haskell.org/bgamari/ghc-utils" - } - }, - "gomod2nix": { - "flake": false, - "locked": { - "lastModified": 1627572165, - "narHash": "sha256-MFpwnkvQpauj799b4QTBJQFEddbD02+Ln5k92QyHOSk=", - "owner": "tweag", - "repo": "gomod2nix", - "rev": "67f22dd738d092c6ba88e420350ada0ed4992ae8", - "type": "github" - }, - "original": { - "owner": "tweag", - "repo": "gomod2nix", - "type": "github" - } - }, - "mach-nix": { - "flake": false, - "locked": { - "lastModified": 1634711045, - "narHash": "sha256-m5A2Ty88NChLyFhXucECj6+AuiMZPHXNbw+9Kcs7F6Y=", - "owner": "DavHau", - "repo": "mach-nix", - "rev": "4433f74a97b94b596fa6cd9b9c0402104aceef5d", - "type": "github" - }, - "original": { - "id": "mach-nix", - "type": "indirect" - } - }, - "nix-pypi-fetcher": { - "flake": false, - "locked": { - "lastModified": 1669568973, - "narHash": "sha256-DGzSjoKAFsgZdOlFcFlnqzxPkxCAKXNvB25BsrehMn8=", - "owner": "DavHau", - "repo": "nix-pypi-fetcher", - "rev": "17f523a15e819fae41ab8a55b5f2851872e4c20b", - "type": "github" - }, - "original": { - "owner": "DavHau", - "repo": "nix-pypi-fetcher", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1657638268, - "narHash": "sha256-blBNtQSslAFkg0Gym9fWNJk+bPxGSZib4SOcPrmTPi4=", + "lastModified": 1685894048, + "narHash": "sha256-QKqv1QS+22k9oxncj1AnAxeqS5jGnQiUW3Jq3B+dI1w=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d80993b5f885515254746ba6d1917276ee386149", + "rev": "2e56a850786211972d99d2bb39665a9b5a1801d6", "type": "github" }, "original": { - "id": "nixpkgs", - "ref": "nixos-unstable", - "type": "indirect" - } - }, - "nixpkgsV1": { - "locked": { - "lastModified": 1687502512, - "narHash": "sha256-dBL/01TayOSZYxtY4cMXuNCBk8UMLoqRZA+94xiFpJA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3ae20aa58a6c0d1ca95c9b11f59a2d12eebc511f", + "rev": "2e56a850786211972d99d2bb39665a9b5a1801d6", "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-unstable", - "type": "indirect" } }, "nixpkgs_": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs" }, "locked": { "dir": "source-flake/nixpkgs", @@ -425,25 +159,9 @@ "type": "github" } }, - "nixpkgs_3": { - "locked": { - "lastModified": 1685894048, - "narHash": "sha256-QKqv1QS+22k9oxncj1AnAxeqS5jGnQiUW3Jq3B+dI1w=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "2e56a850786211972d99d2bb39665a9b5a1801d6", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "2e56a850786211972d99d2bb39665a9b5a1801d6", - "type": "github" - } - }, "nixpkgs__2": { "inputs": { - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_2" }, "locked": { "dir": "source-flake/nixpkgs", @@ -461,74 +179,8 @@ "type": "github" } }, - "poetry2nix": { - "flake": false, - "locked": { - "lastModified": 1666918719, - "narHash": "sha256-BkK42fjAku+2WgCOv2/1NrPa754eQPV7gPBmoKQBWlc=", - "owner": "nix-community", - "repo": "poetry2nix", - "rev": "289efb187123656a116b915206e66852f038720e", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "1.36.0", - "repo": "poetry2nix", - "type": "github" - } - }, - "pre-commit-hooks": { - "inputs": { - "flake-utils": [ - "dream2nix_", - "dream2nix", - "flake-utils-pre-commit" - ], - "nixpkgs": [ - "dream2nix_", - "dream2nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1646153636, - "narHash": "sha256-AlWHMzK+xJ1mG267FdT8dCq/HvLCA6jwmx2ZUy5O8tY=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "b6bc0b21e1617e2b07d8205e7fae7224036dfa4b", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "pruned-racket-catalog": { - "flake": false, - "locked": { - "lastModified": 1685584737, - "narHash": "sha256-8EUYzsJ5K1w8ZnaMGwqkLz9EniWKT3IC+vCfGrm2cIs=", - "owner": "nix-community", - "repo": "pruned-racket-catalog", - "rev": "7f9d3284fb4f82913fa374661832c438073fe0c7", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "catalog", - "repo": "pruned-racket-catalog", - "type": "github" - } - }, "root": { "inputs": { - "dream2nix": [ - "dream2nix_", - "dream2nix" - ], - "dream2nix_": "dream2nix_", "drv-tools": "drv-tools", "flake-utils": [ "flake-utils_", diff --git a/json2md/flake.nix b/json2md/flake.nix index bcdc9853c..57f1dabe2 100644 --- a/json2md/flake.nix +++ b/json2md/flake.nix @@ -3,117 +3,92 @@ nixpkgs_.url = "github:deemp/flakes?dir=source-flake/nixpkgs"; nixpkgs.follows = "nixpkgs_/nixpkgs"; flake-utils_.url = "github:deemp/flakes?dir=source-flake/flake-utils"; - dream2nix_.url = "github:deemp/flakes?dir=source-flake/dream2nix"; - dream2nix.follows = "dream2nix_/dream2nix"; flake-utils.follows = "flake-utils_/flake-utils"; drv-tools.url = "github:deemp/flakes?dir=drv-tools"; }; - outputs = - { self - , flake-utils - , dream2nix - , drv-tools - , nixpkgs - , ... - }: + outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system: let - # json2md converts an input JSON into md and prints to stdout - # Usage: - # json2md input - # Example: - # json2md <(printf '{"h1": "Hello, world"}' ) - out1 = - dream2nix.lib.makeFlakeOutputs - { - systems = flake-utils.lib.defaultSystems; - config.projectRoot = ./.; - source = ./.; - settings = [ - { - subsystemInfo.nodejs = 18; - } - ]; - }; - out2 = flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - inherit (builtins) isString baseNameOf dirOf; - inherit (drv-tools.lib.${system}) - mkBin mkBinName writeJSON withMan mkShellApp - framedBrackets mkShellApps man; - nix2mdSilent = outPath: dataNix: - assert builtins.isString outPath; - assert builtins.isList dataNix; - let - outName = baseNameOf outPath; - outDir = dirOf outPath; - tmpJSON = "${outName}.tmp.json"; - writeTmpJSON = writeJSON "pre-md" "./${tmpJSON}" dataNix; - json2md = out1.packages.${system}.default; - mdlint = pkgs.nodePackages.markdownlint-cli2; - name = "nix-to-md"; - in - mkShellApp { - name = name; - runtimeInputs = [ - pkgs.nodejs_18 - writeTmpJSON - json2md - mdlint - ]; - text = '' - ${mkBin writeTmpJSON} - mkdir -p ${outDir} - ${mkBinName json2md "json2md"} ${tmpJSON} > ${outPath} - ${mkBinName mdlint "markdownlint-cli2-fix"} ${outPath} || echo "" - rm ${tmpJSON} - ''; - }; + pkgs = inputs.nixpkgs.legacyPackages.${system}; + inherit (inputs.drv-tools.lib.${system}) + mkBin mkBinName writeJSON withMan mkShellApp + framedBrackets mkShellApps man; + inherit (builtins) isString baseNameOf dirOf; + + json2md = pkgs.buildNpmPackage rec { + buildInputs = [ + pkgs.nodejs_18 + ]; + + pname = "json2md"; + version = "2.0.0"; + + src = ./.; - nix2md = outPath: dataNix: - assert builtins.isString outPath; - assert builtins.isList dataNix; - withMan - ( - let - nix2md_ = nix2mdSilent outPath dataNix; - name = nix2md_.name; - in - mkShellApp { - name = name; - text = '' - ${mkBin nix2md_} - printf "${framedBrackets "%s"}" "ok ${name}" - ''; - description = "Convert a Nix expression to ${outPath}"; - } - ) - (x: '' - ${man.DESCRIPTION} - ${x.meta.description}. - ''); + npmDepsHash = "sha256-WjGhOEqL6Zg5tbBHgStr10ROcedJnkWCf5qiDwHOOp8="; + }; - test = mkShellApps { - testNix2md = { - text = "${mkBin (nix2md "tmp/some.md" [{ h1 = "Some text"; }])}"; - }; - }; + nix2mdSilent = outPath: dataNix: + assert builtins.isString outPath; + assert builtins.isList dataNix; + let + outName = baseNameOf outPath; + outDir = dirOf outPath; + tmpJSON = "${outName}.tmp.json"; + writeTmpJSON = writeJSON "pre-md" "./${tmpJSON}" dataNix; + # json2md = out1.packages.${system}.default; + mdlint = pkgs.nodePackages.markdownlint-cli2; + name = "nix-to-md"; + in + mkShellApp { + name = name; + runtimeInputs = [ + pkgs.nodejs_18 + writeTmpJSON + json2md + mdlint + ]; + text = '' + ${mkBin writeTmpJSON} + mkdir -p ${outDir} + ${mkBinName json2md "json2md"} ${tmpJSON} > ${outPath} + ${mkBinName mdlint "markdownlint-cli2-fix"} ${outPath} || echo "" + rm ${tmpJSON} + ''; + }; - json2md = out1.packages.${system}.default; + nix2md = outPath: dataNix: + assert builtins.isString outPath; + assert builtins.isList dataNix; + let + nix2md_ = nix2mdSilent outPath dataNix; + name = nix2md_.name; in - { - packages = { - inherit json2md; - } // test; - lib = { - inherit nix2mdSilent nix2md; - }; - devShells.default = pkgs.mkShell { - buildInputs = [ json2md ] ++ builtins.attrValues test; - }; + mkShellApp { + name = name; + text = '' + ${mkBin nix2md_} + printf "${framedBrackets "%s"}" "ok ${name}" + ''; + description = "Convert a Nix expression to ${outPath}"; } - ); + ; + + test = mkShellApps { + testNix2md = { + text = "${mkBin (nix2md "tmp/some.md" [{ h1 = "Some text"; }])}"; + }; + }; in - out2 - ; + { + packages = { + inherit json2md; + } // test; + lib = { + inherit nix2mdSilent nix2md; + }; + devShells.default = pkgs.mkShell { + buildInputs = [ json2md ] ++ builtins.attrValues test; + }; + } + ); } diff --git a/json2md/src/index.js b/json2md/index.js similarity index 92% rename from json2md/src/index.js rename to json2md/index.js index f12a6b314..73cb69e1e 100644 --- a/json2md/src/index.js +++ b/json2md/index.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - import json2md from "json2md" import * as fs from "fs" diff --git a/json2md/package.json b/json2md/package.json index 19ac05deb..a81e7e609 100644 --- a/json2md/package.json +++ b/json2md/package.json @@ -11,6 +11,6 @@ "json2md": "dist/index.js" }, "scripts": { - "build": "esbuild src/index.js --bundle --minify --platform=node --format=esm --outfile=dist/index.js" + "build": "esbuild index.js --bundle --minify --platform=node --format=esm --outfile=dist/index.js" } } \ No newline at end of file