Skip to content

Conversation

@damccull
Copy link
Contributor

@damccull damccull commented Aug 8, 2025

Using the latest build of dx on nix or nixos is difficult because of the package manager requirements and the differing ELF interpreter requirements. You would either need to take an existing bin and run patchelf on it to change the expected location of the ELF interpreter. Either that or we need to build from source.

This change to the flake.nix adds a package output for the dx bin that allows it to be built from source and included directly into another flake as an input.

Included here is a partial framework of the flake I generally use (per project) for rust development, and shows how you can reference this flake in the inputs and then 'install' the dx client in the 'devDeps' such that it is included in the devShell.

{
  inputs = {
    nixpkgs = {
      url = "github:nixos/nixpkgs/nixos-unstable";
    };
    flake-parts.url = "github:hercules-ci/flake-parts";
    dioxus-cli-gh.url = "github:damccull/dioxus?ref=Add-nix-flake";
  };
  outputs =
    inputs:
    inputs.flake-parts.lib.mkFlake { inherit inputs; } {
      systems = [ "x86_64-linux" ];
      perSystem =
        {
          config,
          self',
          pkgs,
          lib,
          system,
          ...
        }:
        let
          dioxusDeps = with pkgs; [
            atkmm
            cairo
            fontconfig
            fribidi
            gdk-pixbuf
            glib
            glib-networking
            gtk3
            gsettings-desktop-schemas # Doesn't fix appimage bundle issue
            harfbuzz
            freetype
            libdrm
            libGL
            libgpg-error
            libsoup_3
            mesa
            openssl
            wrapGAppsHook
            webkitgtk_4_1
            xdotool
            xorg.libX11
            xorg.libxcb
            zlib
            sqlite
          ];

          runtimeDeps = with pkgs; [
          ];

          buildDeps =
            with pkgs;
            [
              clang
              lld
              lldb
              pkg-config
              rustPlatform.bindgenHook
              stdenv.cc.cc.lib
              (wasm-bindgen-cli.overrideAttrs (oldAttrs: rec {
                version = "0.2.100";
                src = fetchCrate {
                  pname = "wasm-bindgen-cli";
                  version = version;
                  hash = "sha256-3RJzK7mkYFrs7C/WkhW9Rr4LdP5ofb2FdYGz1P7Uxog=";
                };

                cargoDeps = rustPlatform.fetchCargoVendor {
                  inherit src;
                  inherit (src) pname version;
                  hash = "sha256-qsO12332HSjWCVKtf1cUePWWb9IdYUmT+8OPj/XP2WE=";
                };
              }))
            ]
            ++ dioxusDeps;

          devDeps =
            with pkgs;
            [
              # Libraries and programs needed for dev work; included in dev shell
              # NOT included in the nix build operation
              bashInteractive
              cargo-edit
              cargo-expand
              cargo-msrv
              gdb
              tailwindcss
              zellij
            ]
            ++ [
              inputs.dioxus-cli-gh.packages.${system}.dioxus-cli
            ];

          cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
          msrv = cargoToml.package.rust-version;

          rustPackage =
            features:
            (pkgs.makeRustPlatform {
              cargo = pkgs.rust-bin.stable.latest.minimal;
              rustc = pkgs.rust-bin.stable.latest.minimal;
            }).buildRustPackage
              {
                inherit (cargoToml.package) name version;
                src = ./.;
                cargoLock.lockFile = ./Cargo.lock;
                buildFeatures = features;
                buildInputs = runtimeDeps;
                nativeBuildInputs = buildDeps;
                # Uncomment if your cargo tests require networking or otherwise
                # don't play nicely with the nix build sandbox:
                # doCheck = false;
              };

          ldpath =
            with pkgs;
            [
              stdenv.cc.cc.lib
            ]
            ++ dioxusDeps;

          mkDevShell =
            rustc:
            pkgs.mkShell {
              shellHook = ''
                exec env SHELL=${pkgs.bashInteractive}/bin/bash zellij --layout ./zellij_layout.kdl
              '';
              LD_LIBRARY_PATH = lib.makeLibraryPath ldpath;
              GIO_MODULE_DIR = "${pkgs.glib-networking}/lib/gio/modules/";

              RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
              buildInputs = runtimeDeps;
              nativeBuildInputs = buildDeps ++ devDeps ++ [ rustc ];
            };

          rustTargets = [
            "x86_64-unknown-linux-gnu"
            "x86_64-linux-android"
            "aarch64-linux-android"
            "wasm32-unknown-unknown"
          ];

          rustExtensions = [
            "rust-analyzer"
            "rust-src"
          ];
        in
        {

          _module.args.pkgs = import inputs.nixpkgs {
            inherit system;
            overlays = [ (import inputs.rust-overlay) ];
            config = {};
          };

          packages.default = self'.packages.base;
          devShells.default = self'.devShells.stable;

          packages.base = (rustPackage "");

          devShells.stable = (
            mkDevShell (
              pkgs.rust-bin.stable.latest.default.override {
                extensions = rustExtensions;
                targets = rustTargets;
              }
            )
          );
        };
    };
}

@damccull damccull requested a review from a team as a code owner August 8, 2025 01:16
@jkelleyrtp jkelleyrtp merged commit 871998e into DioxusLabs:main Aug 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants