|
| 1 | +{ |
| 2 | + inputs = { |
| 3 | + nixpkgs.url = "nixpkgs/nixos-unstable"; |
| 4 | + |
| 5 | + lute-src = { |
| 6 | + url = "github:luau-lang/lute"; |
| 7 | + flake = false; |
| 8 | + }; |
| 9 | + }; |
| 10 | + |
| 11 | + outputs = { |
| 12 | + self, |
| 13 | + nixpkgs, |
| 14 | + lute-src, |
| 15 | + ... |
| 16 | + }: let |
| 17 | + inherit (nixpkgs) lib; |
| 18 | + |
| 19 | + forAllSystems = f: |
| 20 | + lib.genAttrs lib.systems.flakeExposed (system: f nixpkgs.legacyPackages.${system}); |
| 21 | + in { |
| 22 | + packages = forAllSystems (pkgs: let |
| 23 | + deps = builtins.fromJSON (builtins.readFile ./deps.json); |
| 24 | + extern = lib.listToAttrs (map (dep: { |
| 25 | + name = dep.name; |
| 26 | + value = pkgs.fetchgit { |
| 27 | + url = dep.url; |
| 28 | + rev = dep.revision; |
| 29 | + sha256 = dep.sha256; |
| 30 | + fetchSubmodules = false; |
| 31 | + }; |
| 32 | + }) deps); |
| 33 | + |
| 34 | + copyExterns = lib.concatStringsSep "\n" (lib.mapAttrsToList (name: path: '' |
| 35 | + cp -R --no-preserve=mode ${path} extern/${name} |
| 36 | + '') extern); |
| 37 | + in { |
| 38 | + default = pkgs.llvmPackages_18.libcxxStdenv.mkDerivation { |
| 39 | + pname = "lute"; |
| 40 | + version = "0.1.0"; |
| 41 | + |
| 42 | + src = lute-src; |
| 43 | + |
| 44 | + nativeBuildInputs = with pkgs; [ |
| 45 | + cmake |
| 46 | + ninja |
| 47 | + git |
| 48 | + ]; |
| 49 | + |
| 50 | + dontConfigure = true; |
| 51 | + |
| 52 | + buildPhase = '' |
| 53 | + runHook preBuild |
| 54 | +
|
| 55 | + ${copyExterns} |
| 56 | +
|
| 57 | + mkdir -p lute/std/src/generated |
| 58 | + cp tools/templates/std_impl.cpp lute/std/src/generated/modules.cpp |
| 59 | + cp tools/templates/std_header.h lute/std/src/generated/modules.h |
| 60 | +
|
| 61 | + mkdir -p lute/cli/generated |
| 62 | + cp tools/templates/cli_impl.cpp lute/cli/generated/commands.cpp |
| 63 | + cp tools/templates/cli_header.h lute/cli/generated/commands.h |
| 64 | +
|
| 65 | + cmake -G Ninja -B build/debug -DCMAKE_BUILD_TYPE=Debug |
| 66 | + ninja -C build/debug lute/cli/lute |
| 67 | +
|
| 68 | + mv build/debug/lute/cli/lute build/lute0 |
| 69 | +
|
| 70 | + # Precompute the tune hash so luthier won't fetch deps. |
| 71 | + mkdir -p extern/generated |
| 72 | + tmp_hash_input="$(mktemp)" |
| 73 | + LC_ALL=C find extern -maxdepth 1 -type f -name '*.tune' -printf '%f\n' | sort | while read -r name; do |
| 74 | + printf "%s" "$name" >> "$tmp_hash_input" |
| 75 | + cat "extern/$name" >> "$tmp_hash_input" |
| 76 | + done |
| 77 | + tune_hash="$(b2sum --length=256 "$tmp_hash_input" | cut -d' ' -f1)" |
| 78 | + printf "%s" "$tune_hash" > extern/generated/hash.txt |
| 79 | + rm -f "$tmp_hash_input" |
| 80 | +
|
| 81 | + build/lute0 tools/luthier.luau configure --config release --clean lute |
| 82 | + build/lute0 tools/luthier.luau build --config release --clean lute |
| 83 | +
|
| 84 | + runHook postBuild |
| 85 | + ''; |
| 86 | + |
| 87 | + installPhase = '' |
| 88 | + runHook preInstall |
| 89 | +
|
| 90 | + mkdir -p $out/bin |
| 91 | + cp build/release/lute/cli/lute $out/bin/lute |
| 92 | +
|
| 93 | + runHook postInstall |
| 94 | + ''; |
| 95 | + |
| 96 | + checkPhase = '' |
| 97 | + runHook preCheck |
| 98 | +
|
| 99 | + export HOME="$TMPDIR" |
| 100 | + ninja -C build/release tests/lute-tests |
| 101 | + ./build/release/tests/lute-tests |
| 102 | +
|
| 103 | + runHook postCheck |
| 104 | + ''; |
| 105 | + |
| 106 | + doCheck = false; |
| 107 | + }; |
| 108 | + }); |
| 109 | + |
| 110 | + checks = lib.genAttrs lib.systems.flakeExposed (system: { |
| 111 | + lute-tests = self.packages.${system}.default.overrideAttrs (old: { |
| 112 | + doCheck = true; |
| 113 | + }); |
| 114 | + }); |
| 115 | + |
| 116 | + apps = forAllSystems (pkgs: { |
| 117 | + update-deps = { |
| 118 | + type = "app"; |
| 119 | + meta = { |
| 120 | + description = "A script which fetches lute dep hashes"; |
| 121 | + }; |
| 122 | + program = toString (pkgs.writeShellScript "update-deps" '' |
| 123 | + export PATH="${lib.makeBinPath [ pkgs.nushell pkgs.nix-prefetch-git ]}:$PATH" |
| 124 | + exec nu ${./update-deps.nu} --lute-path ${lute-src} --out deps.json |
| 125 | + ''); |
| 126 | + }; |
| 127 | + }); |
| 128 | + }; |
| 129 | +} |
0 commit comments