summaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-03-17 03:23:02 -0400
committerLLLL Colonq <llll@colonq>2025-03-17 03:23:02 -0400
commit9e02a3362ea7136afecbc98df219368590b061b4 (patch)
tree701b60ad2db20d505be0893e4d0fe4cc3a16b3c0 /flake.nix
parent09f04692782e3cd35fbfd0f4f1601cecd29b862c (diff)
Update flake.nix
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix159
1 files changed, 97 insertions, 62 deletions
diff --git a/flake.nix b/flake.nix
index 15c4e3d..000becc 100644
--- a/flake.nix
+++ b/flake.nix
@@ -16,78 +16,113 @@
};
outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, nixpkgs-for-wasm-bindgen, ... }:
- flake-utils.lib.eachDefaultSystem (system:
- let
- pkgs = import nixpkgs {
- inherit system;
- overlays = [ (import rust-overlay) ];
- };
+ let
+ system = "x86_64-linux";
+ pkgs = import nixpkgs {
+ inherit system;
+ overlays = [ (import rust-overlay) ];
+ };
- inherit (pkgs) lib;
+ inherit (pkgs) lib;
- rustToolchain = pkgs.rust-bin.stable.latest.default.override {
- targets = [ "wasm32-unknown-unknown" ];
- };
- craneLib = ((crane.mkLib pkgs).overrideToolchain rustToolchain).overrideScope (_final: _prev: {
- inherit (import nixpkgs-for-wasm-bindgen { inherit system; }) wasm-bindgen-cli;
- });
+ rustToolchain = pkgs.rust-bin.stable.latest.default.override {
+ targets = [ "wasm32-unknown-unknown" "x86_64-unknown-linux-gnu" ];
+ };
+ craneLib = ((crane.mkLib pkgs).overrideToolchain rustToolchain).overrideScope (_final: _prev: {
+ inherit (import nixpkgs-for-wasm-bindgen { inherit system; }) wasm-bindgen-cli;
+ });
+ src = lib.cleanSourceWith {
+ src = ./.;
+ filter = path: type:
+ (lib.hasSuffix "\.html" path) ||
+ (lib.hasSuffix "\.js" path) ||
+ (lib.hasSuffix "\.css" path) ||
+ (lib.hasInfix "/assets/" path) ||
+ (craneLib.filterCargoSources path type)
+ ;
+ };
- src = lib.cleanSourceWith {
- src = ./.;
- filter = path: type:
- (lib.hasSuffix "\.html" path) ||
- (lib.hasSuffix "\.scss" path) ||
- (lib.hasInfix "/assets/" path) ||
- (craneLib.filterCargoSources path type)
- ;
+ native = rec {
+ nativeBuildInputs = [
+ pkgs.pkg-config
+ ];
+ buildInputs = [
+ pkgs.openssl.dev
+ pkgs.glfw
+ pkgs.xorg.libX11
+ pkgs.xorg.libXcursor
+ pkgs.xorg.libXi
+ pkgs.xorg.libXrandr
+ pkgs.xorg.libXinerama
+ pkgs.libxkbcommon
+ pkgs.xorg.libxcb
+ pkgs.libglvnd
+ pkgs.alsa-lib
+ ];
+ commonArgs = {
+ inherit src nativeBuildInputs buildInputs;
+ strictDeps = true;
+ CARGO_BUILD_TARGET = "x86_64-unknown-linux-gnu";
+ inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
};
+ cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
+ doCheck = false;
+ });
+ build = nm: craneLib.buildPackage (commonArgs // {
+ inherit cargoArtifacts;
+ pname = nm;
+ cargoExtraArgs = "-p ${nm}";
+ });
+ };
+ wasm = rec {
commonArgs = {
inherit src;
strictDeps = true;
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
- buildInputs = [
- ] ++ lib.optionals pkgs.stdenv.isDarwin [
- pkgs.libiconv
- ];
+ buildInputs = [];
+ inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
+ wasm-bindgen-cli = pkgs.buildWasmBindgenCli rec {
+ src = pkgs.fetchCrate {
+ pname = "wasm-bindgen-cli";
+ version = "0.2.100";
+ hash = "sha256-3RJzK7mkYFrs7C/WkhW9Rr4LdP5ofb2FdYGz1P7Uxog=";
+ };
+ cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
+ inherit src;
+ inherit (src) pname version;
+ hash = "sha256-qsO12332HSjWCVKtf1cUePWWb9IdYUmT+8OPj/XP2WE=";
+ };
+ };
};
-
- cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
- doCheck = false;
+ build = nm: craneLib.buildTrunkPackage (commonArgs // rec {
+ pname = nm;
+ cargoExtraArgs = "-p ${nm}";
+ cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
+ inherit cargoExtraArgs;
+ doCheck = false;
+ });
+ preBuild = ''
+ cd ./crates/throwshade
+ '';
+ postBuild = ''
+ mv ./dist ../..
+ cd ../..
+ '';
});
+ };
- shell = craneLib.devShell {
- packages = [
- pkgs.trunk
- pkgs.rust-analyzer
- pkgs.glxinfo
- pkgs.alsa-lib
- pkgs.cmake
- pkgs.pkg-config
- pkgs.openssl.dev
- pkgs.glfw
- pkgs.xorg.libX11
- pkgs.xorg.libXcursor
- pkgs.xorg.libXi
- pkgs.xorg.libXrandr
- pkgs.xorg.libXinerama
- pkgs.libxkbcommon
- pkgs.xorg.libxcb
- pkgs.libglvnd
- ];
- LD_LIBRARY_PATH = "$LD_LIBRARY_PATH:${
- pkgs.lib.makeLibraryPath [
- pkgs.xorg.libX11
- pkgs.xorg.libXcursor
- pkgs.xorg.libXi
- pkgs.libxkbcommon
- pkgs.xorg.libxcb
- pkgs.libglvnd
- ]
- }";
- };
- in {
- inherit shell;
- devShells.default = shell;
- });
+ shell = craneLib.devShell {
+ packages = [
+ pkgs.trunk
+ pkgs.rust-analyzer
+ pkgs.glxinfo
+ pkgs.cmake
+ ] ++ native.nativeBuildInputs ++ native.buildInputs;
+ LD_LIBRARY_PATH = "$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath native.buildInputs}";
+ };
+ in {
+ inherit shell native wasm;
+ devShells.${system}.default = shell;
+ };
}