Feature/monorepo (#24)
* refactor to include all necessary dependencies directly here * move indexer into monorepo * add snapshot tests and seperate sub.project for builtin types * add more missing builtins such as fromTOML
39
.gitignore
vendored
@ -1,47 +1,18 @@
|
|||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
# dependencies
|
|
||||||
/node_modules
|
|
||||||
/.pnp
|
|
||||||
.pnp.js
|
|
||||||
|
|
||||||
# testing
|
# testing
|
||||||
/coverage
|
coverage
|
||||||
/models/data/*
|
|
||||||
# !/models/data/index.ts
|
|
||||||
|
|
||||||
# nix
|
# nix
|
||||||
.direnv/
|
.direnv/
|
||||||
result
|
result
|
||||||
result-*
|
result-*
|
||||||
|
|
||||||
|
|
||||||
# next.js
|
|
||||||
/.next/
|
|
||||||
/out/
|
|
||||||
|
|
||||||
# production
|
|
||||||
/build
|
|
||||||
|
|
||||||
# misc
|
|
||||||
.DS_Store
|
|
||||||
*.pem
|
|
||||||
result
|
|
||||||
result-*
|
|
||||||
|
|
||||||
# debug
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
.pnpm-debug.log*
|
|
||||||
|
|
||||||
# local env files
|
|
||||||
.env*.local
|
|
||||||
.pre-commit-config.yaml
|
.pre-commit-config.yaml
|
||||||
|
|
||||||
# vercel
|
# dream2nix
|
||||||
.vercel
|
|
||||||
|
|
||||||
# typescript
|
## dream2nix internal cache
|
||||||
*.tsbuildinfo
|
.dream2nix
|
||||||
next-env.d.ts
|
|
174
flake.lock
@ -43,11 +43,11 @@
|
|||||||
"crane": {
|
"crane": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1670284777,
|
"lastModified": 1670900067,
|
||||||
"narHash": "sha256-JF0pc0s4z/X+Iy+lNHOwUQ8I5bz+q7uX4HrKTNIEj24=",
|
"narHash": "sha256-VXVa+KBfukhmWizaiGiHRVX/fuk66P8dgSFfkVN4/MY=",
|
||||||
"owner": "ipetkov",
|
"owner": "ipetkov",
|
||||||
"repo": "crane",
|
"repo": "crane",
|
||||||
"rev": "2243fb9c872de25cb564a02d324ea6a5b9853052",
|
"rev": "59b31b41a589c0a65e4a1f86b0e5eac68081468b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -86,14 +86,15 @@
|
|||||||
"nix-pypi-fetcher": "nix-pypi-fetcher",
|
"nix-pypi-fetcher": "nix-pypi-fetcher",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"poetry2nix": "poetry2nix",
|
"poetry2nix": "poetry2nix",
|
||||||
"pre-commit-hooks": "pre-commit-hooks"
|
"pre-commit-hooks": "pre-commit-hooks",
|
||||||
|
"pruned-racket-catalog": "pruned-racket-catalog"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1670559747,
|
"lastModified": 1676992344,
|
||||||
"narHash": "sha256-yT/ofVjhgGrdFQeFONFpLNnVJa8ALMuSvlILczvIIn4=",
|
"narHash": "sha256-TEn5kEi/jL9Dt6O+ZZ7kQwnlAgEv0r4VgQZnav/cfV4=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "dream2nix",
|
"repo": "dream2nix",
|
||||||
"rev": "8b4d355e8008c47791219da30fc390baf78c4099",
|
"rev": "db72710500a80bdf4589b6807d2491a4a0dae3ad",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -143,14 +144,17 @@
|
|||||||
},
|
},
|
||||||
"flake-parts": {
|
"flake-parts": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs-lib": "nixpkgs-lib"
|
"nixpkgs-lib": [
|
||||||
|
"dream2nix",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1668450977,
|
"lastModified": 1675933616,
|
||||||
"narHash": "sha256-cfLhMhnvXn6x1vPm+Jow3RiFAUSCw/l1utktCw5rVA4=",
|
"narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "flake-parts",
|
"repo": "flake-parts",
|
||||||
"rev": "d591857e9d7dd9ddbfba0ea02b43b927c3c0f1fa",
|
"rev": "47478a4a003e745402acf63be7f9a092d51b83d7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -161,11 +165,11 @@
|
|||||||
},
|
},
|
||||||
"flake-utils": {
|
"flake-utils": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1659877975,
|
"lastModified": 1667395993,
|
||||||
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -189,21 +193,6 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"flake-utils_2": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1667395993,
|
|
||||||
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flakeCompat": {
|
"flakeCompat": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
@ -304,30 +293,6 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixdoc-fork": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-utils": [
|
|
||||||
"nixdoc-fork",
|
|
||||||
"rust-overlay",
|
|
||||||
"flake-utils"
|
|
||||||
],
|
|
||||||
"nixpkgs": "nixpkgs_2",
|
|
||||||
"rust-overlay": "rust-overlay"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1675862788,
|
|
||||||
"narHash": "sha256-TS8YpNtYKBWP6xXrJ7DIdmJwwcCq0Tuf9NhQYWXoPXA=",
|
|
||||||
"owner": "hsjobeki",
|
|
||||||
"repo": "nixdoc",
|
|
||||||
"rev": "76276fdb30ab4fcbe7ba19844a2afd9447256674",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "hsjobeki",
|
|
||||||
"repo": "nixdoc",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1665580254,
|
"lastModified": 1665580254,
|
||||||
@ -343,22 +308,19 @@
|
|||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs-lib": {
|
"nixpkgs-master": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "lib",
|
"lastModified": 1677165478,
|
||||||
"lastModified": 1665349835,
|
"narHash": "sha256-bWABTj9vlT26d3zpI+NQmuOwcXAzwJGNIgdgPfsnyk8=",
|
||||||
"narHash": "sha256-UK4urM3iN80UXQ7EaOappDzcisYIuEURFRoGQ/yPkug=",
|
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "34c5293a71ffdb2fe054eb5288adc1882c1eb0b1",
|
"rev": "21d1c5425c1c0f4b4ae6203086951164920d9fab",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"dir": "lib",
|
"id": "nixpkgs",
|
||||||
"owner": "NixOS",
|
"ref": "master",
|
||||||
"ref": "nixos-unstable",
|
"type": "indirect"
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs-stable": {
|
"nixpkgs-stable": {
|
||||||
@ -379,46 +341,16 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1675333202,
|
"lastModified": 1677063315,
|
||||||
"narHash": "sha256-ZcZqGz2K7V9/uIrWfdmKUfC5PkcuR29DKTqUTF5BURo=",
|
"narHash": "sha256-qiB4ajTeAOVnVSAwCNEEkoybrAlA+cpeiBxLobHndE8=",
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "a2780dc543d24f33d7a2d7fa5b2bf609ed8c1849",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs_3": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1665296151,
|
|
||||||
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
|
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
|
"rev": "988cc958c57ce4350ec248d2d53087777f9e1949",
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"ref": "nixpkgs-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs_4": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1675249806,
|
|
||||||
"narHash": "sha256-u8Rcqekusl3pMZm68hZqr6zozI8Ug5IxqOiqDLAlu1k=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "79feedf38536de2a27d13fe2eaf200a9c05193ba",
|
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"id": "nixpkgs",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -467,7 +399,7 @@
|
|||||||
"pre-commit-hooks_2": {
|
"pre-commit-hooks_2": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-compat": "flake-compat",
|
"flake-compat": "flake-compat",
|
||||||
"flake-utils": "flake-utils_2",
|
"flake-utils": "flake-utils",
|
||||||
"gitignore": "gitignore",
|
"gitignore": "gitignore",
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
@ -475,11 +407,11 @@
|
|||||||
"nixpkgs-stable": "nixpkgs-stable"
|
"nixpkgs-stable": "nixpkgs-stable"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1674550893,
|
"lastModified": 1677160285,
|
||||||
"narHash": "sha256-HXI8AB96PP7UZ7iPANACXM8qc9eMz0ljxBEDM8JJKhY=",
|
"narHash": "sha256-tBzpCjMP+P3Y3nKLYvdBkXBg3KvTMo3gvi8tLQaqXVY=",
|
||||||
"owner": "cachix",
|
"owner": "cachix",
|
||||||
"repo": "pre-commit-hooks.nix",
|
"repo": "pre-commit-hooks.nix",
|
||||||
"rev": "7bdf85f6bbef581eb687838d19f2b35a4c9d77f0",
|
"rev": "2bd861ab81469428d9c823ef72c4bb08372dd2c4",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -488,11 +420,28 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"pruned-racket-catalog": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1672537287,
|
||||||
|
"narHash": "sha256-SuOvXVcLfakw18oJB/PuRMyvGyGG1+CQD3R+TGHIv44=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "pruned-racket-catalog",
|
||||||
|
"rev": "c8b89557fb53b36efa2ee48a769c7364df0f6262",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"ref": "catalog",
|
||||||
|
"repo": "pruned-racket-catalog",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"dream2nix": "dream2nix",
|
"dream2nix": "dream2nix",
|
||||||
"nixdoc-fork": "nixdoc-fork",
|
"nixpkgs": "nixpkgs_2",
|
||||||
"nixpkgs": "nixpkgs_4",
|
"nixpkgs-master": "nixpkgs-master",
|
||||||
"pre-commit-hooks": "pre-commit-hooks_2"
|
"pre-commit-hooks": "pre-commit-hooks_2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -512,25 +461,6 @@
|
|||||||
"repo": "rust-analyzer",
|
"repo": "rust-analyzer",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"rust-overlay": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-utils": "flake-utils",
|
|
||||||
"nixpkgs": "nixpkgs_3"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1670380307,
|
|
||||||
"narHash": "sha256-7fJN5ndnE8YbrrtYdqMo3gDV/BW37M4wNBRhjdfP/XY=",
|
|
||||||
"owner": "oxalica",
|
|
||||||
"repo": "rust-overlay",
|
|
||||||
"rev": "fc98242f5f49d39b8fd3a611c146741a35dc012d",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "oxalica",
|
|
||||||
"repo": "rust-overlay",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
123
flake.nix
@ -1,55 +1,109 @@
|
|||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
|
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||||
|
nixpkgs-master.url = "nixpkgs/master";
|
||||||
|
|
||||||
dream2nix.url = "github:nix-community/dream2nix";
|
dream2nix.url = "github:nix-community/dream2nix";
|
||||||
nixdoc-fork.url = "github:hsjobeki/nixdoc";
|
|
||||||
pre-commit-hooks = {
|
pre-commit-hooks = {
|
||||||
url = "github:cachix/pre-commit-hooks.nix";
|
url = "github:cachix/pre-commit-hooks.nix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
outputs = { self, nixpkgs, pre-commit-hooks, ... }@inp:
|
outputs = { self, nixpkgs, pre-commit-hooks, dream2nix, nixpkgs-master }:
|
||||||
let
|
let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = inp.nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
inherit (builtins.fromJSON (builtins.readFile ./package.json)) name;
|
websiteName = (builtins.fromJSON (builtins.readFile ./website/package.json)).name;
|
||||||
prepareData = ''
|
inherit (self.packages.${system}) indexer nixpkgs-data builtins-data;
|
||||||
cp -f ${inp.nixdoc-fork.packages.${system}.data.lib} ./models/data/lib.json
|
|
||||||
cp -f ${inp.nixdoc-fork.packages.${system}.data.build_support} ./models/data/trivial-builders.json
|
prepareData = prefix: ''
|
||||||
node ./scripts/make-builtins.js
|
cp -f ${nixpkgs-data.lib} ${prefix}/lib.json
|
||||||
|
cp -f ${nixpkgs-data.build_support} ${prefix}/trivial-builders.json
|
||||||
|
cp -f ${builtins-data}/lib/data.json ${prefix}/builtins.json
|
||||||
'';
|
'';
|
||||||
in
|
|
||||||
(inp.dream2nix.lib.makeFlakeOutputs {
|
|
||||||
systemsFromFile = ./nix_systems;
|
|
||||||
config.projectRoot = ./.;
|
|
||||||
source = ./.;
|
|
||||||
settings = [
|
|
||||||
{
|
|
||||||
subsystemInfo.nodejs = 18;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
packageOverrides = {
|
|
||||||
${name}.staticPage = {
|
|
||||||
preBuild = prepareData;
|
|
||||||
installPhase = ''
|
|
||||||
runHook preInstall
|
|
||||||
|
|
||||||
npm run export
|
dream2nixOutput = dream2nix.lib.makeFlakeOutputs {
|
||||||
mkdir -p $out/static
|
systems = [ system ];
|
||||||
cp -r ./out/* $out/static/
|
projects = ./projects.toml;
|
||||||
|
config.projectRoot = ./.;
|
||||||
|
source = ./.;
|
||||||
|
|
||||||
runHook postInstall
|
packageOverrides = {
|
||||||
'';
|
${websiteName}.staticPage = {
|
||||||
|
preBuild = prepareData "models/data";
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
|
||||||
|
npm run export
|
||||||
|
mkdir -p $out/static
|
||||||
|
cp -r ./out/* $out/static/
|
||||||
|
cp -r ./ $lib
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
tests.run = {
|
||||||
|
installPhase = "";
|
||||||
|
preBuild = ''
|
||||||
|
ls -la
|
||||||
|
mkdir -p data
|
||||||
|
${prepareData "data"}
|
||||||
|
|
||||||
|
'';
|
||||||
|
doCheck = true;
|
||||||
|
checkPhase = ''
|
||||||
|
ls -la
|
||||||
|
npm run test -- --ci
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
in
|
||||||
// {
|
{
|
||||||
|
packages.${system} = dream2nixOutput.packages.${system} // {
|
||||||
|
nixpkgs-data = pkgs.stdenv.mkDerivation {
|
||||||
|
pname = "data";
|
||||||
|
version = "0.1.0";
|
||||||
|
description = ''
|
||||||
|
wrapper around the indexer.
|
||||||
|
|
||||||
|
Calls the indexer with '<nixpkgs>'/path.
|
||||||
|
and defines one output for every specified input path
|
||||||
|
|
||||||
|
currently this list is manually maintained below.
|
||||||
|
'';
|
||||||
|
src = nixpkgs-master;
|
||||||
|
outputs = [ "out" "lib" "build_support" ];
|
||||||
|
nativeBuildInputs = [ indexer ];
|
||||||
|
buildPhase = ''
|
||||||
|
echo "running nix metadata collect in nixpkgs/lib"
|
||||||
|
${indexer}/bin/indexer --dir ./lib
|
||||||
|
${indexer}/bin/indexer --dir ./pkgs/build-support
|
||||||
|
'';
|
||||||
|
installPhase = ''
|
||||||
|
cat lib.json > $lib
|
||||||
|
cat build-support.json > $build_support
|
||||||
|
|
||||||
|
mkdir $out
|
||||||
|
ln -s $lib $out/lib
|
||||||
|
ln -s $build_support $out/build_support
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
default = self.packages.${system}.noogle;
|
||||||
|
};
|
||||||
|
|
||||||
devShells.${system}.default = pkgs.mkShell {
|
devShells.${system}.default = pkgs.mkShell {
|
||||||
buildInputs = with pkgs; [ nodejs-18_x ];
|
buildInputs = with pkgs; [ nodejs-18_x rustfmt rustc cargo clippy ];
|
||||||
|
inputsFrom = [ indexer ];
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
${prepareData}
|
${prepareData "website/models/data"}
|
||||||
|
${prepareData "tests/data"}
|
||||||
${self.checks.${system}.pre-commit-check.shellHook}
|
${self.checks.${system}.pre-commit-check.shellHook}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
checks.${system} = {
|
checks.${system} = {
|
||||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
@ -58,6 +112,11 @@
|
|||||||
statix.enable = true;
|
statix.enable = true;
|
||||||
markdownlint.enable = true;
|
markdownlint.enable = true;
|
||||||
};
|
};
|
||||||
|
excludes = [ "indexer/test" ".github" "scripts/data" ];
|
||||||
|
settings = {
|
||||||
|
statix.ignore = [ "indexer/test" ];
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
4
indexer/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
target/
|
||||||
|
**/*.rs.bk
|
||||||
|
data.json
|
2
indexer/.travis.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
language: nix
|
||||||
|
sudo: true
|
381
indexer/Cargo.lock
generated
Normal file
@ -0,0 +1,381 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ansi_term"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arenatree"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "git+https://gitlab.com/jD91mZM2/arenatree#f9bf7efa9a5ef4c2dd9e2acc5a4cc79a987cb648"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
|
||||||
|
dependencies = [
|
||||||
|
"nodrop",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "atty"
|
||||||
|
version = "0.2.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"termion",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "backtrace"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
|
||||||
|
dependencies = [
|
||||||
|
"backtrace-sys",
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"rustc-demangle",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "backtrace-sys"
|
||||||
|
version = "0.1.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "2.32.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
|
||||||
|
dependencies = [
|
||||||
|
"ansi_term",
|
||||||
|
"atty",
|
||||||
|
"bitflags",
|
||||||
|
"strsim",
|
||||||
|
"textwrap",
|
||||||
|
"unicode-width",
|
||||||
|
"vec_map",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "failure"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"
|
||||||
|
dependencies = [
|
||||||
|
"backtrace",
|
||||||
|
"failure_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "failure_derive"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 0.4.20",
|
||||||
|
"quote 0.6.8",
|
||||||
|
"syn 0.15.15",
|
||||||
|
"synstructure",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indexer"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"rnix",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"structopt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.43"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nodrop"
|
||||||
|
version = "0.1.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "0.4.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-xid",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.47"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "0.6.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 0.4.20",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 1.0.47",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_syscall"
|
||||||
|
version = "0.1.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_termios"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
|
||||||
|
dependencies = [
|
||||||
|
"redox_syscall",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rnix"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "git+https://gitlab.com/jD91mZM2/rnix.git?rev=10b86c94291b4864470158ef8750de85ddd8d4ba#10b86c94291b4864470158ef8750de85ddd8d4ba"
|
||||||
|
dependencies = [
|
||||||
|
"arenatree",
|
||||||
|
"arrayvec",
|
||||||
|
"failure",
|
||||||
|
"smol_str",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-demangle"
|
||||||
|
version = "0.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.148"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.148"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 1.0.47",
|
||||||
|
"quote 1.0.21",
|
||||||
|
"syn 1.0.105",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.89"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "smol_str"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f3ed6f19b800d76574926e458d5f8e2dbea86c2b58c08d33a982448f09ac8d0c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "structopt"
|
||||||
|
version = "0.2.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d77af7242f18c40fd19cb270985930f239ee1646cfb482050bbae9da1d18743b"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"structopt-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "structopt-derive"
|
||||||
|
version = "0.2.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "17ff01fe96de9d16e7372ae5f19dd7ece2c703b51043c3db9ea27f9e393ea311"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 0.4.20",
|
||||||
|
"quote 0.6.8",
|
||||||
|
"syn 0.15.15",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "0.15.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0a9c2bf1e53c21704a7cce1b2a42768f1ae32a6777108a0d7f1faa4bfe7f7c04"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 0.4.20",
|
||||||
|
"quote 0.6.8",
|
||||||
|
"unicode-xid",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.105"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 1.0.47",
|
||||||
|
"quote 1.0.21",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "synstructure"
|
||||||
|
version = "0.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 0.4.20",
|
||||||
|
"quote 0.6.8",
|
||||||
|
"syn 0.15.15",
|
||||||
|
"unicode-xid",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termion"
|
||||||
|
version = "1.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"redox_termios",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "textwrap"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-xid"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vec_map"
|
||||||
|
version = "0.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
14
indexer/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[package]
|
||||||
|
name = "indexer"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Johannes Kirschbauer <hsjobeki@gmail.com>"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
structopt = "0.2"
|
||||||
|
serde_json = "1.0.89"
|
||||||
|
serde = { version = "1.0.148", features = ["derive"] }
|
||||||
|
|
||||||
|
[dependencies.rnix]
|
||||||
|
git = "https://gitlab.com/jD91mZM2/rnix.git"
|
||||||
|
rev = "10b86c94291b4864470158ef8750de85ddd8d4ba"
|
36
indexer/makeMarkdown.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// simple script
|
||||||
|
// test.json in generated with "cargo run -- --dir ./test"
|
||||||
|
const data = require("./test.json");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
const all_docs = data.reduce(
|
||||||
|
(acc, doc) => `${acc}
|
||||||
|
## ${doc.name}
|
||||||
|
|
||||||
|
### Description
|
||||||
|
|
||||||
|
\`\`\`nix
|
||||||
|
${doc.description}
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
\`\`\`nix
|
||||||
|
${doc.example}
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
### Type
|
||||||
|
|
||||||
|
\`\`\`nix
|
||||||
|
${doc.fn_type}
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
`,
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
|
fs.writeFile("content.md", `# Functions\n${all_docs}`, (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
286
indexer/src/main.rs
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
extern crate rnix;
|
||||||
|
extern crate serde;
|
||||||
|
extern crate serde_json;
|
||||||
|
extern crate structopt;
|
||||||
|
use rnix::parser::{ASTKind, ASTNode, Arena, Data};
|
||||||
|
use rnix::tokenizer::Trivia;
|
||||||
|
use rnix::tokenizer::{Meta, Span};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fs::{self, File};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
/// Command line arguments for the indexer
|
||||||
|
#[derive(Debug, StructOpt)]
|
||||||
|
#[structopt(name = "indexer", about = "Generate Metadata from Nix files")]
|
||||||
|
struct Options {
|
||||||
|
/// directory to process.
|
||||||
|
#[structopt(short = "D", long = "dir", parse(from_os_str))]
|
||||||
|
dir: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct ManualEntry {
|
||||||
|
pub id: String,
|
||||||
|
pub line: Option<usize>,
|
||||||
|
pub category: String,
|
||||||
|
pub name: String,
|
||||||
|
pub fn_type: Option<String>,
|
||||||
|
pub description: String,
|
||||||
|
pub example: Option<String>,
|
||||||
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct DocComment {
|
||||||
|
/// Primary documentation string.
|
||||||
|
doc: String,
|
||||||
|
|
||||||
|
/// Optional type annotation for the thing being documented.
|
||||||
|
doc_type: Option<String>,
|
||||||
|
|
||||||
|
/// Usage example(s) (interpreted as a single code block)
|
||||||
|
example: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct DocItem {
|
||||||
|
name: String,
|
||||||
|
span: Span,
|
||||||
|
comment: DocComment,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieve documentation comments. For now only multiline comments are considered
|
||||||
|
fn retrieve_doc_comment(allow_single_line: bool, meta: &Meta) -> Option<String> {
|
||||||
|
for item in meta.leading.iter() {
|
||||||
|
if let Trivia::Comment {
|
||||||
|
multiline, content, ..
|
||||||
|
} = item
|
||||||
|
{
|
||||||
|
if *multiline || allow_single_line {
|
||||||
|
return Some(content.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Transforms an AST node into a `DocItem` if it has a leading
|
||||||
|
/// documentation comment.
|
||||||
|
fn retrieve_doc_item(node: &ASTNode) -> Option<DocItem> {
|
||||||
|
// We are only interested in identifiers.
|
||||||
|
|
||||||
|
if let Data::Ident(meta, name) = &node.data {
|
||||||
|
let comment = retrieve_doc_comment(false, meta)?;
|
||||||
|
return Some(DocItem {
|
||||||
|
span: node.span,
|
||||||
|
name: name.to_string(),
|
||||||
|
comment: parse_doc_comment(&comment),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_indentation(line: &str) -> usize {
|
||||||
|
return line
|
||||||
|
.char_indices()
|
||||||
|
.find(|(_, ch)| !(ch.is_whitespace() && *ch != '\n'))
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.unwrap_or_else(|| line.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// *Really* dumb, mutable, hacky doc comment "parser".
|
||||||
|
fn parse_doc_comment(raw: &str) -> DocComment {
|
||||||
|
enum ParseState {
|
||||||
|
Doc,
|
||||||
|
Type,
|
||||||
|
Example,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut doc = String::new();
|
||||||
|
let mut doc_type = String::new();
|
||||||
|
let mut example = String::new();
|
||||||
|
let mut state = ParseState::Doc;
|
||||||
|
|
||||||
|
let mut type_ident = 0;
|
||||||
|
let mut doc_ident = 0;
|
||||||
|
let mut example_ident = 0;
|
||||||
|
|
||||||
|
for line in raw.clone().lines() {
|
||||||
|
let mut line = line.clone().trim_end();
|
||||||
|
let trimmed = line.clone().trim();
|
||||||
|
if trimmed.starts_with("Type:") {
|
||||||
|
state = ParseState::Type;
|
||||||
|
line = &trimmed[5..]; // trim 'Type:'
|
||||||
|
}
|
||||||
|
|
||||||
|
if trimmed.starts_with("Example:") {
|
||||||
|
state = ParseState::Example;
|
||||||
|
line = &trimmed[8..]; // trim 'Example:'
|
||||||
|
}
|
||||||
|
match state {
|
||||||
|
ParseState::Type => {
|
||||||
|
let curr_indent = get_indentation(line);
|
||||||
|
if curr_indent > 0 && type_ident == 0 {
|
||||||
|
type_ident = curr_indent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ParseState::Doc => {
|
||||||
|
let curr_indent = get_indentation(line);
|
||||||
|
if curr_indent > 0 && doc_ident == 0 {
|
||||||
|
doc_ident = curr_indent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ParseState::Example => {
|
||||||
|
let curr_indent = get_indentation(line);
|
||||||
|
if curr_indent > 0 && example_ident == 0 {
|
||||||
|
example_ident = curr_indent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state = ParseState::Doc;
|
||||||
|
|
||||||
|
for line in raw.lines() {
|
||||||
|
let mut line = line.trim_end();
|
||||||
|
let trimmed = line.clone().trim();
|
||||||
|
if trimmed.starts_with("Type:") {
|
||||||
|
state = ParseState::Type;
|
||||||
|
line = &trimmed[5..]; // trim 'Type:'
|
||||||
|
}
|
||||||
|
|
||||||
|
if trimmed.starts_with("Example:") {
|
||||||
|
state = ParseState::Example;
|
||||||
|
line = &trimmed[8..]; // trim 'Example:'
|
||||||
|
}
|
||||||
|
match state {
|
||||||
|
// important: trim only trailing whitespaces; as leading ones might be markdown formatting or code examples.
|
||||||
|
ParseState::Type => {
|
||||||
|
let stripped = line.trim_end();
|
||||||
|
let formatted = stripped.replacen(&" ".repeat(type_ident), "", 1);
|
||||||
|
doc_type.push_str(&formatted);
|
||||||
|
doc_type.push('\n');
|
||||||
|
}
|
||||||
|
ParseState::Doc => {
|
||||||
|
let stripped = line.trim_end();
|
||||||
|
let formatted = stripped.replacen(&" ".repeat(doc_ident), "", 1);
|
||||||
|
doc.push_str(&formatted);
|
||||||
|
doc.push('\n');
|
||||||
|
}
|
||||||
|
ParseState::Example => {
|
||||||
|
let stripped = line.trim_end();
|
||||||
|
let formatted = stripped.replacen(&" ".repeat(example_ident), "", 1);
|
||||||
|
example.push_str(&formatted);
|
||||||
|
example.push('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let f = |mut s: String| {
|
||||||
|
if s.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
let len = s.trim_end_matches(&['\r', '\n'][..]).len();
|
||||||
|
s.truncate(len);
|
||||||
|
return Some(s.trim_start().into());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// let doc_f = f(doc);
|
||||||
|
DocComment {
|
||||||
|
doc: f(doc).unwrap_or("".to_owned()),
|
||||||
|
doc_type: f(doc_type),
|
||||||
|
example: f(example),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_line(span: Span, src: &String) -> Option<usize> {
|
||||||
|
let mut line_nr: usize = 1;
|
||||||
|
for (count, char) in src.chars().enumerate() {
|
||||||
|
if char == '\n' {
|
||||||
|
line_nr = line_nr + 1;
|
||||||
|
}
|
||||||
|
if count == span.start as usize {
|
||||||
|
return Some(line_nr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Traverse a pattern argument, collecting its argument names.
|
||||||
|
/// Traverse a Nix lambda and collect the identifiers of arguments
|
||||||
|
/// until an unexpected AST node is encountered.
|
||||||
|
///
|
||||||
|
/// This will collect the argument names for curried functions in the
|
||||||
|
/// `a: b: c: ...`-style, but does not currently work with pattern
|
||||||
|
/// functions (`{ a, b, c }: ...`).
|
||||||
|
///
|
||||||
|
/// In the AST representation used by rnix, any lambda node has an
|
||||||
|
/// immediate child that is the identifier of its argument. The "body"
|
||||||
|
/// of the lambda is two steps to the right from that identifier, if
|
||||||
|
/// it is a lambda the function is curried and we can recurse.
|
||||||
|
/// Traverse the arena from a top-level SetEntry and collect, where
|
||||||
|
/// possible:
|
||||||
|
///
|
||||||
|
/// 1. The identifier of the set entry itself.
|
||||||
|
/// 2. The attached doc comment on the entry.
|
||||||
|
/// 3. The argument names of any curried functions (pattern functions
|
||||||
|
/// not yet supported).
|
||||||
|
fn collect_entry_information<'a>(arena: &Arena<'a>, entry_node: &ASTNode) -> Option<DocItem> {
|
||||||
|
// The "root" of any attribute set entry is this `SetEntry` node.
|
||||||
|
// It has an `Attribute` child, which in turn has the identifier
|
||||||
|
// (on which the documentation comment is stored) as its child.
|
||||||
|
let attr_node = &arena[entry_node.node.child?];
|
||||||
|
let ident_node = &arena[attr_node.node.child?];
|
||||||
|
// At this point we can retrieve the `DocItem` from the identifier
|
||||||
|
// node - this already contains most of the information we are
|
||||||
|
// interested in.
|
||||||
|
let doc_item = retrieve_doc_item(ident_node)?;
|
||||||
|
|
||||||
|
// From our entry we can walk two nodes to the right and check
|
||||||
|
// whether we are dealing with a lambda. If so, we can start
|
||||||
|
// collecting the function arguments - otherwise we're done.
|
||||||
|
// let assign_node = &arena[attr_node.node.sibling?];
|
||||||
|
// let content_node = &arena[assign_node.node.sibling?];
|
||||||
|
Some(doc_item)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let opts = Options::from_args();
|
||||||
|
let paths = fs::read_dir(&opts.dir).unwrap();
|
||||||
|
let mut data: Vec<ManualEntry> = vec![];
|
||||||
|
for path in paths {
|
||||||
|
let file_path = path.unwrap();
|
||||||
|
let file_type = file_path.file_type().unwrap();
|
||||||
|
let file = file_path.path();
|
||||||
|
if file_type.is_file() && file.extension().unwrap() == "nix" {
|
||||||
|
// sources.push(file);
|
||||||
|
let src = fs::read_to_string(&file).unwrap();
|
||||||
|
let nix = rnix::parse(&src).unwrap();
|
||||||
|
let filename = file.file_stem().unwrap().to_str().unwrap();
|
||||||
|
let parent = file
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.file_name()
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let entries: Vec<ManualEntry> = nix
|
||||||
|
.arena
|
||||||
|
.into_iter()
|
||||||
|
.filter(|node| node.kind == ASTKind::SetEntry)
|
||||||
|
.filter_map(|node| collect_entry_information(&nix.arena, node))
|
||||||
|
.map(|d| ManualEntry {
|
||||||
|
id: format!("{}.{}.{}", parent, filename, d.name),
|
||||||
|
line: Some(get_line(d.span, &src)).unwrap_or(None),
|
||||||
|
category: file.display().to_string(),
|
||||||
|
name: d.name,
|
||||||
|
description: d.comment.doc,
|
||||||
|
fn_type: d.comment.doc_type,
|
||||||
|
example: d.comment.example,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
data.extend(entries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let json_file =
|
||||||
|
File::create(opts.dir.file_name().unwrap().to_str().unwrap().to_owned() + ".json").unwrap();
|
||||||
|
::serde_json::to_writer(&json_file, &data).unwrap();
|
||||||
|
}
|
987
indexer/test/types.nix
Normal file
@ -0,0 +1,987 @@
|
|||||||
|
# Definitions related to run-time type checking. Used in particular
|
||||||
|
# to type-check NixOS configurations.
|
||||||
|
{ lib }:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit (lib)
|
||||||
|
elem
|
||||||
|
flip
|
||||||
|
isAttrs
|
||||||
|
isBool
|
||||||
|
isDerivation
|
||||||
|
isFloat
|
||||||
|
isFunction
|
||||||
|
isInt
|
||||||
|
isList
|
||||||
|
isString
|
||||||
|
isStorePath
|
||||||
|
toDerivation
|
||||||
|
toList
|
||||||
|
;
|
||||||
|
inherit (lib.lists)
|
||||||
|
all
|
||||||
|
concatLists
|
||||||
|
count
|
||||||
|
elemAt
|
||||||
|
filter
|
||||||
|
foldl'
|
||||||
|
head
|
||||||
|
imap1
|
||||||
|
last
|
||||||
|
length
|
||||||
|
tail
|
||||||
|
;
|
||||||
|
inherit (lib.attrsets)
|
||||||
|
attrNames
|
||||||
|
filterAttrs
|
||||||
|
hasAttr
|
||||||
|
mapAttrs
|
||||||
|
optionalAttrs
|
||||||
|
zipAttrsWith
|
||||||
|
;
|
||||||
|
inherit (lib.options)
|
||||||
|
getFiles
|
||||||
|
getValues
|
||||||
|
mergeDefaultOption
|
||||||
|
mergeEqualOption
|
||||||
|
mergeOneOption
|
||||||
|
mergeUniqueOption
|
||||||
|
showFiles
|
||||||
|
showOption
|
||||||
|
;
|
||||||
|
inherit (lib.strings)
|
||||||
|
concatMapStringsSep
|
||||||
|
concatStringsSep
|
||||||
|
escapeNixString
|
||||||
|
hasInfix
|
||||||
|
isStringLike
|
||||||
|
;
|
||||||
|
inherit (lib.trivial)
|
||||||
|
boolToString
|
||||||
|
;
|
||||||
|
|
||||||
|
inherit (lib.modules)
|
||||||
|
mergeDefinitions
|
||||||
|
fixupOptionType
|
||||||
|
mergeOptionDecls
|
||||||
|
;
|
||||||
|
outer_types =
|
||||||
|
rec {
|
||||||
|
isType = type: x: (x._type or "") == type;
|
||||||
|
|
||||||
|
setType = typeName: value: value // {
|
||||||
|
_type = typeName;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Default type merging function
|
||||||
|
takes two type functors and return the merged type
|
||||||
|
|
||||||
|
*/
|
||||||
|
defaultTypeMerge = f: f':
|
||||||
|
let wrapped = f.wrapped.typeMerge f'.wrapped.functor;
|
||||||
|
payload = f.binOp f.payload f'.payload;
|
||||||
|
in
|
||||||
|
# cannot merge different types
|
||||||
|
if f.name != f'.name
|
||||||
|
then null
|
||||||
|
# simple types
|
||||||
|
else if (f.wrapped == null && f'.wrapped == null)
|
||||||
|
&& (f.payload == null && f'.payload == null)
|
||||||
|
then f.type
|
||||||
|
# composed types
|
||||||
|
else if (f.wrapped != null && f'.wrapped != null) && (wrapped != null)
|
||||||
|
then f.type wrapped
|
||||||
|
# value types
|
||||||
|
else if (f.payload != null && f'.payload != null) && (payload != null)
|
||||||
|
then f.type payload
|
||||||
|
else null;
|
||||||
|
|
||||||
|
/* Default type functor */
|
||||||
|
defaultFunctor = name: {
|
||||||
|
inherit name;
|
||||||
|
type = types.${name} or null;
|
||||||
|
wrapped = null;
|
||||||
|
payload = null;
|
||||||
|
binOp = a: b: null;
|
||||||
|
};
|
||||||
|
|
||||||
|
isOptionType = isType "option-type";
|
||||||
|
/*
|
||||||
|
Function that creates an optionType to be used in the module system.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
Type:
|
||||||
|
{
|
||||||
|
name :: String;
|
||||||
|
description :: String ?;
|
||||||
|
descriptionClass :: "noun" | "conjunction" | "composite" ?;
|
||||||
|
check :: (a -> Bool) ?;
|
||||||
|
merge ::
|
||||||
|
emptyValue :: {} ?;
|
||||||
|
getSubOptions :: ( [String] -> {}) ?;
|
||||||
|
getSubModules :: ( [Module] ) ?;
|
||||||
|
substSubModules :: ( [Module] ) ?;
|
||||||
|
typeMerge ::
|
||||||
|
functor ::
|
||||||
|
deprecationMessage ::
|
||||||
|
nestedTypes ::
|
||||||
|
}
|
||||||
|
->
|
||||||
|
{
|
||||||
|
name :: String
|
||||||
|
name check merge emptyValue getSubOptions getSubModules substSubModules
|
||||||
|
typeMerge functor deprecationMessage nestedTypes descriptionClass;
|
||||||
|
description = if description == null then name else description;
|
||||||
|
|
||||||
|
_type :: "option-type";
|
||||||
|
};
|
||||||
|
|
||||||
|
*/
|
||||||
|
mkOptionType =
|
||||||
|
{ # Human-readable representation of the type, should be equivalent to
|
||||||
|
# the type function name.
|
||||||
|
name
|
||||||
|
, # Description of the type, defined recursively by embedding the wrapped type if any.
|
||||||
|
description ? null
|
||||||
|
# A hint for whether or not this description needs parentheses. Possible values:
|
||||||
|
# - "noun": a simple noun phrase such as "positive integer"
|
||||||
|
# - "conjunction": a phrase with a potentially ambiguous "or" connective.
|
||||||
|
# - "composite": a phrase with an "of" connective
|
||||||
|
# See the `optionDescriptionPhrase` function.
|
||||||
|
, descriptionClass ? null
|
||||||
|
, # DO NOT USE WITHOUT KNOWING WHAT YOU ARE DOING!
|
||||||
|
# Function applied to each definition that must return false when a definition
|
||||||
|
# does not match the type. It should not check more than the root of the value,
|
||||||
|
# because checking nested values reduces laziness, leading to unnecessary
|
||||||
|
# infinite recursions in the module system.
|
||||||
|
# Further checks of nested values should be performed by throwing in
|
||||||
|
# the merge function.
|
||||||
|
# Strict and deep type checking can be performed by calling lib.deepSeq on
|
||||||
|
# the merged value.
|
||||||
|
#
|
||||||
|
# See https://github.com/NixOS/nixpkgs/pull/6794 that introduced this change,
|
||||||
|
# https://github.com/NixOS/nixpkgs/pull/173568 and
|
||||||
|
# https://github.com/NixOS/nixpkgs/pull/168295 that attempted to revert this,
|
||||||
|
# https://github.com/NixOS/nixpkgs/issues/191124 and
|
||||||
|
# https://github.com/NixOS/nixos-search/issues/391 for what happens if you ignore
|
||||||
|
# this disclaimer.
|
||||||
|
check ? (x: true)
|
||||||
|
, # Merge a list of definitions together into a single value.
|
||||||
|
# This function is called with two arguments: the location of
|
||||||
|
# the option in the configuration as a list of strings
|
||||||
|
# (e.g. ["boot" "loader "grub" "enable"]), and a list of
|
||||||
|
# definition values and locations (e.g. [ { file = "/foo.nix";
|
||||||
|
# value = 1; } { file = "/bar.nix"; value = 2 } ]).
|
||||||
|
merge ? mergeDefaultOption
|
||||||
|
, # Whether this type has a value representing nothingness. If it does,
|
||||||
|
# this should be a value of the form { value = <the nothing value>; }
|
||||||
|
# If it doesn't, this should be {}
|
||||||
|
# This may be used when a value is required for `mkIf false`. This allows the extra laziness in e.g. `lazyAttrsOf`.
|
||||||
|
emptyValue ? {}
|
||||||
|
, # Return a flat list of sub-options. Used to generate
|
||||||
|
# documentation.
|
||||||
|
getSubOptions ? prefix: {}
|
||||||
|
, # List of modules if any, or null if none.
|
||||||
|
getSubModules ? null
|
||||||
|
, # Function for building the same option type with a different list of
|
||||||
|
# modules.
|
||||||
|
substSubModules ? m: null
|
||||||
|
, # Function that merge type declarations.
|
||||||
|
# internal, takes a functor as argument and returns the merged type.
|
||||||
|
# returning null means the type is not mergeable
|
||||||
|
typeMerge ? defaultTypeMerge functor
|
||||||
|
, # The type functor.
|
||||||
|
# internal, representation of the type as an attribute set.
|
||||||
|
# name: name of the type
|
||||||
|
# type: type function.
|
||||||
|
# wrapped: the type wrapped in case of compound types.
|
||||||
|
# payload: values of the type, two payloads of the same type must be
|
||||||
|
# combinable with the binOp binary operation.
|
||||||
|
# binOp: binary operation that merge two payloads of the same type.
|
||||||
|
functor ? defaultFunctor name
|
||||||
|
, # The deprecation message to display when this type is used by an option
|
||||||
|
# If null, the type isn't deprecated
|
||||||
|
deprecationMessage ? null
|
||||||
|
, # The types that occur in the definition of this type. This is used to
|
||||||
|
# issue deprecation warnings recursively. Can also be used to reuse
|
||||||
|
# nested types
|
||||||
|
nestedTypes ? {}
|
||||||
|
}:
|
||||||
|
{ _type = "option-type";
|
||||||
|
inherit
|
||||||
|
name check merge emptyValue getSubOptions getSubModules substSubModules
|
||||||
|
typeMerge functor deprecationMessage nestedTypes descriptionClass;
|
||||||
|
description = if description == null then name else description;
|
||||||
|
};
|
||||||
|
|
||||||
|
# optionDescriptionPhrase :: (str -> bool) -> optionType -> str
|
||||||
|
#
|
||||||
|
# Helper function for producing unambiguous but readable natural language
|
||||||
|
# descriptions of types.
|
||||||
|
#
|
||||||
|
# Parameters
|
||||||
|
#
|
||||||
|
# optionDescriptionPhase unparenthesize optionType
|
||||||
|
#
|
||||||
|
# `unparenthesize`: A function from descriptionClass string to boolean.
|
||||||
|
# It must return true when the class of phrase will fit unambiguously into
|
||||||
|
# the description of the caller.
|
||||||
|
#
|
||||||
|
# `optionType`: The option type to parenthesize or not.
|
||||||
|
# The option whose description we're returning.
|
||||||
|
#
|
||||||
|
# Return value
|
||||||
|
#
|
||||||
|
# The description of the `optionType`, with parentheses if there may be an
|
||||||
|
# ambiguity.
|
||||||
|
optionDescriptionPhrase = unparenthesize: t:
|
||||||
|
if unparenthesize (t.descriptionClass or null)
|
||||||
|
then t.description
|
||||||
|
else "(${t.description})";
|
||||||
|
|
||||||
|
# When adding new types don't forget to document them in
|
||||||
|
# nixos/doc/manual/development/option-types.xml!
|
||||||
|
types = rec {
|
||||||
|
/*
|
||||||
|
Can be anything.
|
||||||
|
|
||||||
|
Merge behavior: None; Merging is disabled.
|
||||||
|
|
||||||
|
*/
|
||||||
|
raw = mkOptionType rec {
|
||||||
|
name = "raw";
|
||||||
|
description = "raw value";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = value: true;
|
||||||
|
merge = mergeOneOption;
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
Can be anything.
|
||||||
|
|
||||||
|
Merge behavior: Custom Logic
|
||||||
|
*/
|
||||||
|
anything = mkOptionType {
|
||||||
|
name = "anything";
|
||||||
|
description = "anything";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = value: true;
|
||||||
|
merge = loc: defs:
|
||||||
|
let
|
||||||
|
getType = value:
|
||||||
|
if isAttrs value && isStringLike value
|
||||||
|
then "stringCoercibleSet"
|
||||||
|
else builtins.typeOf value;
|
||||||
|
|
||||||
|
# Returns the common type of all definitions, throws an error if they
|
||||||
|
# don't have the same type
|
||||||
|
commonType = foldl' (type: def:
|
||||||
|
if getType def.value == type
|
||||||
|
then type
|
||||||
|
else throw "The option `${showOption loc}' has conflicting option types in ${showFiles (getFiles defs)}"
|
||||||
|
) (getType (head defs).value) defs;
|
||||||
|
|
||||||
|
mergeFunction = {
|
||||||
|
# Recursively merge attribute sets
|
||||||
|
set = (attrsOf anything).merge;
|
||||||
|
# Safe and deterministic behavior for lists is to only accept one definition
|
||||||
|
# listOf only used to apply mkIf and co.
|
||||||
|
list =
|
||||||
|
if length defs > 1
|
||||||
|
then throw "The option `${showOption loc}' has conflicting definitions, in ${showFiles (getFiles defs)}."
|
||||||
|
else (listOf anything).merge;
|
||||||
|
# This is the type of packages, only accept a single definition
|
||||||
|
stringCoercibleSet = mergeOneOption;
|
||||||
|
lambda = loc: defs: arg: anything.merge
|
||||||
|
(loc ++ [ "<function body>" ])
|
||||||
|
(map (def: {
|
||||||
|
file = def.file;
|
||||||
|
value = def.value arg;
|
||||||
|
}) defs);
|
||||||
|
# Otherwise fall back to only allowing all equal definitions
|
||||||
|
}.${commonType} or mergeEqualOption;
|
||||||
|
in mergeFunction loc defs;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Can be anything.
|
||||||
|
|
||||||
|
Merge behavior: Default logic
|
||||||
|
*/
|
||||||
|
unspecified = mkOptionType {
|
||||||
|
name = "unspecified";
|
||||||
|
description = "unspecified value";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Allows Boolean values
|
||||||
|
|
||||||
|
Merge behavior: Enabled; see lib.mergeEqualOption;
|
||||||
|
*/
|
||||||
|
bool = mkOptionType {
|
||||||
|
name = "bool";
|
||||||
|
description = "boolean";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = isBool;
|
||||||
|
merge = mergeEqualOption;
|
||||||
|
};
|
||||||
|
|
||||||
|
int = mkOptionType {
|
||||||
|
name = "int";
|
||||||
|
description = "signed integer";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = isInt;
|
||||||
|
merge = mergeEqualOption;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Specialized subdomains of int
|
||||||
|
|
||||||
|
- ints.between
|
||||||
|
- ints.unsigned
|
||||||
|
- ints.u8
|
||||||
|
- ints.u16
|
||||||
|
- ints.u32
|
||||||
|
- ints.s8
|
||||||
|
- ints.s16
|
||||||
|
- ints.s32
|
||||||
|
|
||||||
|
|
||||||
|
Example:
|
||||||
|
(ints.between 0 100).check (-1)
|
||||||
|
=> false
|
||||||
|
(ints.between 0 100).check (101)
|
||||||
|
=> false
|
||||||
|
(ints.between 0 0).check 0
|
||||||
|
=> true
|
||||||
|
*/
|
||||||
|
ints =
|
||||||
|
let
|
||||||
|
betweenDesc = lowest: highest:
|
||||||
|
"${toString lowest} and ${toString highest} (both inclusive)";
|
||||||
|
between = lowest: highest:
|
||||||
|
assert lib.assertMsg (lowest <= highest)
|
||||||
|
"ints.between: lowest must be smaller than highest";
|
||||||
|
addCheck int (x: x >= lowest && x <= highest) // {
|
||||||
|
name = "intBetween";
|
||||||
|
description = "integer between ${betweenDesc lowest highest}";
|
||||||
|
};
|
||||||
|
ign = lowest: highest: name: docStart:
|
||||||
|
between lowest highest // {
|
||||||
|
inherit name;
|
||||||
|
description = docStart + "; between ${betweenDesc lowest highest}";
|
||||||
|
};
|
||||||
|
unsign = bit: range: ign 0 (range - 1)
|
||||||
|
"unsignedInt${toString bit}" "${toString bit} bit unsigned integer";
|
||||||
|
sign = bit: range: ign (0 - (range / 2)) (range / 2 - 1)
|
||||||
|
"signedInt${toString bit}" "${toString bit} bit signed integer";
|
||||||
|
|
||||||
|
in {
|
||||||
|
/* An int with a fixed range.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
(ints.between 0 100).check (-1)
|
||||||
|
=> false
|
||||||
|
(ints.between 0 100).check (101)
|
||||||
|
=> false
|
||||||
|
(ints.between 0 0).check 0
|
||||||
|
=> true
|
||||||
|
*/
|
||||||
|
inherit between;
|
||||||
|
|
||||||
|
unsigned = addCheck types.int (x: x >= 0) // {
|
||||||
|
name = "unsignedInt";
|
||||||
|
description = "unsigned integer, meaning >=0";
|
||||||
|
};
|
||||||
|
positive = addCheck types.int (x: x > 0) // {
|
||||||
|
name = "positiveInt";
|
||||||
|
description = "positive integer, meaning >0";
|
||||||
|
};
|
||||||
|
u8 = unsign 8 256;
|
||||||
|
u16 = unsign 16 65536;
|
||||||
|
# the biggest int Nix accepts is 2^63 - 1 (9223372036854775808)
|
||||||
|
# the smallest int Nix accepts is -2^63 (-9223372036854775807)
|
||||||
|
u32 = unsign 32 4294967296;
|
||||||
|
# u64 = unsign 64 18446744073709551616;
|
||||||
|
|
||||||
|
s8 = sign 8 256;
|
||||||
|
s16 = sign 16 65536;
|
||||||
|
s32 = sign 32 4294967296;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Port number can be unsigned 16 bit
|
||||||
|
|
||||||
|
from 0 to 65536
|
||||||
|
|
||||||
|
Alias of ints.u16 for a port number. -> See tye.ints for more infos.
|
||||||
|
*/
|
||||||
|
port = ints.u16;
|
||||||
|
|
||||||
|
/*
|
||||||
|
A Float number
|
||||||
|
|
||||||
|
For more information about validation see: lib.isFloat
|
||||||
|
|
||||||
|
Merge behavior: Enabled; see lib.mergeEqualOption
|
||||||
|
*/
|
||||||
|
float = mkOptionType {
|
||||||
|
name = "float";
|
||||||
|
description = "floating point number";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = isFloat;
|
||||||
|
merge = mergeEqualOption;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Can be either an Int or a Float
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
number = either int float;
|
||||||
|
|
||||||
|
numbers = let
|
||||||
|
betweenDesc = lowest: highest:
|
||||||
|
"${builtins.toJSON lowest} and ${builtins.toJSON highest} (both inclusive)";
|
||||||
|
in {
|
||||||
|
between = lowest: highest:
|
||||||
|
assert lib.assertMsg (lowest <= highest)
|
||||||
|
"numbers.between: lowest must be smaller than highest";
|
||||||
|
addCheck number (x: x >= lowest && x <= highest) // {
|
||||||
|
name = "numberBetween";
|
||||||
|
description = "integer or floating point number between ${betweenDesc lowest highest}";
|
||||||
|
};
|
||||||
|
|
||||||
|
nonnegative = addCheck number (x: x >= 0) // {
|
||||||
|
name = "numberNonnegative";
|
||||||
|
description = "nonnegative integer or floating point number, meaning >=0";
|
||||||
|
};
|
||||||
|
positive = addCheck number (x: x > 0) // {
|
||||||
|
name = "numberPositive";
|
||||||
|
description = "positive integer or floating point number, meaning >0";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
str = mkOptionType {
|
||||||
|
name = "str";
|
||||||
|
description = "string";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = isString;
|
||||||
|
merge = mergeEqualOption;
|
||||||
|
};
|
||||||
|
|
||||||
|
nonEmptyStr = mkOptionType {
|
||||||
|
name = "nonEmptyStr";
|
||||||
|
description = "non-empty string";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = x: str.check x && builtins.match "[ \t\n]*" x == null;
|
||||||
|
inherit (str) merge;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Allow a newline character at the end and trim it in the merge function.
|
||||||
|
singleLineStr =
|
||||||
|
let
|
||||||
|
inherit (strMatching "[^\n\r]*\n?") check merge;
|
||||||
|
in
|
||||||
|
mkOptionType {
|
||||||
|
name = "singleLineStr";
|
||||||
|
description = "(optionally newline-terminated) single-line string";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
inherit check;
|
||||||
|
merge = loc: defs:
|
||||||
|
lib.removeSuffix "\n" (merge loc defs);
|
||||||
|
};
|
||||||
|
|
||||||
|
strMatching = pattern: mkOptionType {
|
||||||
|
name = "strMatching ${escapeNixString pattern}";
|
||||||
|
description = "string matching the pattern ${pattern}";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = x: str.check x && builtins.match pattern x != null;
|
||||||
|
inherit (str) merge;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Merge multiple definitions by concatenating them (with the given
|
||||||
|
# separator between the values).
|
||||||
|
separatedString = sep: mkOptionType rec {
|
||||||
|
name = "separatedString";
|
||||||
|
description = if sep == ""
|
||||||
|
then "Concatenated string" # for types.string.
|
||||||
|
else "strings concatenated with ${builtins.toJSON sep}"
|
||||||
|
;
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = isString;
|
||||||
|
merge = loc: defs: concatStringsSep sep (getValues defs);
|
||||||
|
functor = (defaultFunctor name) // {
|
||||||
|
payload = sep;
|
||||||
|
binOp = sepLhs: sepRhs:
|
||||||
|
if sepLhs == sepRhs then sepLhs
|
||||||
|
else null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
lines = separatedString "\n";
|
||||||
|
commas = separatedString ",";
|
||||||
|
envVar = separatedString ":";
|
||||||
|
|
||||||
|
# Deprecated; should not be used because it quietly concatenates
|
||||||
|
# strings, which is usually not what you want.
|
||||||
|
string = separatedString "" // {
|
||||||
|
name = "string";
|
||||||
|
deprecationMessage = "See https://github.com/NixOS/nixpkgs/pull/66346 for better alternative types.";
|
||||||
|
};
|
||||||
|
|
||||||
|
passwdEntry = entryType: addCheck entryType (str: !(hasInfix ":" str || hasInfix "\n" str)) // {
|
||||||
|
name = "passwdEntry ${entryType.name}";
|
||||||
|
description = "${optionDescriptionPhrase (class: class == "noun") entryType}, not containing newlines or colons";
|
||||||
|
};
|
||||||
|
|
||||||
|
attrs = mkOptionType {
|
||||||
|
name = "attrs";
|
||||||
|
description = "attribute set";
|
||||||
|
check = isAttrs;
|
||||||
|
merge = loc: foldl' (res: def: res // def.value) {};
|
||||||
|
emptyValue = { value = {}; };
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
A package is a top-level store path (/nix/store/hash-name). This includes:
|
||||||
|
|
||||||
|
- derivations
|
||||||
|
- more generally, attribute sets with an `outPath` or `__toString` attribute
|
||||||
|
pointing to a store path, e.g. flake inputs
|
||||||
|
- strings with context, e.g. "${pkgs.foo}" or (toString pkgs.foo)
|
||||||
|
- hardcoded store path literals (/nix/store/hash-foo) or strings without context
|
||||||
|
("/nix/store/hash-foo"). These get a context added to them using builtins.storePath.
|
||||||
|
*/
|
||||||
|
package = mkOptionType {
|
||||||
|
name = "package";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = x: isDerivation x || isStorePath x;
|
||||||
|
merge = loc: defs:
|
||||||
|
let res = mergeOneOption loc defs;
|
||||||
|
in if builtins.isPath res || (builtins.isString res && ! builtins.hasContext res)
|
||||||
|
then toDerivation res
|
||||||
|
else res;
|
||||||
|
};
|
||||||
|
|
||||||
|
shellPackage = package // {
|
||||||
|
check = x: isDerivation x && hasAttr "shellPath" x;
|
||||||
|
};
|
||||||
|
|
||||||
|
path = mkOptionType {
|
||||||
|
name = "path";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = x: isStringLike x && builtins.substring 0 1 (toString x) == "/";
|
||||||
|
merge = mergeEqualOption;
|
||||||
|
};
|
||||||
|
|
||||||
|
listOf = elemType: mkOptionType rec {
|
||||||
|
name = "listOf";
|
||||||
|
description = "list of ${optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType}";
|
||||||
|
descriptionClass = "composite";
|
||||||
|
check = isList;
|
||||||
|
merge = loc: defs:
|
||||||
|
map (x: x.value) (filter (x: x ? value) (concatLists (imap1 (n: def:
|
||||||
|
imap1 (m: def':
|
||||||
|
(mergeDefinitions
|
||||||
|
(loc ++ ["[definition ${toString n}-entry ${toString m}]"])
|
||||||
|
elemType
|
||||||
|
[{ inherit (def) file; value = def'; }]
|
||||||
|
).optionalValue
|
||||||
|
) def.value
|
||||||
|
) defs)));
|
||||||
|
emptyValue = { value = []; };
|
||||||
|
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["*"]);
|
||||||
|
getSubModules = elemType.getSubModules;
|
||||||
|
substSubModules = m: listOf (elemType.substSubModules m);
|
||||||
|
functor = (defaultFunctor name) // { wrapped = elemType; };
|
||||||
|
nestedTypes.elemType = elemType;
|
||||||
|
};
|
||||||
|
|
||||||
|
nonEmptyListOf = elemType:
|
||||||
|
let list = addCheck (types.listOf elemType) (l: l != []);
|
||||||
|
in list // {
|
||||||
|
description = "non-empty ${optionDescriptionPhrase (class: class == "noun") list}";
|
||||||
|
emptyValue = { }; # no .value attr, meaning unset
|
||||||
|
};
|
||||||
|
|
||||||
|
attrsOf = elemType: mkOptionType rec {
|
||||||
|
name = "attrsOf";
|
||||||
|
description = "attribute set of ${optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType}";
|
||||||
|
descriptionClass = "composite";
|
||||||
|
check = isAttrs;
|
||||||
|
merge = loc: defs:
|
||||||
|
mapAttrs (n: v: v.value) (filterAttrs (n: v: v ? value) (zipAttrsWith (name: defs:
|
||||||
|
(mergeDefinitions (loc ++ [name]) elemType defs).optionalValue
|
||||||
|
)
|
||||||
|
# Push down position info.
|
||||||
|
(map (def: mapAttrs (n: v: { inherit (def) file; value = v; }) def.value) defs)));
|
||||||
|
emptyValue = { value = {}; };
|
||||||
|
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name>"]);
|
||||||
|
getSubModules = elemType.getSubModules;
|
||||||
|
substSubModules = m: attrsOf (elemType.substSubModules m);
|
||||||
|
functor = (defaultFunctor name) // { wrapped = elemType; };
|
||||||
|
nestedTypes.elemType = elemType;
|
||||||
|
};
|
||||||
|
|
||||||
|
# A version of attrsOf that's lazy in its values at the expense of
|
||||||
|
# conditional definitions not working properly. E.g. defining a value with
|
||||||
|
# `foo.attr = mkIf false 10`, then `foo ? attr == true`, whereas with
|
||||||
|
# attrsOf it would correctly be `false`. Accessing `foo.attr` would throw an
|
||||||
|
# error that it's not defined. Use only if conditional definitions don't make sense.
|
||||||
|
lazyAttrsOf = elemType: mkOptionType rec {
|
||||||
|
name = "lazyAttrsOf";
|
||||||
|
description = "lazy attribute set of ${optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType}";
|
||||||
|
descriptionClass = "composite";
|
||||||
|
check = isAttrs;
|
||||||
|
merge = loc: defs:
|
||||||
|
zipAttrsWith (name: defs:
|
||||||
|
let merged = mergeDefinitions (loc ++ [name]) elemType defs;
|
||||||
|
# mergedValue will trigger an appropriate error when accessed
|
||||||
|
in merged.optionalValue.value or elemType.emptyValue.value or merged.mergedValue
|
||||||
|
)
|
||||||
|
# Push down position info.
|
||||||
|
(map (def: mapAttrs (n: v: { inherit (def) file; value = v; }) def.value) defs);
|
||||||
|
emptyValue = { value = {}; };
|
||||||
|
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name>"]);
|
||||||
|
getSubModules = elemType.getSubModules;
|
||||||
|
substSubModules = m: lazyAttrsOf (elemType.substSubModules m);
|
||||||
|
functor = (defaultFunctor name) // { wrapped = elemType; };
|
||||||
|
nestedTypes.elemType = elemType;
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO: deprecate this in the future:
|
||||||
|
loaOf = elemType: types.attrsOf elemType // {
|
||||||
|
name = "loaOf";
|
||||||
|
deprecationMessage = "Mixing lists with attribute values is no longer"
|
||||||
|
+ " possible; please use `types.attrsOf` instead. See"
|
||||||
|
+ " https://github.com/NixOS/nixpkgs/issues/1800 for the motivation.";
|
||||||
|
nestedTypes.elemType = elemType;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Value of given type but with no merging (i.e. `uniq list`s are not concatenated).
|
||||||
|
uniq = elemType: mkOptionType rec {
|
||||||
|
name = "uniq";
|
||||||
|
inherit (elemType) description descriptionClass check;
|
||||||
|
merge = mergeOneOption;
|
||||||
|
emptyValue = elemType.emptyValue;
|
||||||
|
getSubOptions = elemType.getSubOptions;
|
||||||
|
getSubModules = elemType.getSubModules;
|
||||||
|
substSubModules = m: uniq (elemType.substSubModules m);
|
||||||
|
functor = (defaultFunctor name) // { wrapped = elemType; };
|
||||||
|
nestedTypes.elemType = elemType;
|
||||||
|
};
|
||||||
|
|
||||||
|
unique = { message }: type: mkOptionType rec {
|
||||||
|
name = "unique";
|
||||||
|
inherit (type) description descriptionClass check;
|
||||||
|
merge = mergeUniqueOption { inherit message; };
|
||||||
|
emptyValue = type.emptyValue;
|
||||||
|
getSubOptions = type.getSubOptions;
|
||||||
|
getSubModules = type.getSubModules;
|
||||||
|
substSubModules = m: uniq (type.substSubModules m);
|
||||||
|
functor = (defaultFunctor name) // { wrapped = type; };
|
||||||
|
nestedTypes.elemType = type;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Null or value of ...
|
||||||
|
nullOr = elemType: mkOptionType rec {
|
||||||
|
name = "nullOr";
|
||||||
|
description = "null or ${optionDescriptionPhrase (class: class == "noun" || class == "conjunction") elemType}";
|
||||||
|
descriptionClass = "conjunction";
|
||||||
|
check = x: x == null || elemType.check x;
|
||||||
|
merge = loc: defs:
|
||||||
|
let nrNulls = count (def: def.value == null) defs; in
|
||||||
|
if nrNulls == length defs then null
|
||||||
|
else if nrNulls != 0 then
|
||||||
|
throw "The option `${showOption loc}` is defined both null and not null, in ${showFiles (getFiles defs)}."
|
||||||
|
else elemType.merge loc defs;
|
||||||
|
emptyValue = { value = null; };
|
||||||
|
getSubOptions = elemType.getSubOptions;
|
||||||
|
getSubModules = elemType.getSubModules;
|
||||||
|
substSubModules = m: nullOr (elemType.substSubModules m);
|
||||||
|
functor = (defaultFunctor name) // { wrapped = elemType; };
|
||||||
|
nestedTypes.elemType = elemType;
|
||||||
|
};
|
||||||
|
|
||||||
|
functionTo = elemType: mkOptionType {
|
||||||
|
name = "functionTo";
|
||||||
|
description = "function that evaluates to a(n) ${optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType}";
|
||||||
|
descriptionClass = "composite";
|
||||||
|
check = isFunction;
|
||||||
|
merge = loc: defs:
|
||||||
|
fnArgs: (mergeDefinitions (loc ++ [ "<function body>" ]) elemType (map (fn: { inherit (fn) file; value = fn.value fnArgs; }) defs)).mergedValue;
|
||||||
|
getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "<function body>" ]);
|
||||||
|
getSubModules = elemType.getSubModules;
|
||||||
|
substSubModules = m: functionTo (elemType.substSubModules m);
|
||||||
|
functor = (defaultFunctor "functionTo") // { wrapped = elemType; };
|
||||||
|
nestedTypes.elemType = elemType;
|
||||||
|
};
|
||||||
|
|
||||||
|
# A submodule (like typed attribute set). See NixOS manual.
|
||||||
|
submodule = modules: submoduleWith {
|
||||||
|
shorthandOnlyDefinesConfig = true;
|
||||||
|
modules = toList modules;
|
||||||
|
};
|
||||||
|
|
||||||
|
# A module to be imported in some other part of the configuration.
|
||||||
|
deferredModule = deferredModuleWith { };
|
||||||
|
|
||||||
|
# A module to be imported in some other part of the configuration.
|
||||||
|
# `staticModules`' options will be added to the documentation, unlike
|
||||||
|
# options declared via `config`.
|
||||||
|
deferredModuleWith = attrs@{ staticModules ? [] }: mkOptionType {
|
||||||
|
name = "deferredModule";
|
||||||
|
description = "module";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = x: isAttrs x || isFunction x || path.check x;
|
||||||
|
merge = loc: defs: {
|
||||||
|
imports = staticModules ++ map (def: lib.setDefaultModuleLocation "${def.file}, via option ${showOption loc}" def.value) defs;
|
||||||
|
};
|
||||||
|
inherit (submoduleWith { modules = staticModules; })
|
||||||
|
getSubOptions
|
||||||
|
getSubModules;
|
||||||
|
substSubModules = m: deferredModuleWith (attrs // {
|
||||||
|
staticModules = m;
|
||||||
|
});
|
||||||
|
functor = defaultFunctor "deferredModuleWith" // {
|
||||||
|
type = types.deferredModuleWith;
|
||||||
|
payload = {
|
||||||
|
inherit staticModules;
|
||||||
|
};
|
||||||
|
binOp = lhs: rhs: {
|
||||||
|
staticModules = lhs.staticModules ++ rhs.staticModules;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# The type of a type!
|
||||||
|
optionType = mkOptionType {
|
||||||
|
name = "optionType";
|
||||||
|
description = "optionType";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = value: value._type or null == "option-type";
|
||||||
|
merge = loc: defs:
|
||||||
|
if length defs == 1
|
||||||
|
then (head defs).value
|
||||||
|
else let
|
||||||
|
# Prepares the type definitions for mergeOptionDecls, which
|
||||||
|
# annotates submodules types with file locations
|
||||||
|
optionModules = map ({ value, file }:
|
||||||
|
{
|
||||||
|
_file = file;
|
||||||
|
# There's no way to merge types directly from the module system,
|
||||||
|
# but we can cheat a bit by just declaring an option with the type
|
||||||
|
options = lib.mkOption {
|
||||||
|
type = value;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
) defs;
|
||||||
|
# Merges all the types into a single one, including submodule merging.
|
||||||
|
# This also propagates file information to all submodules
|
||||||
|
mergedOption = fixupOptionType loc (mergeOptionDecls loc optionModules);
|
||||||
|
in mergedOption.type;
|
||||||
|
};
|
||||||
|
|
||||||
|
submoduleWith =
|
||||||
|
{ modules
|
||||||
|
, specialArgs ? {}
|
||||||
|
, shorthandOnlyDefinesConfig ? false
|
||||||
|
, description ? null
|
||||||
|
}@attrs:
|
||||||
|
let
|
||||||
|
inherit (lib.modules) evalModules;
|
||||||
|
|
||||||
|
allModules = defs: map ({ value, file }:
|
||||||
|
if isAttrs value && shorthandOnlyDefinesConfig
|
||||||
|
then { _file = file; config = value; }
|
||||||
|
else { _file = file; imports = [ value ]; }
|
||||||
|
) defs;
|
||||||
|
|
||||||
|
base = evalModules {
|
||||||
|
inherit specialArgs;
|
||||||
|
modules = [{
|
||||||
|
# This is a work-around for the fact that some sub-modules,
|
||||||
|
# such as the one included in an attribute set, expects an "args"
|
||||||
|
# attribute to be given to the sub-module. As the option
|
||||||
|
# evaluation does not have any specific attribute name yet, we
|
||||||
|
# provide a default for the documentation and the freeform type.
|
||||||
|
#
|
||||||
|
# This is necessary as some option declaration might use the
|
||||||
|
# "name" attribute given as argument of the submodule and use it
|
||||||
|
# as the default of option declarations.
|
||||||
|
#
|
||||||
|
# We use lookalike unicode single angle quotation marks because
|
||||||
|
# of the docbook transformation the options receive. In all uses
|
||||||
|
# > and < wouldn't be encoded correctly so the encoded values
|
||||||
|
# would be used, and use of `<` and `>` would break the XML document.
|
||||||
|
# It shouldn't cause an issue since this is cosmetic for the manual.
|
||||||
|
_module.args.name = lib.mkOptionDefault "‹name›";
|
||||||
|
}] ++ modules;
|
||||||
|
};
|
||||||
|
|
||||||
|
freeformType = base._module.freeformType;
|
||||||
|
|
||||||
|
name = "submodule";
|
||||||
|
|
||||||
|
in
|
||||||
|
mkOptionType {
|
||||||
|
inherit name;
|
||||||
|
description =
|
||||||
|
if description != null then description
|
||||||
|
else freeformType.description or name;
|
||||||
|
check = x: isAttrs x || isFunction x || path.check x;
|
||||||
|
merge = loc: defs:
|
||||||
|
(base.extendModules {
|
||||||
|
modules = [ { _module.args.name = last loc; } ] ++ allModules defs;
|
||||||
|
prefix = loc;
|
||||||
|
}).config;
|
||||||
|
emptyValue = { value = {}; };
|
||||||
|
getSubOptions = prefix: (base.extendModules
|
||||||
|
{ inherit prefix; }).options // optionalAttrs (freeformType != null) {
|
||||||
|
# Expose the sub options of the freeform type. Note that the option
|
||||||
|
# discovery doesn't care about the attribute name used here, so this
|
||||||
|
# is just to avoid conflicts with potential options from the submodule
|
||||||
|
_freeformOptions = freeformType.getSubOptions prefix;
|
||||||
|
};
|
||||||
|
getSubModules = modules;
|
||||||
|
substSubModules = m: submoduleWith (attrs // {
|
||||||
|
modules = m;
|
||||||
|
});
|
||||||
|
nestedTypes = lib.optionalAttrs (freeformType != null) {
|
||||||
|
freeformType = freeformType;
|
||||||
|
};
|
||||||
|
functor = defaultFunctor name // {
|
||||||
|
type = types.submoduleWith;
|
||||||
|
payload = {
|
||||||
|
inherit modules specialArgs shorthandOnlyDefinesConfig description;
|
||||||
|
};
|
||||||
|
binOp = lhs: rhs: {
|
||||||
|
modules = lhs.modules ++ rhs.modules;
|
||||||
|
specialArgs =
|
||||||
|
let intersecting = builtins.intersectAttrs lhs.specialArgs rhs.specialArgs;
|
||||||
|
in if intersecting == {}
|
||||||
|
then lhs.specialArgs // rhs.specialArgs
|
||||||
|
else throw "A submoduleWith option is declared multiple times with the same specialArgs \"${toString (attrNames intersecting)}\"";
|
||||||
|
shorthandOnlyDefinesConfig =
|
||||||
|
if lhs.shorthandOnlyDefinesConfig == null
|
||||||
|
then rhs.shorthandOnlyDefinesConfig
|
||||||
|
else if rhs.shorthandOnlyDefinesConfig == null
|
||||||
|
then lhs.shorthandOnlyDefinesConfig
|
||||||
|
else if lhs.shorthandOnlyDefinesConfig == rhs.shorthandOnlyDefinesConfig
|
||||||
|
then lhs.shorthandOnlyDefinesConfig
|
||||||
|
else throw "A submoduleWith option is declared multiple times with conflicting shorthandOnlyDefinesConfig values";
|
||||||
|
description =
|
||||||
|
if lhs.description == null
|
||||||
|
then rhs.description
|
||||||
|
else if rhs.description == null
|
||||||
|
then lhs.description
|
||||||
|
else if lhs.description == rhs.description
|
||||||
|
then lhs.description
|
||||||
|
else throw "A submoduleWith option is declared multiple times with conflicting descriptions";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# A value from a set of allowed ones.
|
||||||
|
enum = values:
|
||||||
|
let
|
||||||
|
inherit (lib.lists) unique;
|
||||||
|
show = v:
|
||||||
|
if builtins.isString v then ''"${v}"''
|
||||||
|
else if builtins.isInt v then builtins.toString v
|
||||||
|
else if builtins.isBool v then boolToString v
|
||||||
|
else ''<${builtins.typeOf v}>'';
|
||||||
|
in
|
||||||
|
mkOptionType rec {
|
||||||
|
name = "enum";
|
||||||
|
description =
|
||||||
|
# Length 0 or 1 enums may occur in a design pattern with type merging
|
||||||
|
# where an "interface" module declares an empty enum and other modules
|
||||||
|
# provide implementations, each extending the enum with their own
|
||||||
|
# identifier.
|
||||||
|
if values == [] then
|
||||||
|
"impossible (empty enum)"
|
||||||
|
else if builtins.length values == 1 then
|
||||||
|
"value ${show (builtins.head values)} (singular enum)"
|
||||||
|
else
|
||||||
|
"one of ${concatMapStringsSep ", " show values}";
|
||||||
|
descriptionClass =
|
||||||
|
if builtins.length values < 2
|
||||||
|
then "noun"
|
||||||
|
else "conjunction";
|
||||||
|
check = flip elem values;
|
||||||
|
merge = mergeEqualOption;
|
||||||
|
functor = (defaultFunctor name) // { payload = values; binOp = a: b: unique (a ++ b); };
|
||||||
|
};
|
||||||
|
|
||||||
|
# Either value of type `t1` or `t2`.
|
||||||
|
either = t1: t2: mkOptionType rec {
|
||||||
|
name = "either";
|
||||||
|
description = "${optionDescriptionPhrase (class: class == "noun" || class == "conjunction") t1} or ${optionDescriptionPhrase (class: class == "noun" || class == "conjunction" || class == "composite") t2}";
|
||||||
|
descriptionClass = "conjunction";
|
||||||
|
check = x: t1.check x || t2.check x;
|
||||||
|
merge = loc: defs:
|
||||||
|
let
|
||||||
|
defList = map (d: d.value) defs;
|
||||||
|
in
|
||||||
|
if all (x: t1.check x) defList
|
||||||
|
then t1.merge loc defs
|
||||||
|
else if all (x: t2.check x) defList
|
||||||
|
then t2.merge loc defs
|
||||||
|
else mergeOneOption loc defs;
|
||||||
|
typeMerge = f':
|
||||||
|
let mt1 = t1.typeMerge (elemAt f'.wrapped 0).functor;
|
||||||
|
mt2 = t2.typeMerge (elemAt f'.wrapped 1).functor;
|
||||||
|
in
|
||||||
|
if (name == f'.name) && (mt1 != null) && (mt2 != null)
|
||||||
|
then functor.type mt1 mt2
|
||||||
|
else null;
|
||||||
|
functor = (defaultFunctor name) // { wrapped = [ t1 t2 ]; };
|
||||||
|
nestedTypes.left = t1;
|
||||||
|
nestedTypes.right = t2;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Any of the types in the given list
|
||||||
|
oneOf = ts:
|
||||||
|
let
|
||||||
|
head' = if ts == [] then throw "types.oneOf needs to get at least one type in its argument" else head ts;
|
||||||
|
tail' = tail ts;
|
||||||
|
in foldl' either head' tail';
|
||||||
|
|
||||||
|
# Either value of type `coercedType` or `finalType`, the former is
|
||||||
|
# converted to `finalType` using `coerceFunc`.
|
||||||
|
coercedTo = coercedType: coerceFunc: finalType:
|
||||||
|
assert lib.assertMsg (coercedType.getSubModules == null)
|
||||||
|
"coercedTo: coercedType must not have submodules (it’s a ${
|
||||||
|
coercedType.description})";
|
||||||
|
mkOptionType rec {
|
||||||
|
name = "coercedTo";
|
||||||
|
description = "${optionDescriptionPhrase (class: class == "noun") finalType} or ${optionDescriptionPhrase (class: class == "noun") coercedType} convertible to it";
|
||||||
|
check = x: (coercedType.check x && finalType.check (coerceFunc x)) || finalType.check x;
|
||||||
|
merge = loc: defs:
|
||||||
|
let
|
||||||
|
coerceVal = val:
|
||||||
|
if coercedType.check val then coerceFunc val
|
||||||
|
else val;
|
||||||
|
in finalType.merge loc (map (def: def // { value = coerceVal def.value; }) defs);
|
||||||
|
emptyValue = finalType.emptyValue;
|
||||||
|
getSubOptions = finalType.getSubOptions;
|
||||||
|
getSubModules = finalType.getSubModules;
|
||||||
|
substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m);
|
||||||
|
typeMerge = t1: t2: null;
|
||||||
|
functor = (defaultFunctor name) // { wrapped = finalType; };
|
||||||
|
nestedTypes.coercedType = coercedType;
|
||||||
|
nestedTypes.finalType = finalType;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Augment the given type with an additional type check function.
|
||||||
|
addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; };
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
in outer_types // outer_types.types
|
@ -1 +0,0 @@
|
|||||||
x86_64-linux
|
|
57
projects.toml
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# projects.toml file describing inputs for dream2nix
|
||||||
|
#
|
||||||
|
# To re-generate this file, run:
|
||||||
|
# nix run .#detect-projects $source
|
||||||
|
# ... where `$source` points to the source of your project.
|
||||||
|
#
|
||||||
|
# If the local flake is unavailable, alternatively execute the app from the
|
||||||
|
# upstream dream2nix flake:
|
||||||
|
# nix run github:nix-community/dream2nix#detect-projects $source
|
||||||
|
|
||||||
|
[noogle]
|
||||||
|
name = "noogle"
|
||||||
|
relPath = "website"
|
||||||
|
subsystem = "nodejs"
|
||||||
|
translator = "package-lock"
|
||||||
|
builder = "strict-builder"
|
||||||
|
translators = ["package-lock", "package-json"]
|
||||||
|
|
||||||
|
[noogle.subsystemInfo]
|
||||||
|
nodejs = 18
|
||||||
|
|
||||||
|
[indexer]
|
||||||
|
name = "indexer"
|
||||||
|
relPath = "indexer"
|
||||||
|
subsystem = "rust"
|
||||||
|
translator = "cargo-lock"
|
||||||
|
translators = ["cargo-lock", "cargo-toml"]
|
||||||
|
|
||||||
|
[indexer.subsystemInfo]
|
||||||
|
workspaceMembers = []
|
||||||
|
[[indexer.subsystemInfo.crates]]
|
||||||
|
name = "indexer"
|
||||||
|
relPath = "indexer"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[builtins-data]
|
||||||
|
name = "builtins-data"
|
||||||
|
relPath = "scripts"
|
||||||
|
subsystem = "nodejs"
|
||||||
|
translator = "package-lock"
|
||||||
|
builder = "strict-builder"
|
||||||
|
translators = ["package-lock", "package-json"]
|
||||||
|
|
||||||
|
[builtins-data.subsystemInfo]
|
||||||
|
nodejs = 18
|
||||||
|
|
||||||
|
|
||||||
|
[tests]
|
||||||
|
name = "tests"
|
||||||
|
relPath = "tests"
|
||||||
|
subsystem = "nodejs"
|
||||||
|
translator = "package-lock"
|
||||||
|
builder = "strict-builder"
|
||||||
|
translators = ["package-lock", "package-json"]
|
||||||
|
|
||||||
|
[tests.subsystemInfo]
|
||||||
|
nodejs = 18
|
2
scripts/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
data.json
|
||||||
|
node_modules
|
114
scripts/data/builtins-names.json
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
[
|
||||||
|
"abort",
|
||||||
|
"add",
|
||||||
|
"addErrorContext",
|
||||||
|
"all",
|
||||||
|
"any",
|
||||||
|
"appendContext",
|
||||||
|
"attrNames",
|
||||||
|
"attrValues",
|
||||||
|
"baseNameOf",
|
||||||
|
"bitAnd",
|
||||||
|
"bitOr",
|
||||||
|
"bitXor",
|
||||||
|
"break",
|
||||||
|
"builtins",
|
||||||
|
"catAttrs",
|
||||||
|
"ceil",
|
||||||
|
"compareVersions",
|
||||||
|
"concatLists",
|
||||||
|
"concatMap",
|
||||||
|
"concatStringsSep",
|
||||||
|
"currentSystem",
|
||||||
|
"currentTime",
|
||||||
|
"deepSeq",
|
||||||
|
"derivation",
|
||||||
|
"derivationStrict",
|
||||||
|
"dirOf",
|
||||||
|
"div",
|
||||||
|
"elem",
|
||||||
|
"elemAt",
|
||||||
|
"false",
|
||||||
|
"fetchGit",
|
||||||
|
"fetchMercurial",
|
||||||
|
"fetchTarball",
|
||||||
|
"fetchTree",
|
||||||
|
"fetchurl",
|
||||||
|
"filter",
|
||||||
|
"filterSource",
|
||||||
|
"findFile",
|
||||||
|
"floor",
|
||||||
|
"foldl'",
|
||||||
|
"fromJSON",
|
||||||
|
"fromTOML",
|
||||||
|
"functionArgs",
|
||||||
|
"genList",
|
||||||
|
"genericClosure",
|
||||||
|
"getAttr",
|
||||||
|
"getContext",
|
||||||
|
"getEnv",
|
||||||
|
"getFlake",
|
||||||
|
"groupBy",
|
||||||
|
"hasAttr",
|
||||||
|
"hasContext",
|
||||||
|
"hashFile",
|
||||||
|
"hashString",
|
||||||
|
"head",
|
||||||
|
"import",
|
||||||
|
"intersectAttrs",
|
||||||
|
"isAttrs",
|
||||||
|
"isBool",
|
||||||
|
"isFloat",
|
||||||
|
"isFunction",
|
||||||
|
"isInt",
|
||||||
|
"isList",
|
||||||
|
"isNull",
|
||||||
|
"isPath",
|
||||||
|
"isString",
|
||||||
|
"langVersion",
|
||||||
|
"length",
|
||||||
|
"lessThan",
|
||||||
|
"listToAttrs",
|
||||||
|
"map",
|
||||||
|
"mapAttrs",
|
||||||
|
"match",
|
||||||
|
"mul",
|
||||||
|
"nixPath",
|
||||||
|
"nixVersion",
|
||||||
|
"null",
|
||||||
|
"parseDrvName",
|
||||||
|
"partition",
|
||||||
|
"path",
|
||||||
|
"pathExists",
|
||||||
|
"placeholder",
|
||||||
|
"readDir",
|
||||||
|
"readFile",
|
||||||
|
"removeAttrs",
|
||||||
|
"replaceStrings",
|
||||||
|
"scopedImport",
|
||||||
|
"seq",
|
||||||
|
"sort",
|
||||||
|
"split",
|
||||||
|
"splitVersion",
|
||||||
|
"storeDir",
|
||||||
|
"storePath",
|
||||||
|
"stringLength",
|
||||||
|
"sub",
|
||||||
|
"substring",
|
||||||
|
"tail",
|
||||||
|
"throw",
|
||||||
|
"toFile",
|
||||||
|
"toJSON",
|
||||||
|
"toPath",
|
||||||
|
"toString",
|
||||||
|
"toXML",
|
||||||
|
"trace",
|
||||||
|
"traceVerbose",
|
||||||
|
"true",
|
||||||
|
"tryEval",
|
||||||
|
"typeOf",
|
||||||
|
"unsafeDiscardOutputDependency",
|
||||||
|
"unsafeDiscardStringContext",
|
||||||
|
"unsafeGetAttrPos",
|
||||||
|
"zipAttrsWith"
|
||||||
|
]
|
@ -108,5 +108,9 @@
|
|||||||
"typeOf": { "fn_type": "typeOf :: a -> String" },
|
"typeOf": { "fn_type": "typeOf :: a -> String" },
|
||||||
"zipAttrsWith": {
|
"zipAttrsWith": {
|
||||||
"fn_type": "zipAttrsWith :: (String -> [a] ) -> [a] -> AttrSet"
|
"fn_type": "zipAttrsWith :: (String -> [a] ) -> [a] -> AttrSet"
|
||||||
|
},
|
||||||
|
|
||||||
|
"fromTOML": {
|
||||||
|
"fn_type": "fromTOML :: String -> { Any }"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
32
scripts/data/fromTOML.md
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Parse a TOML-configuration from String
|
||||||
|
|
||||||
|
```
|
||||||
|
builtins.fromTOML ''
|
||||||
|
# Toplevel
|
||||||
|
foo = "bar"
|
||||||
|
|
||||||
|
# Simple Attrset
|
||||||
|
[set]
|
||||||
|
info = "foobar"
|
||||||
|
|
||||||
|
# Nested Attrset
|
||||||
|
[set.nested]
|
||||||
|
meta = 42
|
||||||
|
''
|
||||||
|
->
|
||||||
|
{
|
||||||
|
foo = "bar";
|
||||||
|
set = {
|
||||||
|
info = "foobar";
|
||||||
|
nested = {
|
||||||
|
meta = 42;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Also works nicely with `readFile`:
|
||||||
|
|
||||||
|
```
|
||||||
|
builtins.fromTOML (builtins.readFile ./config.toml)
|
||||||
|
```
|
47
scripts/data/more.json
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"addErrorContext": {
|
||||||
|
"args": ["s", "c"],
|
||||||
|
"arity": 2,
|
||||||
|
"doc": ""
|
||||||
|
},
|
||||||
|
"appendContext": {
|
||||||
|
"args": ["s", "c"],
|
||||||
|
"arity": 2,
|
||||||
|
"doc": ""
|
||||||
|
},
|
||||||
|
"builtins": {
|
||||||
|
"args": [],
|
||||||
|
"arity": 0,
|
||||||
|
"doc": "The set `builtins` contains all the built-in functions and values.\nYou can use `builtins` to test for the availability of features in\nthe Nix installation, e.g.,\n\n```nix\nif builtins ? getEnv then builtins.getEnv \"PATH\" else \"\"\n```\n\nThis allows a Nix expression to fall back gracefully on older Nix\ninstallations that don’t have the desired built-in function."
|
||||||
|
},
|
||||||
|
"currentSystem": {
|
||||||
|
"args": [],
|
||||||
|
"arity": 0,
|
||||||
|
"doc": "The built-in value `currentSystem` evaluates to the Nix platform\nidentifier for the Nix installation on which the expression is being\nevaluated, such as `\"i686-linux\"` or `\"x86_64-darwin\"`."
|
||||||
|
},
|
||||||
|
"currentTime": {
|
||||||
|
"args": [],
|
||||||
|
"arity": 0,
|
||||||
|
"doc": "The built-in value `currentSystem` evaluates to the current seconds since Jan 01 1970. (UTC)."
|
||||||
|
},
|
||||||
|
"false": {
|
||||||
|
"args": [],
|
||||||
|
"arity": 0,
|
||||||
|
"doc": "The built-in boolean value `false`."
|
||||||
|
},
|
||||||
|
"true": {
|
||||||
|
"args": [],
|
||||||
|
"arity": 0,
|
||||||
|
"doc": "The built-in boolean value `true`."
|
||||||
|
},
|
||||||
|
"null": {
|
||||||
|
"args": [],
|
||||||
|
"arity": 0,
|
||||||
|
"doc": "The built-in value `null`."
|
||||||
|
},
|
||||||
|
"fromTOML": {
|
||||||
|
"args": ["s"],
|
||||||
|
"arity": 1,
|
||||||
|
"doc": "# Parse a TOML-configuration from String\n\n```\nbuiltins.fromTOML ''\n# Toplevel\nfoo = \"bar\"\n\n# Simple Attrset\n[set]\ninfo = \"foobar\"\n\n# Nested Attrset\n[set.nested]\nmeta = 42\n''\n-> \n{\n foo = \"bar\";\n set = {\n info = \"foobar\";\n nested = {\n meta = 42;\n };\n };\n}\n```\n\nAlso works nicely with `readFile`:\n\n```\nbuiltins.fromTOML (builtins.readFile ./config.toml)\n```\n"
|
||||||
|
}
|
||||||
|
}
|
76
scripts/make-builtins.js
Normal file → Executable file
@ -1,25 +1,59 @@
|
|||||||
const builtins = require("./data/builtins.json");
|
const builtins = require("./data/builtins.json");
|
||||||
|
const names = require("./data/builtins-names.json");
|
||||||
const types = require("./data/builtins.types.json");
|
const types = require("./data/builtins.types.json");
|
||||||
const derivation = require("./data/derivation.json");
|
|
||||||
builtins["derivation"] = derivation.derivation;
|
|
||||||
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const info = Object.entries(builtins).map(([name, meta]) => {
|
const { exit } = require("process");
|
||||||
const fn_type = types[name]?.fn_type || null;
|
|
||||||
const { args, arity, doc } = meta;
|
const { derivation } = require("./data/derivation.json");
|
||||||
return {
|
|
||||||
id: `builtins.${name}`,
|
const more = require("./data/more.json");
|
||||||
category: "builtins",
|
|
||||||
fn_type,
|
builtins["derivation"] = derivation;
|
||||||
name,
|
|
||||||
description: [
|
Object.entries(more).forEach((e) => {
|
||||||
`takes ${arity} arguments: __\`${args.join("` `")}\`__ \n`,
|
const [name, meta] = e;
|
||||||
`${doc}\n`,
|
builtins[name] = meta;
|
||||||
],
|
|
||||||
};
|
|
||||||
});
|
|
||||||
fs.writeFile("./models/data/builtins.json", JSON.stringify(info), (err) => {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const DATA_PATH = process.argv.length >= 3 && process.argv[2];
|
||||||
|
|
||||||
|
if (!DATA_PATH) {
|
||||||
|
console.error("argument OUT_PATH is not set");
|
||||||
|
console.info("usage: node make-builtins.js <OUT_PATH>");
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
let leftover = names;
|
||||||
|
const info = Object.entries(builtins).map(([name, meta]) => {
|
||||||
|
leftover = leftover.filter((e) => e !== name);
|
||||||
|
const fn_type = types[name]?.fn_type || null;
|
||||||
|
const { args, arity, doc } = meta;
|
||||||
|
console.log(
|
||||||
|
"arity:" +
|
||||||
|
`${
|
||||||
|
arity > 0
|
||||||
|
? `takes ${arity} arguments: __\`${args.join("` `")}\`__ \n`
|
||||||
|
: ""
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
id: `builtins.${name}`,
|
||||||
|
category: "builtins",
|
||||||
|
fn_type,
|
||||||
|
name,
|
||||||
|
description: [
|
||||||
|
`${
|
||||||
|
arity > 0
|
||||||
|
? `takes ${arity} arguments: __\`${args.join("` `")}\`__ \n`
|
||||||
|
: ""
|
||||||
|
}`,
|
||||||
|
`${doc}\n`,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
console.log({ leftover });
|
||||||
|
fs.writeFile(`${DATA_PATH}/data.json`, JSON.stringify(info), (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
11
scripts/package.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "builtins-data",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "make-builtins.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "node ./make-builtins.js ./"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
3
tests/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
node_modules
|
||||||
|
data/*
|
6919
tests/__snapshots__/data.test.js.snap
Normal file
13
tests/data.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import libData from "./data/lib.json";
|
||||||
|
import trivialBuilders from "./data/trivial-builders.json";
|
||||||
|
import builtins from "./data/builtins.json";
|
||||||
|
|
||||||
|
it("has not changed lib data", () => {
|
||||||
|
expect(libData).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
it("has not changed trivial-builders data", () => {
|
||||||
|
expect(trivialBuilders).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
it("has not changed builtins data", () => {
|
||||||
|
expect(builtins).toMatchSnapshot();
|
||||||
|
});
|
10
tests/jest.config.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/** @type {import('jest').Config} */
|
||||||
|
|
||||||
|
import { defaults } from "jest-config";
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
...defaults,
|
||||||
|
// transform: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
3434
tests/package-lock.json
generated
Normal file
15
tests/package.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "tests",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"module": "index.js",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"jest": "^29.4.3"
|
||||||
|
}
|
||||||
|
}
|
44
website/.gitignore
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
node_modules
|
||||||
|
.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
coverage
|
||||||
|
/models/data/*
|
||||||
|
!/models/data/index.ts
|
||||||
|
|
||||||
|
# nix
|
||||||
|
.direnv/
|
||||||
|
|
||||||
|
|
||||||
|
# next.js
|
||||||
|
/.next/
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
result
|
||||||
|
result-*
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env*.local
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
next-env.d.ts
|
@ -15,10 +15,10 @@ export const CodeHighlight = (props: CodeHighlightProps) => {
|
|||||||
const { theme, code, lang, background } = props;
|
const { theme, code, lang, background } = props;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (theme === "dark") {
|
if (theme === "dark") {
|
||||||
// @ts-ignore - dont check type of css module
|
// @ts-ignore - don't check type of css module
|
||||||
import("highlight.js/styles/github-dark.css");
|
import("highlight.js/styles/github-dark.css");
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore - dont check type of css module
|
// @ts-ignore - don't check type of css module
|
||||||
import("highlight.js/styles/github.css");
|
import("highlight.js/styles/github.css");
|
||||||
}
|
}
|
||||||
}, [theme]);
|
}, [theme]);
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "nextapp",
|
"name": "noogle",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |