# Cargo.nix and crate-hashes.json were created with: # - `nix run '.#crate2nix' -- generate -f ~/ref/repos/gnome/fractal/Cargo.toml` # or, for latest crate2nix: # - `nix shell -f https://github.com/kolloch/crate2nix/tarball/master` # - `crate2nix generate -f ~/ref/repos/gnome/fractal/Cargo.toml` # # note that serde_derive fails for cross compilation. pin to 1.0.171. # - see: # - sounds like serde-derive did eventually remove the "precompiled" blobs # - 1.0.183: fails # - 1.0.192: seems to work? # # to update: # - `git fetch` in `~/ref/repos/gnome/fractal/` # - re-run that crate2nix step # - update `src` rev to match the local checkout! # # 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 , fetchFromGitHub , gdk-pixbuf , glib , gst_all_1 , gtk4 , gtksourceview5 , libadwaita , libshumate , meson , ninja , openssl , pipewire , pkg-config , rust , rustPlatform , sqlite , wrapGAppsHook4 , writeText , xdg-desktop-portal , optimize ? true }: let mkConfigured = { optimize }: let # `optimize` option applies only to the top-level build; not fractal's dependencies. # as of 2023/10/29: # - 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 # as of 2023/10/30: # - opt-level=3: builds in 5min, 71M binary optFlags = if optimize then "-C opt-level=3" else "-C opt-level=0"; extraCrateOverrides = { fractal = attrs: attrs // { src = pkgs.fetchFromGitLab { domain = "gitlab.gnome.org"; owner = "GNOME"; repo = "fractal"; rev = "5"; hash = "sha256-XHb8HjQ5PDL2sen6qUivDllvYEhKnp1vQynD2Lksi30="; # rev = "ba15c5b12a3cdb67b57d6a1ce7c4a2e6a15f8c88"; # hash = "sha256-BZC/otMPM4pf/VOhFkgRrq6yEquChL3I9QsQVpFMakQ="; }; 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.gst-plugins-good 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}" ]; # patch so meson will invoke our `crate2nix_cmd.sh` instead of cargo 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 <