alper
September 19, 2023, 7:06am
1
I had to compare a bunch of online examples and copy paste stuff here and there to get dioxus-cli to compile:
# flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
rust-overlay,
flake-utils, ...
}: flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay)];
pkgs = import nixpkgs {
inherit system overlays;
};
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./toolchain.toml;
in
{
devShells.default = pkgs.mkShell {
packages = [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.CoreServices
pkgs.zlib
toolchain
];
};
}
);
}
Toolchain contains:
[toolchain]
channel = "nightly"
profile = "default"
targets = ["wasm32-unknown-unknown", "aarch64-apple-darwin"]
That was a relatively bad experience and it set back my development here back by at least 30-45 minutes.
Then I found out that the cli is in nixpkgs, so for that I needn’t have bothered (but might need the same dependencies for developing anyway?).
Did you find anything?
I USED
let
nixpkgs = fetchTarball "https://github.com/nixos/nixpkgs/archive/nixpkgs-unstable.tar.gz";
rust-overlay-url = fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz";
pkgs = import nixpkgs {
overlays = [ (import rust-overlay-url) ];
system = builtins.currentSystem;
};
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
"rust-analyzer"
"clippy"
];
};
rustBuildInputs = [
pkgs.openssl
pkgs.libiconv
pkgs.pkg-config
] ++ [
pkgs.mesa
pkgs.libgbm
pkgs.libglvnd
pkgs.xorg.libXi
pkgs.xorg.libXrandr
pkgs.xorg.libX11
]++ pkgs.lib.optionals pkgs.stdenv.isLinux [
pkgs.glib
pkgs.gtk3
pkgs.libsoup_3
pkgs.webkitgtk_4_1
pkgs.xdotool
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
IOKit
Carbon
WebKit
Security
Cocoa
]);
dioxusCli = pkgs.rustPlatform.buildRustPackage rec {
pname = "dioxus-cli";
version = "0.5.7";
src = pkgs.fetchCrate {
inherit pname version;
hash = "sha256-/LeMh5WX4dvkveu5w6qBQLbtoi5yUW6iad0YatA/tMQ=";
};
cargoHash = "sha256-D6y2NiFqSf0u6icSKCRZK7ycR+GswOX627M7PEy/D6U=";
nativeBuildInputs = [ pkgs.pkg-config pkgs.cacert ];
buildInputs = [ pkgs.openssl ] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
pkgs.darwin.apple_sdk.frameworks.CoreServices
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];
OPENSSL_NO_VENDOR = 1;
nativeCheckInputs = [ pkgs.rustfmt ];
checkFlags = [
# requires network access
"--skip=server::web::proxy::test::add_proxy"
"--skip=server::web::proxy::test::add_proxy_trailing_slash"
];
passthru = {
updateScript = pkgs.nix-update-script { };
tests.version = pkgs.testers.testVersion { package = dioxusCli; };
};
meta = with pkgs.lib; {
homepage = "https://dioxuslabs.com";
description = "CLI tool for developing, testing, and publishing Dioxus apps";
license = with licenses; [ mit asl20 ];
maintainers = with maintainers; [ xanderio cathalmullan ];
mainProgram = "dx";
};
};
in pkgs.mkShell {
name = "dioxus-dev";
buildInputs = rustBuildInputs ++ [ dioxusCli ];
nativeBuildInputs = [
rustToolchain
];
shellHook = ''
# For rust-analyzer 'hover' tooltips to work.
export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library";
'';
}
But i get an error building or running the project
mmuenn
February 10, 2025, 9:43am
3
I’ve seen this error before when using dioxus-cli 0.5.7 with newish rust versions (>1.82 I guess).
Here’s the github issue: https://github.com/DioxusLabs/dioxus/issues/3034 .
Should be fine if you use dioxus-cli 0.6.0 or an older rust toolchain.
1 Like
I have nixos. I created a nix flake for dioxus.
The dioxus cli works.
dx serve --platform android --device true
But it fails openning on android mobile
Error:
Caused by:
Failed to assemble apk: Output { status: ExitStatus(unix_wait_status(256)), stdout: "\n> Confi
gure project :app\nWARNING: The option setting ‘android.defaults.buildfeatures.buildconfig=true’ i
s deprecated.\nThe current default is ‘false’.
and
The SDK directory is not writable
Can somebody help with the issue or the steps to open diouxs in my android phone.
my flake nix
{
description = "Dioxus Android dev environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
config = {
allowUnfree = true;
android_sdk.accept_license = true;
};
};
# All possible Android targets
androidTargets = [
"aarch64-linux-android" # 64-bit ARM
"armv7-linux-androideabi" # 32-bit ARM
"i686-linux-android" # 32-bit x86
"x86_64-linux-android" # 64-bit x86
# "riscv64-linux-android" # RISC-V (Android 12+)
];
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
"rust-std"
"clippy"
"rust-analyzer"
"rustfmt"
];
targets = ["wasm32-unknown-unknown"] ++ androidTargets;
};
androidPkgs = pkgs.androidenv.composeAndroidPackages {
platformVersions = [ "34" ];
buildToolsVersions = [ "35.0.0" ];
includeNDK = true;
ndkVersions = [ "25.2.9519653" ];
abiVersions = [ "arm64-v8a" "armeabi-v7a" ];
includeEmulator = false;
};
dioxusCli = pkgs.rustPlatform.buildRustPackage rec {
pname = "dioxus-cli";
version = "0.6.3";
src = pkgs.fetchCrate {
inherit pname version;
hash = "sha256-wuIJq+UN1q5qYW4TXivq93C9kZiPHwBW5Ty2Vpik2oY=";
};
cargoHash = "sha256-L9r/nJj0Rz41mg952dOgKxbDS5u4zGEjSA3EhUHfGIk=";
nativeBuildInputs = [ pkgs.pkg-config pkgs.cacert pkgs.rustfmt ];
buildInputs = [ pkgs.openssl ];
OPENSSL_NO_VENDOR = 1;
};
in {
devShells.default = pkgs.mkShell {
name = "dioxus-android-dev";
buildInputs = [
rustToolchain
dioxusCli
androidPkgs.androidsdk
pkgs.openjdk
];
shellHook = ''
export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library"
export SDK_CACHE_DIR="$HOME/.android-sdk"
export NDK_VERSION="25.2.9519653"
if [ ! -d "$SDK_CACHE_DIR" ]; then
echo "[→] Copying Android SDK to writable directory..."
cp -r ${androidPkgs.androidsdk}/libexec/android-sdk "$SDK_CACHE_DIR"
fi
export ANDROID_SDK_ROOT="$SDK_CACHE_DIR"
export ANDROID_NDK_HOME="$SDK_CACHE_DIR/ndk/$NDK_VERSION"
export ANDROID_HOME="$SDK_CACHE_DIR"
export JAVA_HOME="${pkgs.jdk}/lib/openjdk"
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"
echo "[→] Accepting licenses..."
yes | "$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" --licenses || true
echo "[→] Ensuring android-33 and build-tools 34.0.0 are installed..."
"$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" \
"platforms;android-33" \
"build-tools;34.0.0" || true
BUILD_GRADLE="$PWD/.dioxus/platforms/android/app/build.gradle"
if [ -f "$BUILD_GRADLE" ] && ! grep -q "buildConfig true" "$BUILD_GRADLE"; then
echo "[→] Patching build.gradle to enable buildConfig"
sed -i '/android {/a\ buildFeatures {\n buildConfig true\n }' "$BUILD_GRADLE"
fi
echo "[✔] Dioxus Android shell is ready. Run: dx serve --platform android"
'';
};
});
}