Using naersk seems to work.

This commit is contained in:
Jeremy Wall 2022-02-28 14:28:21 -05:00
parent 3da9f135be
commit 3c812a737f
7 changed files with 85 additions and 21 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@ target/
.clj-kondo/
web/dist/
webdist/
nix/*/result
nix/*/result
result/

35
flake.lock generated
View File

@ -31,7 +31,39 @@
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1639947939,
"narHash": "sha256-pGsM8haJadVP80GFq4xhnSpNitYNQpaXk4cnA796Cso=",
"owner": "nix-community",
"repo": "naersk",
"rev": "2fc8ce9d3c025d59fee349c1f80be9785049d653",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1645937171,
"narHash": "sha256-n9f9GZBNMe8UMhcgmmaXNObkH01jjgp7INMrUgBgcy4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "22dc22f8cedc58fcb11afe1acb08e9999e78be9c",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1641224400,
"narHash": "sha256-unXptp6PtSHSFVSAz+v6ZLtFDgaZZUCSjV0ie5A0qIw=",
@ -51,7 +83,8 @@
"inputs": {
"flake-utils": "flake-utils",
"gitignore": "gitignore",
"nixpkgs": "nixpkgs"
"naersk": "naersk",
"nixpkgs": "nixpkgs_2"
}
}
},

View File

@ -5,11 +5,12 @@
nixpkgs.url = "github:NixOS/nixpkgs/adf7f03d3bfceaba64788e1e846191025283b60d";
gitignore = { url = "github:hercules-ci/gitignore.nix"; flake = false; };
flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
};
outputs = {self, nixpkgs, flake-utils, gitignore}:
outputs = {self, nixpkgs, flake-utils, naersk, gitignore}:
let
kitchenGen = (import ./nix/default.nix);
kitchenGen = (import ./nix/kitchen/default.nix);
trunkGen = (import ./nix/trunk/default.nix);
kitchenWasmGen = (import ./nix/kitchenWasm/default.nix);
cargoVendorGen = (import ./nix/cargoVendorDeps/default.nix);
@ -18,7 +19,8 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
trunk = trunkGen { inherit pkgs; };
naersk-lib = naersk.lib."${system}";
trunk = trunkGen { inherit pkgs naersk-lib; };
cargoVendorDeps = cargoVendorGen {
inherit pkgs version;
lockFile = ./Cargo.lock;
@ -26,20 +28,21 @@
kitchenWasm = kitchenWasmGen {
inherit pkgs cargoVendorDeps trunk version;
};
#kitchen = (kitchenGen {
# inherit pkgs cargoDeps version kitchenWasm;
## gitignoreSrc = nixpkgs.callPackage gitignore { };
#});
kitchen = (kitchenGen {
inherit pkgs version naersk-lib kitchenWasm;# cargoVendorDeps;
# Because it's a workspace we need the other crates available as source
root = (pkgs.callPackage gitignore { }).gitignoreSource ./.;
});
in
{
packages = {
inherit trunk
cargoVendorDeps
kitchenWasm
# kitchen
kitchen
;
};
defaultPackage = cargoVendorDeps;
defaultPackage = kitchen;
}
);
}

View File

@ -3,7 +3,7 @@
version ? "0.2.1"}:
let
cargoDeps = (pkgs.rustPlatform.importCargoLock { inherit lockFile; });
recipes = ./../../recipes;
#recipes = ./../../recipes;
in
with pkgs;
stdenv.mkDerivation {
@ -14,8 +14,8 @@ stdenv.mkDerivation {
mkdir -p $out
cp -r ${cargoDeps}/* $out/
cp -r ${cargoDeps}/.cargo $out/
cp -r ${recipes} $out/recipes-${version}
ls -al $out/
'';
#cp -r ${recipes} $out/recipes-${version}
}

28
nix/kitchen/default.nix Normal file
View File

@ -0,0 +1,28 @@
{pkgs ? (import <nixpkgs>) {},
# Because it's a workspace we need the other crates available as source
root,
kitchenWasm,
version,
naersk-lib,
#cargoVendorDeps ? (import ./../cargoVendorDeps/default.nix {inherit pkgs version; }),
}:
with pkgs;
#let
# vendorDir = "cargo-vendor-dir";
# #cargoVendorDrv = cargoVendorDeps;
#in
(naersk-lib.buildPackage rec {
pname = "kitchen";
inherit version;
# However the crate we are building has it's root in specific crate.
src = root;
cargoBuildOptions = opts: opts ++ ["-p" "${pname}" ];
postPatch = ''
echo ln -s ${kitchenWasm} web/dist
ln -s ${kitchenWasm} web/dist
'';
# echo cp -r ${cargoVendorDrv}/* ${vendorDir}/
# cp -r ${cargoVendorDrv}/* ${vendorDir}/
# mkdir -p .cargo
# cp -r ${cargoVendorDrv}/.cargo/* .cargo/
})

View File

@ -6,7 +6,7 @@
with pkgs;
let
pname = "kitchen-wasm";
src = ./../../web;
src = ./../..;
in
stdenv.mkDerivation {
inherit src pname;
@ -18,11 +18,9 @@ stdenv.mkDerivation {
cp -r ./cargo-vendor-dir/.cargo ./
cp -r $src/* ./
'';
# NOTE(jwall): For some reason trunk is trying to do something with staging that
# nix doesn't like. We suppress the message for now but I'd like to
# know why trunk can't create those directories.
# TODO(jwall): Build this from the root rather than the src.
buildPhase = ''
trunk build --release --public-url /ui/ --dist ./dist || echo ignoring staging errors for now;
trunk build --release --public-url /ui/ --dist ./dist web/index.html || echo ignoring staging errors for now;
pwd
ls -al .
'';

View File

@ -1,6 +1,8 @@
{pkgs ? (import <nixpkgs>) {}}:
{pkgs ? (import <nixpkgs>) {},
naersk-lib,
}:
with pkgs;
rustPlatform.buildRustPackage rec {
naersk-lib.buildPackage rec {
pname = "trunk";
version = "v0.14.0";
src = fetchFromGitHub {
@ -9,7 +11,6 @@ rustPlatform.buildRustPackage rec {
rev = version;
sha256 = "sha256-69MQDIF79pSuaOgZEIqb/ESPQzL7MUiQaJaxPccGxo8=";
};
cargoSha256 = "sha256-RPE2wMggD8nXpuUkRsvG5wxIWCHifD4RLLLPkq8HOEQ=";
# Trunk uses the network in it's test which is lame. We'll work around
# by disabling here for now.