feat(rust-crane): add devshell to packages

This commit is contained in:
Yusuf Bera Ertan 2023-09-05 14:59:18 +03:00 committed by DavHau
parent 556f2e7114
commit ddca0cecf6
3 changed files with 12 additions and 58 deletions

View File

@ -127,6 +127,7 @@
# common args we use for both buildDepsOnly and buildPackage # common args we use for both buildDepsOnly and buildPackage
common = { common = {
src = lib.mkForce (utils.getRootSource pname version);
postUnpack = '' postUnpack = ''
export CARGO_HOME=$(pwd)/.cargo_home export CARGO_HOME=$(pwd)/.cargo_home
export cargoVendorDir="$TMPDIR/nix-vendor" export cargoVendorDir="$TMPDIR/nix-vendor"
@ -154,7 +155,6 @@
# The deps-only derivation will use this as a prefix to the `pname` # The deps-only derivation will use this as a prefix to the `pname`
depsNameSuffix = "-deps"; depsNameSuffix = "-deps";
depsArgs = { depsArgs = {
src = config.mkDerivation.src;
preUnpack = '' preUnpack = ''
${vendoring.copyVendorDir "$dream2nixVendorDir" common.cargoVendorDir} ${vendoring.copyVendorDir "$dream2nixVendorDir" common.cargoVendorDir}
''; '';
@ -195,7 +195,6 @@ in {
rust-crane.depsDrv = { rust-crane.depsDrv = {
inherit version; inherit version;
name = pname + depsNameSuffix; name = pname + depsNameSuffix;
mkDerivation = builtins.removeAttrs config.mkDerivation ["src"];
package-func.func = crane.buildDepsOnly; package-func.func = crane.buildDepsOnly;
package-func.args = l.mkMerge [ package-func.args = l.mkMerge [
common common
@ -207,6 +206,12 @@ in {
package-func.args = l.mkMerge [common buildArgs]; package-func.args = l.mkMerge [common buildArgs];
public = { 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; dependencies = cfg.depsDrv.public;
meta = utils.getMeta pname version; meta = utils.getMeta pname version;
}; };
@ -232,6 +237,8 @@ in {
runCommand runCommand
writeText writeText
fetchFromGitHub fetchFromGitHub
libiconv
mkShell
; ;
inherit inherit
(nixpkgs.writers) (nixpkgs.writers)

View File

@ -6,6 +6,7 @@
lib, lib,
libiconv, libiconv,
mkShell, mkShell,
stdenv,
... ...
}: let }: let
l = lib // builtins; l = lib // builtins;
@ -51,7 +52,7 @@
then v then v
else null else null
) )
drv.drvAttrs drv.config.mkDerivation
); );
combineEnvs = envs: combineEnvs = envs:
l.foldl' l.foldl'
@ -78,4 +79,4 @@
passthru.env = _shellEnv; passthru.env = _shellEnv;
}; };
in in
(mkShell.override {stdenv = (l.head drvs).stdenv;}) shellEnv (mkShell.override {stdenv = (l.head drvs).config.mkDerivation.stdenv or stdenv;}) shellEnv

View File

@ -13,41 +13,6 @@
}: let }: let
l = lib // builtins; l = lib // builtins;
isInPackages = name: version: (packages.${name} or null) == version; 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 { in rec {
getMeta = pname: version: let getMeta = pname: version: let
meta = subsystemAttrs.meta.${pname}.${version}; meta = subsystemAttrs.meta.${pname}.${version};
@ -86,25 +51,6 @@ in rec {
${replace} ${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 # Backup original Cargo.lock if it exists and write our own one
writeCargoLock = '' writeCargoLock = ''
mv -f Cargo.lock Cargo.lock.orig || echo "no Cargo.lock" mv -f Cargo.lock Cargo.lock.orig || echo "no Cargo.lock"