From ddca0cecf6dc28cba903d9060988f5c19f3edeef Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Tue, 5 Sep 2023 14:59:18 +0300 Subject: [PATCH] feat(rust-crane): add devshell to packages --- modules/dream2nix/rust-crane/default.nix | 11 ++++- modules/dream2nix/rust-crane/devshell.nix | 5 ++- modules/dream2nix/rust-crane/utils.nix | 54 ----------------------- 3 files changed, 12 insertions(+), 58 deletions(-) diff --git a/modules/dream2nix/rust-crane/default.nix b/modules/dream2nix/rust-crane/default.nix index 43b369a7..941030d2 100644 --- a/modules/dream2nix/rust-crane/default.nix +++ b/modules/dream2nix/rust-crane/default.nix @@ -127,6 +127,7 @@ # common args we use for both buildDepsOnly and buildPackage common = { + src = lib.mkForce (utils.getRootSource pname version); postUnpack = '' export CARGO_HOME=$(pwd)/.cargo_home export cargoVendorDir="$TMPDIR/nix-vendor" @@ -154,7 +155,6 @@ # The deps-only derivation will use this as a prefix to the `pname` depsNameSuffix = "-deps"; depsArgs = { - src = config.mkDerivation.src; preUnpack = '' ${vendoring.copyVendorDir "$dream2nixVendorDir" common.cargoVendorDir} ''; @@ -195,7 +195,6 @@ in { rust-crane.depsDrv = { inherit version; name = pname + depsNameSuffix; - mkDerivation = builtins.removeAttrs config.mkDerivation ["src"]; package-func.func = crane.buildDepsOnly; package-func.args = l.mkMerge [ common @@ -207,6 +206,12 @@ in { package-func.args = l.mkMerge [common buildArgs]; public = { + devShell = import ./devshell.nix { + name = "${pname}-devshell"; + drvs = [cfg.depsDrv.public config.public]; + inherit lib; + inherit (config.deps) libiconv mkShell stdenv; + }; dependencies = cfg.depsDrv.public; meta = utils.getMeta pname version; }; @@ -232,6 +237,8 @@ in { runCommand writeText fetchFromGitHub + libiconv + mkShell ; inherit (nixpkgs.writers) diff --git a/modules/dream2nix/rust-crane/devshell.nix b/modules/dream2nix/rust-crane/devshell.nix index e1e890c9..7ece3d38 100644 --- a/modules/dream2nix/rust-crane/devshell.nix +++ b/modules/dream2nix/rust-crane/devshell.nix @@ -6,6 +6,7 @@ lib, libiconv, mkShell, + stdenv, ... }: let l = lib // builtins; @@ -51,7 +52,7 @@ then v else null ) - drv.drvAttrs + drv.config.mkDerivation ); combineEnvs = envs: l.foldl' @@ -78,4 +79,4 @@ passthru.env = _shellEnv; }; in - (mkShell.override {stdenv = (l.head drvs).stdenv;}) shellEnv + (mkShell.override {stdenv = (l.head drvs).config.mkDerivation.stdenv or stdenv;}) shellEnv diff --git a/modules/dream2nix/rust-crane/utils.nix b/modules/dream2nix/rust-crane/utils.nix index 6c777b97..678c7413 100644 --- a/modules/dream2nix/rust-crane/utils.nix +++ b/modules/dream2nix/rust-crane/utils.nix @@ -13,41 +13,6 @@ }: let l = lib // builtins; isInPackages = name: version: (packages.${name} or null) == version; - # a make overridable for rust derivations specifically - makeOverridable = f: origArgs: let - result = f origArgs; - - # Creates a functor with the same arguments as f - copyArgs = g: l.setFunctionArgs g (l.functionArgs f); - # Changes the original arguments with (potentially a function that returns) a set of new attributes - overrideWith = newArgs: - origArgs - // ( - if l.isFunction newArgs - then newArgs origArgs - else newArgs - ); - - # Re-call the function but with different arguments - overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs)); - # Change the result of the function call by applying g to it - overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs; - in - result.derivation - // { - override = args: - overrideArgs { - args = - origArgs.args - // ( - if l.isFunction args - then args origArgs.args - else args - ); - }; - overrideRustToolchain = f: overrideArgs {toolchain = f origArgs.toolchain;}; - overrideAttrs = fdrv: overrideResult (x: {derivation = x.derivation.overrideAttrs fdrv;}); - }; in rec { getMeta = pname: version: let meta = subsystemAttrs.meta.${pname}.${version}; @@ -86,25 +51,6 @@ in rec { ${replace} ''; - mkBuildWithToolchain = mkBuildFunc: let - buildWithToolchain = args: - makeOverridable - (args: { - derivation = - (mkBuildFunc args.toolchain) - ( - args.args - // { - passthru = - (args.args.passthru or {}) - // {rustToolchain = args.toolchain;}; - } - ); - }) - args; - in - buildWithToolchain; - # Backup original Cargo.lock if it exists and write our own one writeCargoLock = '' mv -f Cargo.lock Cargo.lock.orig || echo "no Cargo.lock"