diff options
| -rwxr-xr-x | .gitignore | 2 | ||||
| -rw-r--r-- | default.nix | 2 | ||||
| -rw-r--r-- | flake.nix | 18 | ||||
| -rw-r--r-- | package.nix | 67 |
4 files changed, 89 insertions, 0 deletions
@@ -17,3 +17,5 @@ zig-pkg/ /build/ /build-*/ /docgen_tmp/ +/result +/result-* diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..068bd32 --- /dev/null +++ b/default.nix @@ -0,0 +1,2 @@ +{ pkgs ? import <nixpkgs> { } }: +pkgs.callPackage ./package.nix { } diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a956884 --- /dev/null +++ b/flake.nix @@ -0,0 +1,18 @@ +{ + description = "HTMLua HTML templating engine"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + outputs = { self, nixpkgs }: + let + systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forAllSystems = nixpkgs.lib.genAttrs systems; + in { + packages = forAllSystems (system: + let pkgs = import nixpkgs { inherit system; }; + in { + htmlua = import ./default.nix { inherit pkgs; }; + default = self.packages.${system}.htmlua; + }); + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..e459172 --- /dev/null +++ b/package.nix @@ -0,0 +1,67 @@ +{ + lib, + stdenv, + runCommand, + zig_0_16, + zigDepsHash ? "sha256-HWfTcAUFL4vZJDg242y5R3zQY6fDshKk6VMn+qgSNi4=", +}: + +let + zig = zig_0_16; +in +stdenv.mkDerivation (finalAttrs: { + pname = "htmlua"; + version = "1.0.0-alpha"; + + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./build.zig + ./build.zig.zon + ./src + ./examples + ./LICENSE + ./README.md + ]; + }; + + nativeBuildInputs = [ zig ]; + + zigDeps = + runCommand "${finalAttrs.pname}-${finalAttrs.version}-zig-deps" + { + inherit (finalAttrs) src; + nativeBuildInputs = [ zig ]; + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + outputHash = zigDepsHash; + } + '' + export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-cache" + mkdir -p "$ZIG_GLOBAL_CACHE_DIR/tmp" + runHook unpackPhase + cd "$sourceRoot" + + for attempt in 1 2 3; do + if zig build --fetch; then + mv "$ZIG_GLOBAL_CACHE_DIR/p" "$out" + exit 0 + fi + echo "Zig dependency fetch attempt $attempt failed" >&2 + done + exit 1 + ''; + + postConfigure = '' + ln -s ${finalAttrs.zigDeps} "$ZIG_GLOBAL_CACHE_DIR/p" + ''; + + doCheck = true; + + meta = { + description = "An HTML templating engine with (not yet reimplemented) Lua scripting abilities"; + license = lib.licenses.mit; + mainProgram = "htmlua"; + platforms = lib.platforms.unix; + }; +}) |
