# Cargo.nix and crate-hashes.json were created with: # - `nix shell -f https://github.com/kolloch/crate2nix/tarball/master` # - `crate2nix generate -f ~/ref/repos/gnome/fractal/Cargo.toml` # or, once 0.11 reaches nixpkgs: # - `nix run '.#crate2nix' -- generate -f ~/ref/repos/gnome/fractal/Cargo.toml` # # then: # - `sed -i 's/target."curve25519_dalek_backend"/target."curve25519_dalek_backend" or ""/g' Cargo.nix` { pkgs , lib , stdenv , appstream-glib , buildPackages , cargo , desktop-file-utils , gdk-pixbuf , glib , gst_all_1 , gtk4 , gtksourceview5 , libadwaita , libshumate , meson , ninja , openssl , pipewire , pkg-config , rust , rustPlatform , sqlite , wrapGAppsHook4 , writeText , xdg-desktop-portal }: let # opt-level=0: builds in 1min, 105M binary # opt-level=1: builds in 2.25hr, 75M binary # opt-level=2: builds in 2.25hr # opt-level=3: builds in 2.25hr, 68-70M binary optFlags = "-C opt-level=0"; cargoNix = import ./Cargo.nix { inherit pkgs; # release = false; rootFeatures = [ ]; #< avoids --cfg feature="default", simplifying the rustc CLI so that i can pass it around easier defaultCrateOverrides = pkgs.defaultCrateOverrides // { fractal = attrs: attrs // { src = pkgs.fetchFromGitLab { domain = "gitlab.gnome.org"; owner = "GNOME"; repo = "fractal"; rev = "350a65cb0a221c70fc3e4746898036a345ab9ed8"; hash = "sha256-z6uURqMG5pT8rXZCv5IzTjXxtt/f4KUeCDSgk90aWdo="; }; codegenUnits = 256; #< this does get plumbed, but doesn't seem to affect build speed outputs = [ "out" ]; # default is "out" and "lib", but that somehow causes cycles outputDev = [ "out" ]; nativeBuildInputs = [ appstream-glib # optional, for validation desktop-file-utils # for update-desktop-database glib # for glib-compile-resources, gettext gtk4 # for gtk4-update-icon-cache meson ninja pkg-config wrapGAppsHook4 ]; buildInputs = [ glib gst_all_1.gst-plugins-bad gst_all_1.gst-plugins-base gst_all_1.gstreamer gtk4 gtksourceview5 libadwaita libshumate openssl pipewire sqlite xdg-desktop-portal ]; mesonFlags = let # this gets meson to shutup about rustc not producing executables. # kinda silly though, since we patch out the actual cargo (rustc) invocations. crossFile = writeText "cross-file.conf" '' [binaries] rust = [ 'rustc', '--target', '${rust.toRustTargetSpec stdenv.hostPlatform}' ] ''; in lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "--cross-file=${crossFile}" ]; postPatch = '' substituteInPlace src/meson.build \ --replace 'cargo_options,' "" \ --replace "cargo, 'build'," "'bash', 'crate2nix_cmd.sh'," \ --replace "'src' / rust_target" "'target/bin'" ''; postConfigure = '' # copied from mesonFlags="--prefix=$prefix $mesonFlags" mesonFlags="\ --libdir=''${!outputLib}/lib --libexecdir=''${!outputLib}/libexec \ --bindir=''${!outputBin}/bin --sbindir=''${!outputBin}/sbin \ --includedir=''${!outputInclude}/include \ --mandir=''${!outputMan}/share/man --infodir=''${!outputInfo}/share/info \ --localedir=''${!outputLib}/share/locale \ -Dauto_features=''${mesonAutoFeatures:-enabled} \ -Dwrap_mode=''${mesonWrapMode:-nodownload} \ $mesonFlags" mesonFlags="''${crossMesonFlags+$crossMesonFlags }--buildtype=''${mesonBuildType:-plain} $mesonFlags" echo "meson flags: $mesonFlags ''${mesonFlagsArray[@]}" meson setup build $mesonFlags "''${mesonFlagsArray[@]}" cd build ''; preBuild = '' build_bin() { # build_bin is what buildRustCrate would use to invoke rustc, but we want to drive the build # with meson instead. however, meson doesn't know how to plumb our rust dependencies into cargo, # so we still need to use build_bin for just one portion of the build. # # so, this mocks out the original build_bin: # - we patch upstream fractal to call our `crate2nix_cmd.sh` when it wants to compile the rust. # - we don't actually invoke meson (ninja) at all here, but rather in the `installPhase`. # if we invoked it here, the whole build would just get re-done in installPhase anyway. # # rustc invocation copied from crate_name_=fractal main_file=../src/main.rs fix_link="-C linker=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" EXTRA_RUSTC_FLAGS="$EXTRA_RUSTC_FLAGS ${optFlags}" cat >> crate2nix_cmd.sh <