dioxus.nix
1 { 2 lib, 3 pkgs, 4 config, 5 inputs, 6 ... 7 }: 8 let 9 pkgs-unstable = import inputs.nixpkgs-unstable { system = pkgs.stdenv.system; }; 10 dioxus = config.languages.rust.dioxus; 11 in 12 { 13 options.languages.rust.dioxus = { 14 enable = lib.mkEnableOption "Dioxus (Rust) development stack"; 15 desktop.linux.enable = lib.mkEnableOption "Dioxus desktop stack for GNU/Linux (glib, atk, gtk, webkitgtk, openssl, etc.)."; 16 mobile.android.enable = lib.mkEnableOption "Dioxus mobile stack for Android (SDK+NDK+Emulator+Studio + Rust targets)."; 17 18 extraPackages = lib.mkOption { 19 type = lib.types.listOf lib.types.package; 20 default = [ ]; 21 description = "Extra packages to add when Dioxus stack is enabled."; 22 }; 23 24 extraTargets = lib.mkOption { 25 type = lib.types.listOf lib.types.str; 26 default = [ ]; 27 description = "Extra rust targets to add when Dioxus stack is enabled."; 28 }; 29 }; 30 31 config = lib.mkIf dioxus.enable { 32 assertions = [ 33 { 34 assertion = (!dioxus.desktop.linux.enable) || pkgs.stdenv.isLinux; 35 message = "languages.rust.dioxus.desktop.linux.enable is true, but this system is not Linux. Disable it (or make it conditional) on Darwin/other platforms."; 36 } 37 ]; 38 39 packages = 40 (with pkgs-unstable; [ 41 binaryen 42 dioxus-cli 43 tailwindcss_4 44 cargo-binstall 45 # FIXME: nixpkgs behind on latest 46 # use `cargo binstall wasm-bindgen-cli@0.2.116` 47 ]) 48 ++ lib.optionals pkgs.stdenv.isLinux ( 49 with pkgs-unstable; 50 [ 51 openssl 52 ] 53 ) 54 ++ lib.optionals (dioxus.desktop.linux.enable && pkgs.stdenv.isLinux) ( 55 with pkgs-unstable; 56 [ 57 atk 58 glib 59 file 60 cairo 61 pango 62 xdotool 63 librsvg 64 gdk-pixbuf 65 pkg-config 66 webkitgtk_4_1 67 libappindicator-gtk3 68 ] 69 ) 70 ++ dioxus.extraPackages; 71 72 languages.rust.targets = [ 73 "wasm32-unknown-unknown" 74 ] 75 ++ lib.optionals dioxus.mobile.android.enable [ 76 "i686-linux-android" 77 "x86_64-linux-android" 78 "aarch64-linux-android" 79 "armv7-linux-androideabi" 80 ] 81 ++ dioxus.extraTargets; 82 83 android = lib.mkIf dioxus.mobile.android.enable { 84 enable = true; 85 ndk.enable = true; 86 emulator.enable = true; 87 android-studio.enable = true; 88 }; 89 }; 90 }