mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-23 14:31:55 +03:00
feat(rust-crane): add devshell to packages
This commit is contained in:
parent
556f2e7114
commit
ddca0cecf6
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user