WIP: feat(webserver): Vendor and reimplement in leptos
This commit is contained in:
parent
aeba7301b0
commit
daec74e73f
12 changed files with 2976 additions and 163 deletions
143
pkgs/packages/webserver/package.nix
Normal file
143
pkgs/packages/webserver/package.nix
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
{
|
||||
lib,
|
||||
stdenvNoCC,
|
||||
fetchFromGitHub,
|
||||
symlinkJoin,
|
||||
makeBinaryWrapper,
|
||||
|
||||
cargo-leptos,
|
||||
dart-sass,
|
||||
llvmPackages,
|
||||
|
||||
mkShell,
|
||||
clangStdenv,
|
||||
rust-analyzer,
|
||||
rustc,
|
||||
rustfmt,
|
||||
leptosfmt,
|
||||
cargo,
|
||||
clippy,
|
||||
|
||||
writers,
|
||||
nix-update,
|
||||
nixfmt-rfc-style,
|
||||
}:
|
||||
let
|
||||
cargoMetadata = lib.pipe ./Cargo.toml [
|
||||
builtins.readFile
|
||||
builtins.fromTOML
|
||||
];
|
||||
|
||||
bulma = stdenvNoCC.mkDerivation (drv: {
|
||||
pname = "bulma";
|
||||
version = "1.0.4";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "jgthms";
|
||||
repo = "bulma";
|
||||
rev = "${drv.version}";
|
||||
hash = "sha256-hlejqBI6ayzhm15IymrzhTevkl3xffMfdTasZ2CmAas=";
|
||||
};
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/node_modules/bulma/
|
||||
cp -r ./sass $out/node_modules/bulma/
|
||||
'';
|
||||
});
|
||||
|
||||
fontsource-fonts = stdenvNoCC.mkDerivation (drv: {
|
||||
pname = "fontsource-fonts";
|
||||
version = "";
|
||||
});
|
||||
|
||||
# Hack to allow importing sass *without* resorting to using `npm`
|
||||
# and dealing with the insanity that is `package.json` files.
|
||||
#
|
||||
# dart-sass *in theory* supports completely arbitrary logic for
|
||||
# package importing via the `pkg:` url prefix, but unfortunately
|
||||
# currently the only implementation of it that is available in the
|
||||
# upstream binary *requires* using a `node_modules` file in the
|
||||
# repository root. See here:
|
||||
# https://sass-lang.com/documentation/at-rules/use/#node-js-package-importer
|
||||
#
|
||||
# This wouldn't be so bad if it supported an environment variable or
|
||||
# command line arg to specify what the repo root should be, but it
|
||||
# doesn't; so instead we use the load-path to specify a package
|
||||
# import root.
|
||||
#
|
||||
# As a consequence, we cannot use the `pkg:` prefix, so package
|
||||
# imports are indistinguishable from relative path imports. This
|
||||
# isn't the end of the world, but:
|
||||
#
|
||||
# TODO(tlater): See if we can talk to upstream about an
|
||||
# implementation better suited for use with nix, perhaps in
|
||||
# dart-sass (add an env variable?) or in cargo-leptos (add a config
|
||||
# option that can also be set with an env variable, and use the sass
|
||||
# protocol instead of the raw exe?).
|
||||
dart-sass-with-packages =
|
||||
let
|
||||
packages = symlinkJoin {
|
||||
name = "sass-packages";
|
||||
paths = [ bulma ];
|
||||
stripPrefix = "/node_modules";
|
||||
};
|
||||
in
|
||||
symlinkJoin {
|
||||
inherit (dart-sass) version;
|
||||
pname = "dart-sass-with-packages";
|
||||
|
||||
paths = [ dart-sass ];
|
||||
nativeBuildInputs = [ makeBinaryWrapper ];
|
||||
|
||||
postBuild = ''
|
||||
wrapProgram $out/bin/sass \
|
||||
--add-flag --load-path=${packages}
|
||||
'';
|
||||
};
|
||||
in
|
||||
symlinkJoin {
|
||||
inherit (cargoMetadata.package) version;
|
||||
pname = cargoMetadata.package.name;
|
||||
|
||||
paths = [ bulma ];
|
||||
|
||||
passthru = {
|
||||
devShell = mkShell.override { stdenv = clangStdenv; } {
|
||||
packages = [
|
||||
cargo-leptos
|
||||
dart-sass-with-packages
|
||||
# lld is exposed as ld by the clangStdenv, adding it
|
||||
# explicitly with bintools makes it work
|
||||
llvmPackages.bintools
|
||||
|
||||
rust-analyzer
|
||||
rustc
|
||||
rustfmt
|
||||
leptosfmt
|
||||
cargo
|
||||
clippy
|
||||
];
|
||||
};
|
||||
|
||||
updateScript =
|
||||
writers.writeNuBin "update-bulma"
|
||||
{
|
||||
makeWrapperArgs = [
|
||||
"--prefix"
|
||||
"PATH"
|
||||
":"
|
||||
(lib.makeBinPath [
|
||||
nix-update
|
||||
nixfmt-rfc-style
|
||||
])
|
||||
];
|
||||
}
|
||||
''
|
||||
(nix-update --flake --format
|
||||
--subpackage bulma
|
||||
--subpackage fontsource-fonts
|
||||
--subpackage fontsource-scss
|
||||
webserver)
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue