radicle-explorer: refactor
`withConfig` has been simplified to not merge the default config
anymore, since this already seems to happen in the build process of
radicle-explorer anyway.
Cleaned up the nested `lib.fix` and `makeOverridable` invocations.
Removed the `npmDepsHash` and `patches` overridable parameters. Use
`overrideAttrs` instead:
```nix
radicle-explorer.overrideAttrs (finalAttrs: prevAttrs: {
patches = prevAttrs.patches or [ ] ++ [ ... ];
npmDepsHash = "sha256-...";
npmDeps = fetchNpmDeps {
inherit (finalAttrs) src;
hash = finalAttrs.npmDepsHash;
};
})
```
This should also work more reliably in combination with `withConfig`.
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
{
|
||||
radicle-httpd,
|
||||
fetchFromGitHub,
|
||||
lib,
|
||||
buildNpmPackage,
|
||||
writeText,
|
||||
jq,
|
||||
runCommand,
|
||||
fetchFromGitHub,
|
||||
radicle-httpd,
|
||||
writers,
|
||||
}:
|
||||
|
||||
let
|
||||
@@ -14,106 +12,80 @@ let
|
||||
twemojiAssets = fetchFromGitHub {
|
||||
owner = "twitter";
|
||||
repo = "twemoji";
|
||||
rev = "v14.0.2";
|
||||
tag = "v14.0.2";
|
||||
hash = "sha256-YoOnZ5uVukzi/6bLi22Y8U5TpplPzB7ji42l+/ys5xI=";
|
||||
meta.license = [ lib.licenses.cc-by-40 ];
|
||||
};
|
||||
|
||||
mkPassthru = self: args: {
|
||||
# radicle-explorer is configured through static build time configuration.
|
||||
#
|
||||
# Using this function you can override the this configuration, for example,
|
||||
# to configure alternative preferred peers (which are shown in the UI by
|
||||
# default).
|
||||
#
|
||||
# Example usage:
|
||||
#
|
||||
# ```nix
|
||||
# radicle-explorer.withConfig {
|
||||
# preferredSeeds = [{
|
||||
# hostname = "seed.example.com";
|
||||
# port = 443;
|
||||
# scheme = "https";
|
||||
# }];
|
||||
# }
|
||||
# ```
|
||||
withConfig =
|
||||
config:
|
||||
let
|
||||
overrides = writeText "config-overrides.json" (builtins.toJSON config);
|
||||
newConfig = runCommand "config.json" { } ''
|
||||
${jq}/bin/jq -s '.[0] * .[1]' ${(self args).src}/config/default.json ${overrides} > $out
|
||||
'';
|
||||
in
|
||||
lib.fix (
|
||||
final:
|
||||
(self args).overrideAttrs (prev: {
|
||||
preBuild = ''
|
||||
${prev.preBuild or ""}
|
||||
cp ${newConfig} config/local.json
|
||||
'';
|
||||
|
||||
passthru = prev.passthru // mkPassthru final args;
|
||||
})
|
||||
);
|
||||
};
|
||||
in
|
||||
lib.fix (
|
||||
self:
|
||||
lib.makeOverridable (
|
||||
{
|
||||
npmDepsHash ? "sha256-8vmAs788PjdUTaQ5E8YLX0KiIPymJbH51oNaGZACe6I=",
|
||||
patches ? [ ],
|
||||
}@args:
|
||||
buildNpmPackage {
|
||||
pname = "radicle-explorer";
|
||||
version = radicle-httpd.version;
|
||||
inherit patches npmDepsHash;
|
||||
|
||||
# radicle-explorer uses the radicle-httpd API, and they are developed in the
|
||||
# same repo. For this reason we pin the sources to each other, but due to
|
||||
# radicle-httpd using a more limited sparse checkout we need to carry a
|
||||
# separate hash.
|
||||
src = radicle-httpd.src.override {
|
||||
hash = "sha256-cnQsPWkRChC8yPrICRoUpGW2GGLB2TK9+3v8ZRGe3x0=";
|
||||
sparseCheckout = [ ];
|
||||
};
|
||||
buildNpmPackage (finalAttrs: {
|
||||
pname = "radicle-explorer";
|
||||
inherit (radicle-httpd) version;
|
||||
|
||||
postPatch = ''
|
||||
patchShebangs --build ./scripts
|
||||
mkdir -p "public/twemoji"
|
||||
cp -t public/twemoji -r -- ${twemojiAssets}/assets/svg/*
|
||||
: >scripts/install-twemoji-assets
|
||||
'';
|
||||
# radicle-explorer uses the radicle-httpd API, and they are developed in the
|
||||
# same repo. For this reason we pin the sources to each other, but due to
|
||||
# radicle-httpd using a more limited sparse checkout we need to carry a
|
||||
# separate hash.
|
||||
src = radicle-httpd.src.override {
|
||||
hash = "sha256-cnQsPWkRChC8yPrICRoUpGW2GGLB2TK9+3v8ZRGe3x0=";
|
||||
sparseCheckout = [ ];
|
||||
};
|
||||
|
||||
dontConfigure = true;
|
||||
doCheck = false;
|
||||
npmDepsHash = "sha256-8vmAs788PjdUTaQ5E8YLX0KiIPymJbH51oNaGZACe6I=";
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
mkdir -p "$out"
|
||||
cp -r -t "$out" build/*
|
||||
runHook postInstall
|
||||
'';
|
||||
postPatch = ''
|
||||
patchShebangs --build ./scripts
|
||||
: >scripts/install-twemoji-assets
|
||||
|
||||
passthru = mkPassthru self args;
|
||||
cp -r "${twemojiAssets}/assets/svg" public/twemoji
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "Web frontend for Radicle";
|
||||
longDescription = ''
|
||||
Radicle Explorer is a web-frontend for Radicle which supports browsing
|
||||
repositories, issues and patches on publicly available Radicle seeds.
|
||||
preBuild = ''
|
||||
if [[ $configFile ]]; then
|
||||
cp "$configFile" config/local.json
|
||||
fi
|
||||
'';
|
||||
|
||||
This package builds the web interface, ready to be served by any web
|
||||
server.
|
||||
'';
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
homepage = "https://radicle.dev";
|
||||
license = lib.licenses.gpl3;
|
||||
mv build $out
|
||||
|
||||
teams = [ lib.teams.radicle ];
|
||||
maintainers = with lib.maintainers; [ tazjin ];
|
||||
};
|
||||
}
|
||||
)
|
||||
) { }
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
# radicle-explorer is configured through static build time configuration.
|
||||
#
|
||||
# Using this function you can override this configuration, for example to
|
||||
# configure alternative preferred peers (which are shown in the UI by default).
|
||||
#
|
||||
# Example usage:
|
||||
#
|
||||
# ```nix
|
||||
# radicle-explorer.withConfig {
|
||||
# preferredSeeds = [{
|
||||
# hostname = "seed.example.com";
|
||||
# port = 443;
|
||||
# scheme = "https";
|
||||
# }];
|
||||
# }
|
||||
# ```
|
||||
passthru.withConfig =
|
||||
config:
|
||||
finalAttrs.finalPackage.overrideAttrs { configFile = writers.writeJSON "config.json" config; };
|
||||
|
||||
meta = {
|
||||
description = "Web frontend for Radicle";
|
||||
longDescription = ''
|
||||
Radicle Explorer is a web-frontend for Radicle which supports browsing
|
||||
repositories, issues and patches on publicly available Radicle seeds.
|
||||
|
||||
This package builds the web interface, ready to be served by any web
|
||||
server.
|
||||
'';
|
||||
homepage = "https://radicle.dev";
|
||||
license = lib.licenses.gpl3;
|
||||
teams = [ lib.teams.radicle ];
|
||||
maintainers = with lib.maintainers; [ tazjin ];
|
||||
};
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user