Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ixx: swap backend to ixx #115

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ Thumbs.db

# CUSTOM
result
/public/meta
/public/index.ixx
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.

17 changes: 13 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +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 {
buildInputs = with pkgs; [
nativeBuildInputs = with pkgs; [
nodejs
pnpm
(python3.withPackages (ps: with ps; [ markdown pygments ]))
ixxPkgs.ixx
];
};

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.

6 changes: 5 additions & 1 deletion nix/frontend.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ stdenv.mkDerivation (finalAttrs: {
postPatch = ''
substituteInPlace src/app/core/config.domain.ts \
--replace-fail '##TITLE##' '${title}'
substituteInPlace src/index.html \
--replace-fail '##TITLE##' '${title}'
'';

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+x9zCFPxfm6p3uBfx4eMm1=";
};

nativeBuildInputs = [ nodejs pnpm.configHook ];
Expand Down
52 changes: 26 additions & 26 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, nuscht-search, ixxPkgs, runCommand, xorg }:

rec {
mkOptionsJSON = modules: (nixosOptionsDoc {
Expand All @@ -15,39 +15,39 @@ 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/";
# title = "Custom Search";
# scopes = [
# { modules = [ self.inputs.nixos-modules.nixosModule ]; urlPrefix = "https://github.com/NuschtOS/nixos-modules/blob/main/"; }
# { optionsJSON = ./path/to/options.json; optionsPrefix = "programs.example"; urlPrefix = "https://git.example.com/blob/main/"; }
# { modules = [ self.inputs.nixos-modules.nixosModule ]; urlPrefix = "https://github.com/NuschtOS/nixos-modules/blob/main/"; name = "NixOS Modules"; }
# { optionsJSON = ./path/to/options.json; optionsPrefix = "programs.example"; urlPrefix = "https://git.example.com/blob/main/"; name = "Example Module"; }
# ];
# };
mkMultiSearch = { scopes, baseHref ? "/", title ? "NüschtOS 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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
"@angular/platform-browser": "^18.2.7",
"@angular/platform-browser-dynamic": "^18.2.7",
"@angular/router": "^18.2.7",
"@feel/form": "^0.0.25",
"@feel/style": "^0.0.25",
"@feel/form": "^0.0.27",
"@feel/style": "^0.0.27",
"@fontsource/dm-mono": "^5.1.0",
"@fontsource/dm-sans": "^5.1.0",
"@nuschtos/fixx": "link:../ixx/result",
"rxjs": "~7.8.1",
"tslib": "^2.7.0",
"zone.js": "~0.15.0"
Expand Down
Loading
Loading