Skip to content

Commit

Permalink
flake reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Jan 3, 2024
1 parent e2f74f1 commit b522666
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 67 deletions.
47 changes: 11 additions & 36 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,16 @@
overlays = [
(import rust-overlay)
(final: prev: {
npmlock2nix = import npmlock2nix { pkgs = final; };
rust-wasm = (final.rust-bin.stable.latest.default.override {
targets = [ "wasm32-unknown-unknown" ];
});
demo-inspector-wasm = import ./wasm.nix final;
nodejs = final.nodejs_20;

node_modules = final.npmlock2nix.v2.node_modules {
src = ./www;
nodejs = final.nodejs;
localPackages = {
"demo-inspector" = final.demo-inspector-wasm;
};
};
npmlock2nix = import npmlock2nix {pkgs = final;};
})
(import ./overlay.nix)
];
pkgs = import nixpkgs {
inherit system overlays;
};
in rec {
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
rust-wasm
cargo-edit
bacon
wasm-pack
Expand All @@ -56,26 +43,14 @@
];
};

packages.demo-inspector-wasm = pkgs.demo-inspector-wasm;

packages.node_modules = pkgs.node_modules;

packages.demo-inspector = pkgs.stdenv.mkDerivation rec {
name = "demo-inspector";
version = "0.1.0";

src = ./www;

nativeBuildInputs = with pkgs; [nodejs_20];
buildPhase = with pkgs; ''
cp -r ${node_modules}/node_modules ./node_modules
npm run build
'';

installPhase = ''
cp -r dist $out
'';
packages = rec {
wasm = pkgs.demo-inspector-wasm;
node_modules = pkgs.demo-inspector-node-modules;
demo-inspector = pkgs.demo-inspector;
default = demo-inspector;
};
defaultPackage = packages.demo-inspector;
});
})
// {
overlays.default = import ./overlay.nix;
};
}
12 changes: 12 additions & 0 deletions modules.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
npmlock2nix,
nodejs_20,
demo-inspector-wasm,
}:
npmlock2nix.v2.node_modules {
src = ./www;
nodejs = nodejs_20;
localPackages = {
"demo-inspector" = demo-inspector-wasm;
};
}
5 changes: 5 additions & 0 deletions overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
prev: final: {
demo-inspector-wasm = final.callPackage ./wasm.nix {};
demo-inspector-node-modules = final.callPackage ./modules.nix {};
demo-inspector = final.callPackage ./package.nix {};
}
21 changes: 21 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
stdenv,
nodejs_20,
demo-inspector-node-modules,
}:
stdenv.mkDerivation rec {
name = "demo-inspector";
version = "0.1.0";

src = ./www;

nativeBuildInputs = [nodejs_20];
buildPhase = ''
cp -r ${demo-inspector-node-modules}/node_modules ./node_modules
npm run build
'';

installPhase = ''
cp -r dist $out
'';
}
75 changes: 44 additions & 31 deletions wasm.nix
Original file line number Diff line number Diff line change
@@ -1,46 +1,59 @@
pkgs: let
{
rustPlatform,
nodejs_20,
pkg-config,
openssl,
fetchCrate,
rust-bin,
wasm-pack,
binaryen,
}: let
deps = (builtins.fromTOML (builtins.readFile ./wasm/Cargo.toml)).dependencies;
wasm-bindgen-cli = pkgs.rustPlatform.buildRustPackage rec {
wasm-bindgen-cli = rustPlatform.buildRustPackage rec {
pname = "wasm-bindgen-cli";
version = deps.wasm-bindgen.version;
src = pkgs.fetchCrate {
src = fetchCrate {
inherit pname version;
sha256 = "sha256-IPxP68xtNSpwJjV2yNMeepAS0anzGl02hYlSTvPocz8=";
};

cargoSha256 = "sha256-pBeQaG6i65uJrJptZQLuIaCb/WCQMhba1Z1OhYqA8Zc=";
nativeBuildInputs = [ pkgs.pkg-config ];
nativeBuildInputs = [pkg-config];

buildInputs = with pkgs; [ openssl ];
buildInputs = [openssl];

checkInputs = [ pkgs.nodejs_20 ];
checkInputs = [nodejs_20];

dontCargoCheck = true;
};
in pkgs.rustPlatform.buildRustPackage rec {
name = "demo-inspector-wasm";
version = "0.1.0";

cargoLock = {
lockFile = ./wasm/Cargo.lock;
rust-wasm = rust-bin.stable.latest.default.override {
targets = ["wasm32-unknown-unknown"];
};
in
rustPlatform.buildRustPackage rec {
name = "demo-inspector-wasm";
version = "0.1.0";

cargoLock = {
lockFile = ./wasm/Cargo.lock;
};

src = ./wasm;

WASM_PACK_CACHE = "/build/cache";
nativeBuildInputs = [rust-wasm wasm-pack wasm-bindgen-cli binaryen];
buildPhase = ''
runHook preBuild
(
set -x
wasm-pack build --mode no-install
)
runHook postBuild
'';
dontCargoBuild = true;
dontCargoCheck = true;

src = ./wasm;

WASM_PACK_CACHE = "/build/cache";
nativeBuildInputs = [pkgs.rust-wasm pkgs.wasm-pack wasm-bindgen-cli pkgs.binaryen];
buildPhase = ''
runHook preBuild
(
set -x
wasm-pack build --mode no-install
)
runHook postBuild
'';
dontCargoBuild = true;
dontCargoCheck = true;

installPhase = ''
cp -r pkg $out
'';
}
installPhase = ''
cp -r pkg $out
'';
}

0 comments on commit b522666

Please sign in to comment.