nix: reorganize

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-08-08 20:07:30 +05:30
parent f2bf8321cd
commit 8c101df12a
8 changed files with 221 additions and 146 deletions

18
nix/default.nix Normal file
View File

@@ -0,0 +1,18 @@
{ ... }: {
imports = [
./torana.nix
./torana-web.nix
];
perSystem = { self', pkgs, ... }: {
packages.default = self'.packages.torana;
devShells.default = pkgs.mkShell {
name = "torana-dev";
inputsFrom = with self'.devShells; [
torana
torana-web
];
};
};
}

48
nix/torana-web.nix Normal file
View File

@@ -0,0 +1,48 @@
{ ... }: {
perSystem = { pkgs, src, craneLib, toolchain, ... }:
let
commonArgs = {
inherit src;
cargoExtraArgs = "--target wasm32-unknown-unknown";
doCheck = false;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
torana = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});
in
{
packages = {
torana-web = torana;
torana-web-clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
});
torana-web-fmt = craneLib.cargoFmt {
inherit src;
};
torana-web-doc = craneLib.cargoDoc (commonArgs // {
inherit cargoArtifacts;
});
torana-web-nextest = craneLib.cargoNextest (commonArgs // {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
});
};
devShells.torana-web = pkgs.mkShell {
name = "torana-web";
nativeBuildInputs = [
pkgs.wasm-bindgen-cli
toolchain
];
};
};
}

73
nix/torana.nix Normal file
View File

@@ -0,0 +1,73 @@
{ ... }: {
perSystem = { pkgs, src, craneLib, toolchain, ... }:
let
runtimeDependencies = with pkgs; [
freetype
fontconfig
vulkan-loader
];
buildInputs = with pkgs; (with xorg; [
libX11
libXcursor
libXrandr
libXi
]) ++ [
# libxkbcommon
# wayland
];
nativeBuildInputs = with pkgs; [
cmake
openssl.dev
fontconfig.dev
pkg-config
]
++ lib.optionals (with stdenv.hostPlatform; (isx86 || isi686 || isAarch64)) [ mold ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.Cocoa ];
commonArgs = {
inherit src nativeBuildInputs buildInputs;
doCheck = false;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
torana = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts runtimeDependencies;
nativeBuildInputs = nativeBuildInputs ++ [ pkgs.autoPatchelfHook ];
});
in
{
packages = {
inherit torana;
torana-clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
});
torana-fmt = craneLib.cargoFmt {
inherit src;
};
torana-doc = craneLib.cargoDoc (commonArgs // {
inherit cargoArtifacts;
});
torana-nextest = craneLib.cargoNextest (commonArgs // {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
});
};
devShells.torana = pkgs.mkShell {
name = "torana";
nativeBuildInputs = nativeBuildInputs
++ [ toolchain ];
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath
(buildInputs ++ runtimeDependencies);
};
};
}