diff --git a/nix/default.nix b/nix/default.nix index f5b7da0234..53b8f93ea8 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -21,7 +21,7 @@ let else builtins.fetchGit { name = "common-sources"; url = "ssh://git@github.com/dfinity-lab/common"; - rev = "bbf39c31e08b4ab7db82f799a3e3c693a0fdced6"; + rev = "b35ba23941c5f3b555eba33c144f2cf9e5036cfb"; }; in import commonSrc { inherit system crossSystem config; diff --git a/nix/overlays/dfinity-sdk.nix b/nix/overlays/dfinity-sdk.nix index 2af387da4f..ff8a6df315 100644 --- a/nix/overlays/dfinity-sdk.nix +++ b/nix/overlays/dfinity-sdk.nix @@ -1,23 +1,21 @@ self: super: let mkRelease = super.callPackage ./mk-release.nix {}; - + rust-package' = super.callPackage ../rust-workspace.nix {}; + # remove some stuff leftover by callPackage + rust-package = removeAttrs rust-package' + [ "override" "overrideDerivation" ]; + rust-workspace = rust-package.build; in { dfinity-sdk = rec { - packages = rec { + packages = + # remove the shell since it's being built below in "shells" + removeAttrs rust-package [ "shell" ] // rec { + inherit rust-workspace; + rust-workspace-debug = rust-package.debug; js-user-library = super.callPackage ../../js-user-library/package.nix { inherit (self) napalm; }; - rust-workspace = super.callPackage ../rust-workspace.nix {}; - rust-workspace-debug = (rust-workspace.override (_: { - release = false; - doClippy = true; - doFmt = true; - doDoc = true; - })).overrideAttrs (oldAttrs: { - name = "${oldAttrs.name}-debug"; - }); - rust-workspace-doc = rust-workspace-debug.doc; rust-workspace-standalone = super.lib.standaloneRust { drv = rust-workspace; @@ -136,7 +134,7 @@ in { # of all the shells here. shells = { js-user-library = import ../../js-user-library/shell.nix { pkgs = self; }; - rust-workspace = import ../rust-shell.nix { pkgs = self; }; + rust-workspace = import ../rust-shell.nix { pkgs = self; shell = rust-package.shell; }; }; licenses = { diff --git a/nix/rust-shell.nix b/nix/rust-shell.nix index cd2d5ca562..a00dd0969c 100644 --- a/nix/rust-shell.nix +++ b/nix/rust-shell.nix @@ -1,21 +1,9 @@ -{ pkgs ? (import ./. {}).pkgs }: +{ pkgs ? (import ./. {}).pkgs, shell }: pkgs.mkCompositeShell { name = "dfinity-sdk-rust-env"; buildInputs = [pkgs.rls]; - inputsFrom = [ - - (pkgs.dfinity-sdk.packages.rust-workspace-debug.overrideAttrs (oldAttrs: { - # _oldAttrs.configurePhase refers to the dfinity-application-and-others-deps - # derivation which is the build of all 3rd-party Rust dependencies. Since in this - # nix-shell we use cargo locally to build all dependencies we don't need to depend - # on this derivation saving a lot of time downloading/building. - configurePhase = ""; - - # for some odd reason this is needed in the shell: - # https://dfinity.atlassian.net/browse/INF-542 - nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.stdenv.cc ]; - })) ]; - + nativeBuildInputs = [ pkgs.stdenv.cc ]; + inputsFrom = [ shell ]; shellHook = '' # Set CARGO_HOME to minimize interaction with any environment outside nix export CARGO_HOME=${pkgs.lib.dfinityRoot}/.cargo-home diff --git a/nix/rust-workspace.nix b/nix/rust-workspace.nix index db221c92a8..ea88d3dacb 100644 --- a/nix/rust-workspace.nix +++ b/nix/rust-workspace.nix @@ -1,8 +1,4 @@ -{ release ? true -, doClippy ? false -, doFmt ? false -, doDoc ? false -, motoko +{ motoko , buildDfinityRustPackage , cargo-graph , darwin @@ -15,7 +11,7 @@ , dfinity-sdk }: let - drv = buildDfinityRustPackage { + workspace = buildDfinityRustPackage { name = "dfinity-sdk-rust"; srcDir = ../.; regexes = [ @@ -26,35 +22,43 @@ let ".*Cargo\.lock$" "^.cargo/config$" ]; - inherit release doClippy doFmt doDoc; }; -in -drv.overrideAttrs (oldAttrs: { - DFX_ASSETS = runCommandNoCC "dfx-assets" {} '' - mkdir -p $out - cp ${dfinity.nodemanager}/bin/nodemanager $out - cp ${dfinity.ic-client}/bin/client $out - cp ${motoko.moc-bin}/bin/moc $out - cp ${motoko.mo-ide}/bin/mo-ide $out - cp ${motoko.didc}/bin/didc $out - cp ${motoko.rts}/rts/mo-rts.wasm $out - mkdir $out/stdlib && cp -R ${motoko.stdlib}/. $out/stdlib - mkdir $out/js-user-library && cp -R ${dfinity-sdk.packages.js-user-library}/. $out/js-user-library - ''; + workspace' = (workspace // + { lint = workspace.lint.overrideAttrs (oldAttrs: { + nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ + cargo-graph + graphviz + ]; - nativeBuildInputs = oldAttrs.nativeBuildInputs ++ lib.optionals doDoc [ - cargo-graph - graphviz - ]; + postDoc = oldAttrs.postDoc + '' + pushd dfx + cargo graph | dot -Tsvg > ../target/doc/dfx/cargo-graph.svg + popd + ''; - postDoc = oldAttrs.postDoc + '' - pushd dfx - cargo graph | dot -Tsvg > ../target/doc/dfx/cargo-graph.svg - popd - ''; + postInstall = oldAttrs.postInstall + '' + echo "report cargo-graph-dfx $doc dfx/cargo-graph.svg" >> \ + $doc/nix-support/hydra-build-products + ''; + }); + }); +in - postInstall = oldAttrs.postInstall + lib.optionalString doDoc '' - echo "report cargo-graph-dfx $doc dfx/cargo-graph.svg" >> \ - $doc/nix-support/hydra-build-products - ''; -}) +# override all derivations and add DFX_ASSETS as an environment variable +(lib.mapAttrs (k: drv: + if !lib.isDerivation drv then drv else + drv.overrideAttrs (_: { + DFX_ASSETS = runCommandNoCC "dfx-assets" {} '' + mkdir -p $out + cp ${dfinity.nodemanager}/bin/nodemanager $out + cp ${dfinity.ic-client}/bin/client $out + cp ${motoko.moc-bin}/bin/moc $out + cp ${motoko.mo-ide}/bin/mo-ide $out + cp ${motoko.didc}/bin/didc $out + cp ${motoko.rts}/rts/mo-rts.wasm $out + mkdir $out/stdlib && cp -R ${motoko.stdlib}/. $out/stdlib + mkdir $out/js-user-library && cp -R ${dfinity-sdk.packages.js-user-library}/. $out/js-user-library + ''; + }) +) workspace') +(throw "this argument is used to trigger the functor and shouldn't actually be evaluated.")