Skip to content

Commit

Permalink
wrapper: update to ixx
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelCoding committed Oct 14, 2024
1 parent a409ad2 commit 3914f2a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 98 deletions.
25 changes: 25 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,37 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
ixx = {
# match version with npm package
url = "github:NuschtOS/ixx/declaration-store-path";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};

outputs = { nixpkgs, flake-utils, ... }:
outputs = { nixpkgs, flake-utils, ixx, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = (import nixpkgs) {
inherit system;
};
ixxPkgs = ixx.packages.${system};
in
{
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
nodejs
pnpm
(python3.withPackages (ps: with ps; [ markdown pygments ]))

cargo
clippy
rustc
rustc.llvmPackages.lld
wasm-pack
ixxPkgs.ixx
];

RUST_SRC_PATH = pkgs.rust.packages.stable.rustPlatform.rustLibSrc;
};

packages = rec {
nuscht-search = pkgs.callPackage ./nix/frontend.nix { };
inherit (pkgs.callPackages ./nix/wrapper.nix { inherit nuscht-search; }) mkOptionsJSON mkSearchJSON mkSearch mkMultiSearch;
inherit (pkgs.callPackages ./nix/wrapper.nix { inherit nuscht-search ixxPkgs; }) mkOptionsJSON mkSearchJSON mkSearch mkMultiSearch;
default = nuscht-search;
};
}
Expand Down
56 changes: 0 additions & 56 deletions nix/fixup-options.py

This file was deleted.

4 changes: 3 additions & 1 deletion nix/frontend.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ stdenv.mkDerivation (finalAttrs: {

pnpmDeps = pnpm.fetchDeps {
inherit (finalAttrs) pname version src;
hash = "sha256-Ib3LtASKSLEnaLqa7nPIMX7I/FncL2pb7u7KcxaR4f8=";
# TODO: update hash
# @nuschtos/fixx is not yet released and still only a PR
hash = "sha256-QzuR/Xc8kAfqK4pO7sU2e+x9zCFPxfm6p3uBfx4eMmM=";
};

nativeBuildInputs = [ nodejs pnpm.configHook ];
Expand Down
48 changes: 24 additions & 24 deletions nix/wrapper.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, nixosOptionsDoc, jq, nuscht-search, python3, runCommand, xorg }:
{ lib, nixosOptionsDoc, jq, nuscht-search, ixxPkgs, runCommand, xorg }:

rec {
mkOptionsJSON = modules: (nixosOptionsDoc {
Expand All @@ -15,32 +15,32 @@ rec {
warningsAreErrors = false;
}).optionsJSON + /share/doc/nixos/options.json;

mkSearchJSON = scopes:
mkSearchData = scopes:
let
optionsJSON = opt: opt.optionsJSON or (mkOptionsJSON opt.modules);
optionsJSONPrefixed = opt:
if opt?optionsJSON then (runCommand "options.json-prefixed"
{
nativeBuildInputs = [ jq ];
} /* bash */ ''
mkdir $out
jq -r '[to_entries[] | select(.key | test("^(_module|_freeformOptions|warnings|assertions|content)\\..*") | not)] | from_entries ${lib.optionalString (opt?optionsPrefix) ''| with_entries(.key as $key | .key |= "${opt.optionsPrefix}.\($key)")''}' ${optionsJSON opt} > $out/options.json
'') + /options.json else optionsJSON opt;
config = {
scopes = map
(scope: (lib.filterAttrs (name: _value: name != "modules") scope) // { optionsJson = optionsJSON scope; })
scopes;
};
in
runCommand "options.json"
{ nativeBuildInputs = [ (python3.withPackages (ps: with ps; [ markdown pygments html-sanitizer ])) ]; }
(''
runCommand "search-meta"
{
config = builtins.toJSON config;
passAsFile = [ "config" ];
nativeBuildInputs = [ ixxPkgs.ixx ];
}
# NOTE: "chunk-size" has to match with constant JS code
# maybe we should encode this in the index file,
# so the frontend can determinate the value dynamically
''
mkdir $out
python \
${./fixup-options.py} \
'' + lib.concatStringsSep " " (lib.flatten (map
(opt: [
(optionsJSONPrefixed opt)
"'${opt.urlPrefix}'"
])
scopes)) + ''
> $out/options.json
'');
ixx index \
--index-output $out/index.ixx \
--meta-output $out/meta \
--chunk-size 100 \
$configPath
'';

# mkMultiSearch {
# baseHref = "/search/";
Expand All @@ -56,7 +56,7 @@ rec {
''
mkdir $out
lndir ${nuscht-search.override { inherit baseHref title; }} $out
ln -s ${mkSearchJSON scopes}/options.json $out/options.json
ln -s ${mkSearchData scopes}/{meta,index.ixx} $out
'';

# mkSearch { modules = [ self.inputs.nixos-modules.nixosModule ]; urlPrefix = "https://github.com/NuschtOS/nixos-modules/blob/main/"; }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@feel/style": "^0.0.25",
"@fontsource/dm-mono": "^5.1.0",
"@fontsource/dm-sans": "^5.1.0",
"@nuschtos/fixx": "link:../ixx/result",
"@nuschtos/fixx": "^0.0.3",
"rxjs": "~7.8.1",
"tslib": "^2.7.0",
"zone.js": "~0.15.0"
Expand Down
9 changes: 7 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/app/core/data/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface SearchedOption {
}

const CHUNK_SIZE = 100;
export const MAX_SEARCH_RESULTS=500;
export const MAX_SEARCH_RESULTS = 500;

// https://transform.tools/json-to-typescript
export interface Option {
Expand Down Expand Up @@ -51,10 +51,13 @@ export class SearchService {
}

public getByName(name: string | undefined): Observable<Option | undefined> {
if (typeof name === "undefined" || name.length == 0) {
return of(undefined);
}

return this.index.pipe(
switchMap(index => {
const idx = index && name && name.length > 0 ? index.get_idx_by_name(name) : undefined;
console.log(idx);
const idx = index ? index.get_idx_by_name(name) : undefined;
return idx ? this.getByIdx(idx) : of(undefined);
})
);
Expand Down

0 comments on commit 3914f2a

Please sign in to comment.