reading
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
/site/target/
|
/site/target/
|
||||||
/site/dist/
|
/site/dist/
|
||||||
|
result
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# iana-angl site
|
||||||
|
|
||||||
|
Build the static Leptos/Trunk site:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix build .#iana-angl
|
||||||
|
```
|
||||||
|
|
||||||
|
## NixOS integration
|
||||||
|
|
||||||
|
Add this flake as an input, import its module, and provide the built package and
|
||||||
|
virtual host domain:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
inputs.iana-angl.url = "path:/home/yukkop/pj/iana-angl";
|
||||||
|
|
||||||
|
outputs = { nixpkgs, ... }@inputs: {
|
||||||
|
nixosConfigurations.my-host = nixpkgs.lib.nixosSystem {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
modules = [
|
||||||
|
inputs.iana-angl.nixosModules.iana-angl
|
||||||
|
({ pkgs, ... }: {
|
||||||
|
services.iana-angl = {
|
||||||
|
enable = true;
|
||||||
|
package = inputs.iana-angl.packages.${pkgs.system}.iana-angl;
|
||||||
|
domain = "lessons.example.com";
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The module enables nginx, serves the package as a static SPA, and falls back to
|
||||||
|
`index.html` for client-side routes. Configure TLS, ACME, firewall ports, and
|
||||||
|
reverse-proxy policy separately in the consuming system.
|
||||||
@@ -21,6 +21,68 @@
|
|||||||
forEachSystem = f: nixpkgs.lib.genAttrs systems f;
|
forEachSystem = f: nixpkgs.lib.genAttrs systems f;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
packages = forEachSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [ (import rust-overlay) ];
|
||||||
|
};
|
||||||
|
|
||||||
|
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||||
|
targets = [ "wasm32-unknown-unknown" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
wasmBindgenCli = pkgs.wasm-bindgen-cli.overrideAttrs (_: rec {
|
||||||
|
version = "0.2.128";
|
||||||
|
src = pkgs.fetchCrate {
|
||||||
|
pname = "wasm-bindgen-cli";
|
||||||
|
inherit version;
|
||||||
|
hash = "sha256-a7lcXJnnZkYReja+iUO7NqqrWyv3toxnUgQb8s4IS5s=";
|
||||||
|
};
|
||||||
|
cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
|
||||||
|
inherit src;
|
||||||
|
hash = "sha256-R1Tas33Ursy8kqsxguAkG0ZhNed2n5uFTAhw1l2qlLY=";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
in
|
||||||
|
{
|
||||||
|
iana-angl = pkgs.stdenv.mkDerivation {
|
||||||
|
pname = "iana-angl";
|
||||||
|
version = "0.1.0";
|
||||||
|
|
||||||
|
src = pkgs.lib.cleanSourceWith {
|
||||||
|
src = ./site;
|
||||||
|
filter = path: type:
|
||||||
|
let
|
||||||
|
name = builtins.baseNameOf path;
|
||||||
|
in
|
||||||
|
name != "target" && name != "dist";
|
||||||
|
};
|
||||||
|
|
||||||
|
cargoDeps = pkgs.rustPlatform.importCargoLock {
|
||||||
|
lockFile = ./site/Cargo.lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkgs.rustPlatform.cargoSetupHook
|
||||||
|
rustToolchain
|
||||||
|
pkgs.trunk
|
||||||
|
wasmBindgenCli
|
||||||
|
pkgs.binaryen
|
||||||
|
pkgs.pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
export HOME="$TMPDIR"
|
||||||
|
trunk build --release --dist "$out"
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = "true";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
devShells = forEachSystem (system:
|
devShells = forEachSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
@@ -50,5 +112,7 @@
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
nixosModules = import ./nixos/module;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
let
|
||||||
|
iana-angl = import ./iana-angl;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit iana-angl;
|
||||||
|
default = iana-angl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
imports = [ ./static-nginx.nix ];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
{ config, lib, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.services.iana-angl;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.services.iana-angl = {
|
||||||
|
enable = lib.mkEnableOption "iana-angl static site";
|
||||||
|
|
||||||
|
package = lib.mkOption {
|
||||||
|
type = lib.types.package;
|
||||||
|
description = "Static iana-angl site package to serve.";
|
||||||
|
};
|
||||||
|
|
||||||
|
domain = lib.mkOption {
|
||||||
|
type = lib.types.strMatching ".+";
|
||||||
|
description = "Nonempty nginx virtual host domain for iana-angl.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
services.nginx = {
|
||||||
|
enable = true;
|
||||||
|
virtualHosts.${cfg.domain}.locations."/".extraConfig = ''
|
||||||
|
alias ${cfg.package}/;
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user