Skip to content

Commit

Permalink
Merge pull request #195 from NuschtOS/MarcelCoding-patch-1
Browse files Browse the repository at this point in the history
Add FAQ example
  • Loading branch information
SuperSandro2000 authored Jan 25, 2025
2 parents 570cc17 + 1c95aec commit f91a0ac
Showing 1 changed file with 55 additions and 21 deletions.
76 changes: 55 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ Simple and fast static-page NixOS option search
## Usage

There are two functions exposeed to build the directory containing the static search:
- `mkMultiSearch` to build a search with multiple scopes (modules).
It takes the `baseHref`, `title` and `scopes` option.
- `mkSearch` is a thin wrapper around `mkMultiSearch` to only use one scope (module).
It takes the `modules`, `optionsJSON`, `optionsPrefix`, `urlPrefix`, `baseHref` and `title` option.

### Explanation of options
| Name | Description | Available Options |
|---|---|---|
| `mkMultiSearch` | to build a search with multiple scopes (modules). | `baseHref`, `title` and `scopes` |
| `mkSearch` | is a thin wrapper around `mkMultiSearch` to only use one scope (module). | `modules`, `optionsJSON`, `optionsPrefix`, `urlPrefix`, `baseHref` and `title` |

- `baseHref` - The directory to where the search is going to be deployed relative to the domain. Defaults to `/`.
- `title` - The title on the top left. Defaults to `NüschtOS Search`.
- `modules` - A list of NixOS modules as an attrset or file similar to the `nixosSystem` function. Exclusive with `optionsJSON`.
- `optionsJSON` - Path to a pre-generated `options.json` file. Exclusive with `modules`.
- `optionsPrefix` - A static prefix to append to all options. An extra `dot` is always appended. Defaults to being empty.
- `urlPrefix` - The prefix which is prepended to the declaration link. This is usually a link to a git.
### Explanation of options

- `scopes` is a list of attributes which each takes `name`, `modules`, `optionsJSON`, `optionsPrefix` or `urlPrefix` option.
| Name | Description |
|---|---|
| `baseHref` | The directory to where the search is going to be deployed relative to the domain. Defaults to `/`. |
| `title` | The title on the top left. Defaults to `NüschtOS Search`. |
| `modules` | A list of NixOS modules as an attrset or file similar to the `nixosSystem` function. Exclusive with `optionsJSON`. |
| `optionsJSON` | Path to a pre-generated `options.json` file. Exclusive with `modules`. |
| `optionsPrefix` | A static prefix to append to all options. An extra `dot` is always appended. Defaults to being empty. |
| `urlPrefix` | The prefix which is prepended to the declaration link. This is usually a link to a git. |
| `scopes` | is a list of attributes which each takes `name`, `modules`, `optionsJSON`, `optionsPrefix` or `urlPrefix` option. |

### Examples

Expand All @@ -49,12 +51,35 @@ mkMultiSearch {
```

```nix
mkSearch { modules = [ self.inputs.nixos-modules.nixosModule ]; urlPrefix = "https://github.com/NuschtOS/nixos-modules/blob/main/"; }
mkSearch { optionsJSON = ./path/to/options.json; optionsPrefix = "programs.example"; urlPrefix = "https://git.example.com/blob/main/"; }
mkSearch { optionsJSON = ./path/to/options.json; urlPrefix = "https://git.example.com/blob/main/"; baseHref = "/search/"; title = "Custom Search"; }
mkSearch {
modules = [ self.inputs.nixos-modules.nixosModule ];
urlPrefix = "https://github.com/NuschtOS/nixos-modules/blob/main/";
}
```

```nix
mkSearch {
optionsJSON = ./path/to/options.json;
optionsPrefix = "programs.example";
urlPrefix = "https://git.example.com/blob/main/";
}
```

```nix
mkSearch {
optionsJSON = ./path/to/options.json;
urlPrefix = "https://git.example.com/blob/main/";
baseHref = "/search/";
title = "Custom Search";
}
```
- Static page with GitHub Actions and Cloudflare/GitHub Pages https://github.com/NuschtOS/search.nuschtos.de/blob/main/.github/workflows/gh-pages.yaml https://github.com/NuschtOS/search.nuschtos.de/blob/main/flake.nix
- Deployed with NixOS https://gitea.c3d2.de/c3d2/nix-config/src/branch/master/hosts/nixos-misc/default.nix#L48-L103

- Static page with GitHub Actions and Cloudflare/GitHub Pages <br/>
<https://github.com/NuschtOS/search.nuschtos.de/blob/main/.github/workflows/gh-pages.yaml> <br/>
<https://github.com/NuschtOS/search.nuschtos.de/blob/main/flake.nix>

- Deployed with NixOS <br/>
<https://gitea.c3d2.de/c3d2/nix-config/src/branch/master/hosts/nixos-misc/default.nix#L50-L148>

## Motivation

Expand All @@ -68,19 +93,23 @@ but without the need to deploy an Elasticsearch. Ideally it should be just a sta
This is most often caused by using nix' `import` keyword to load a module in the flake instead of referencing it via the path type.
This causes the module system to no longer be aware of the origin of the module and the missing declaration.

If no arguments are being hand over, this can be easily fixed by removing the `import` keyword. (e.g. [change in sops-nix](https://github.com/Mic92/sops-nix/pull/645))
If arguments are being hand over, the module needs to be slightly refactored.
It is often the easiest to move everything depending on the arguments into the `flake.nix` and loading the module via the module systems `imports` variable. (e.g. [change in ifstate.nix](https://codeberg.org/m4rc3l/ifstate.nix/pulls/9))
- If no arguments are being hand over, this can be easily fixed by removing the `import` keyword. (e.g. [change in sops-nix](https://github.com/Mic92/sops-nix/pull/645))
- If arguments are being hand over, the module needs to be slightly refactored.
- It is often the easiest to move everything depending on the arguments into the `flake.nix` and loading the module via the module systems `imports` variable. (e.g. [change in ifstate.nix](https://codeberg.org/m4rc3l/ifstate.nix/pulls/9))

### default/example is a string/has extra surrounding quotes

This is caused by a missing `lib.literalExpression` in default/example. Please open a pull request against the source of that option to fix this.

### Eval Errors

Sometimes default values are computed. As the required input data is typically not available, `defaultText` should be used. (e.g. [change in nixos-hardware](https://github.com/NixOS/nixos-hardware/pull/1343))

## Debugging `options.json`

Generating a `options.json` in a `nix repl` can be done with the following snippet:

```
```nix
:b (pkgs.nixosOptionsDoc { inherit ((lib.evalModules { modules = [ { config._module.check = false; } outputs.nixosModules.default ]; })) options; warningsAreErrors = false; }).optionsJSON
```

Expand All @@ -91,3 +120,8 @@ It is assumed that the flake was loaded before with `:lf` and the module(s) is/a
For bugs and issues please open an issue in this repository.

If you want to chat about things or have ideas, feel free to join the [Matrix chat](https://matrix.to/#/#nuschtos:c3d2.de).

## License

Licensed under MIT license ([LICENSE](LICENSE) or <http://opensource.org/licenses/MIT>).

0 comments on commit f91a0ac

Please sign in to comment.