From 55f0b414de5e1f46ac2764725bb07bd37f63c9b2 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 25 Jan 2023 15:54:44 +0100 Subject: [PATCH 1/4] add pre-commit checks (#16) --- .gitignore | 1 + README.md | 96 +++++++++++++++--------- components/functionItem/functionItem.tsx | 11 +-- components/searchInput/searchInput.tsx | 3 +- flake.lock | 95 ++++++++++++++++++++++- flake.nix | 39 +++++++--- tsconfig.json | 3 +- 7 files changed, 190 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index 23eee51..4588e2d 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ yarn-error.log* # local env files .env*.local +.pre-commit-config.yaml # vercel .vercel diff --git a/README.md b/README.md index 4ad302e..9a07355 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,79 @@ +# [Noogle](https://noogle.dev) + ![Website](https://img.shields.io/website?down_message=noogle.dev&up_message=noogle.dev&url=https%3A%2F%2Fnoogle.dev) ![GitHub top language](https://img.shields.io/github/languages/top/hsjobeki/noogle) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/hsjobeki/noogle/main.yml) +![built-with-dream2nix](https://img.shields.io/badge/built%20with-dream2nix-blue) -# [Noogle](https://noogle.dev) +Noogle is a Nix API search engine. It allows you to search functions based on +their types and other attributes in `nix` projects. In `nixpkgs` especially +the `builtins` and `lib` attributes. -Noogle is a Nix API search engine. It allows you to search functions based on their types and other attributes in `nix` projects. In `nixpkgs` especially the `builtins` and `lib` attributes. +## Current Features -- Beginners-friendly search for nix and nix-related functions -- Expert search with directly typing type signatures -- Search functions based on: - - type - - signature +- [x] Beginners-friendly search for nix and nix-related functions +- [x] Search by **type** signatures +- [x] Sorted by relevance based on: + - id - name -- tree-search from one type to another - -## How it works + - category + - description + - example +- [ ] tree-search from one type to another +- [ ] functions from external libraries and nix frameworks -### Indexers: +## Available data -Data collections need to be up-to-date -Those collections are then combined and dumped somewhere (db / json) +Currently there are the following subsets of nix functions available. -For the indexing i currently use: +- nix/**builtins** +- nixpkgs/**lib** +- nixpkgs/build-support/**trivial-builders** -- Nixdoc (a fork) to collect nixpkgs.lib informations -- nix __dump-builtins + builtins-types.json for the nix builtins +### Search -As some parts of nix already have nixos modules their input/output can be discovered. I still lack some tool to integrate that into noogle. +- types are parsed and interpreted +- text search, looks in all metadata fields for an **exact match** word +or character sequence. +Noogle does not offer elastic search yet. And it remains open if it ever will. -### Search: +> If you have a function/set that you would like to find here, +> don't hesitate to file an issue. -- haskell-like types are parsed and splitted between input and ouput -- text search, looks in all metadata fields for an exact matching word or character sequence. I dont have elastic search yet. - -# View the prototype [here](https://noogle.dev) +**View the prototype [here](https://noogle.dev)** ## We need your help / what is missing -- Parsing `Types:` into a real type signature tree -- Upstream missing type informations (like in /lib/attrsets.nix) -- Write type signatures for the `builtins` in json -- Add path, where each function can be imported from. e.g. `lib.makeOverridable` or `lib.customisation.makeOverridable` (it is available in both sets) -- Website - - improve share / social interactions - - Add filter by tags e.g. lib.lists - - Prepare for scaling up: Either use api or use indexedDB with WebAssembly for complete offline usage? - - Mobile optimization for reading on the go -- Clean up / enhance my nixdoc fork. - - Make the `sloppy` parser more error resistant - - Some valueable information can be used from the rnix AST ? +### Extend available function + +Currently there is only a limited set of data. + +Because nixpkgs is very inconsistently documented it is +really hard to extend the scope. + +So if you want to help noogle, we must improve nixpkgs itself. + +- [ ] Parsing `Types:` into a real type signature tree +- [ ] Fix: line beginnings that include Asterisk (*) : Is interpreted as List-Markdown +- [x] Upstream missing type informations (like in /lib/attrsets.nix) +- [x] Write type signatures for the `builtins` in json +- [ ] Add path, where each function can be imported from. + +e.g. `lib.makeOverridable` or `lib.customisation.makeOverridable` +it is available in both sets + +### Website + +- [x] improve share (deeplinks) +- [ ] social interactions +- [ ] Add filter by tags e.g. lib.lists +- [ ] Prepare for scaling up (we expect more users) +- [x] Mobile optimization for reading on the go + +## Nixdoc / Indexer (fork) + +- [ ] Parse types directly while also parsing comments +- [ ] Extend the scope, so that is can parse more comments ## Contribute @@ -62,4 +87,5 @@ Contributions are very welcome just file a PR or issue `nix develop` -This command creates the node_modules folder with all needed dependencies based on dream2nix. +This command creates the node_modules folder +with all needed dependencies based on dream2nix. diff --git a/components/functionItem/functionItem.tsx b/components/functionItem/functionItem.tsx index 83cd44b..db95316 100644 --- a/components/functionItem/functionItem.tsx +++ b/components/functionItem/functionItem.tsx @@ -1,5 +1,4 @@ import { - Box, IconButton, ListItemText, Paper, @@ -9,15 +8,10 @@ import { Typography, } from "@mui/material"; import { useMemo } from "react"; -import { DocItem, NixType } from "../../models/nix"; +import { DocItem } from "../../models/nix"; import { Preview } from "../preview/preview"; -import StarIcon from "@mui/icons-material/Star"; import ShareIcon from "@mui/icons-material/Share"; -import { useLocalStorage } from "usehooks-ts"; import { useSnackbar } from "notistack"; -import StarRateIcon from "@mui/icons-material/StarRate"; -import StarBorderIcon from "@mui/icons-material/StarBorder"; -import { Key } from "@mui/icons-material"; interface FunctionItemProps { selected: boolean; @@ -25,10 +19,9 @@ interface FunctionItemProps { docItem: DocItem; handleClose: () => void; } -const getKey = (item: DocItem) => `${item.category}/${item.name}`; export default function FunctionItem(props: FunctionItemProps) { - const { name, docItem, selected, handleClose } = props; + const { docItem, selected, handleClose } = props; const { fn_type, category, description, id } = docItem; const { enqueueSnackbar } = useSnackbar(); const descriptionPreview = useMemo(() => { diff --git a/components/searchInput/searchInput.tsx b/components/searchInput/searchInput.tsx index 7eb3559..52ebc32 100644 --- a/components/searchInput/searchInput.tsx +++ b/components/searchInput/searchInput.tsx @@ -3,12 +3,11 @@ import Paper from "@mui/material/Paper"; import InputBase from "@mui/material/InputBase"; import IconButton from "@mui/material/IconButton"; import ClearIcon from "@mui/icons-material/Clear"; -import { Box, debounce, Grid, Tooltip, Typography } from "@mui/material"; +import { Box, debounce, Grid, Typography } from "@mui/material"; import ChevronRightIcon from "@mui/icons-material/ChevronRight"; import { NixType, nixTypes } from "../../models/nix"; import SearchIcon from "@mui/icons-material/Search"; import { usePageContext } from "../pageContext"; -import { initialPageState } from "../../models/internals"; import { SelectOption } from "../selectOption"; export type Filter = { from: NixType; to: NixType }; diff --git a/flake.lock b/flake.lock index e9df65a..ab1de49 100644 --- a/flake.lock +++ b/flake.lock @@ -125,6 +125,22 @@ "type": "github" } }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" @@ -173,6 +189,21 @@ "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": { "flake": false, "locked": { @@ -205,6 +236,27 @@ "url": "https://gitlab.haskell.org/bgamari/ghc-utils" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "gomod2nix": { "flake": false, "locked": { @@ -309,6 +361,22 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1673800717, + "narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1673027386, @@ -395,11 +463,36 @@ "type": "github" } }, + "pre-commit-hooks_2": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1674550893, + "narHash": "sha256-HXI8AB96PP7UZ7iPANACXM8qc9eMz0ljxBEDM8JJKhY=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "7bdf85f6bbef581eb687838d19f2b35a4c9d77f0", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "dream2nix": "dream2nix", "nixdoc-fork": "nixdoc-fork", - "nixpkgs": "nixpkgs_4" + "nixpkgs": "nixpkgs_4", + "pre-commit-hooks": "pre-commit-hooks_2" } }, "rust-analyzer-src": { diff --git a/flake.nix b/flake.nix index 856b75f..a55beef 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,18 @@ { - inputs.dream2nix.url = "github:nix-community/dream2nix"; - inputs.nixdoc-fork.url = "github:hsjobeki/nixdoc"; - outputs = {self, nixpkgs,...}@inp: - let - system = "x86_64-linux"; - pkgs = inp.nixpkgs.legacyPackages.${system}; - inherit (builtins.fromJSON (builtins.readFile ./package.json)) name; - in + inputs = { + dream2nix.url = "github:nix-community/dream2nix"; + nixdoc-fork.url = "github:hsjobeki/nixdoc"; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + outputs = { self, nixpkgs, pre-commit-hooks, ... }@inp: + let + system = "x86_64-linux"; + pkgs = inp.nixpkgs.legacyPackages.${system}; + inherit (builtins.fromJSON (builtins.readFile ./package.json)) name; + in (inp.dream2nix.lib.makeFlakeOutputs { systemsFromFile = ./nix_systems; config.projectRoot = ./.; @@ -19,7 +25,7 @@ packageOverrides = { ${name}.staticPage = { preBuild = '' - cp ${inp.nixdoc-fork.packages.${system}.data} ./models/lib.json + cp ${inp.nixdoc-fork.packages.${system}.data} ./models/lib.json ''; installPhase = '' runHook preInstall @@ -35,7 +41,20 @@ }) // { devShells.${system}.default = pkgs.mkShell { - buildInputs = with pkgs; [nodejs-18_x ]; + buildInputs = with pkgs; [ nodejs-18_x ]; + shellHook = '' + ${self.checks.${system}.pre-commit-check.shellHook} + ''; + }; + checks.${system} = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + nixpkgs-fmt.enable = true; + statix.enable = true; + markdownlint.enable = true; + }; + }; }; }; diff --git a/tsconfig.json b/tsconfig.json index 7f87932..783458b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "target": "es6", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, + "noUnusedLocals": true, "skipLibCheck": true, "strict": true, "forceConsistentCasingInFileNames": true, @@ -16,5 +17,5 @@ "incremental": true }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], - "exclude": ["node_modules"] + "exclude": ["node_modules", "result"] } From 72c3a28d92b6682b8ddce0c0b62daeaeeea8ff53 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 25 Jan 2023 16:23:32 +0100 Subject: [PATCH 2/4] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3d02f0c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Johannes Kirschbauer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 676a68608783e276a2bdc989031ab50496965164 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 25 Jan 2023 16:34:22 +0100 Subject: [PATCH 3/4] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 38 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 23 ++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..f7408ed --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**What happened** +The bug you encountered + +**Steps to Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + - Screen resolution (optional) + +or + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bdc4d68 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,23 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**If your Feature is adding / extending more functions** +Tell us where to find the function / functions e.g. where in nixpkgs + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From a7ded1215ce512a89ff304a65c6d1aa6e20b9eb1 Mon Sep 17 00:00:00 2001 From: Paul Haerle Date: Wed, 25 Jan 2023 22:45:33 +0100 Subject: [PATCH 4/4] Add OpenSearch description (#17) This allows users to add noogle search to their browser toolbar. See https://developer.mozilla.org/en-US/docs/Web/OpenSearch#autodiscovery_of_search_plugins or search.nixos.org --- pages/_app.tsx | 1 + public/search.xml | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 public/search.xml diff --git a/pages/_app.tsx b/pages/_app.tsx index 49d4cc5..fd40338 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -49,6 +49,7 @@ const MyApp: React.FunctionComponent = (props) => { + diff --git a/public/search.xml b/public/search.xml new file mode 100644 index 0000000..38b8c55 --- /dev/null +++ b/public/search.xml @@ -0,0 +1,10 @@ + + +Noogle + Search for nix functions by name. + UTF-8 + https://noogle.dev/favicon.png + + https://noogle.dev +