forked from mirrors/nixpkgs
Added self
views of the interface in makeExtensibleWithInterface
Fixing the `overrideScope` in `haskellpackages`.
This commit is contained in:
parent
8b764960e9
commit
05f9db601a
|
@ -50,28 +50,22 @@ rec {
|
||||||
}
|
}
|
||||||
else { }));
|
else { }));
|
||||||
|
|
||||||
# Like `makeOverridable`, except a `self` argument is passed to `f`,
|
# A more powerful version of `makeOverridable` with features similar
|
||||||
# which represents the fixed point result, even after using `extend`
|
# to `makeExtensibleWithInterface`.
|
||||||
# or `override`.
|
|
||||||
#
|
|
||||||
# Also, an `interface` function is taken as an argument, paralleling
|
|
||||||
# the `interface` argument to `makeExtensibleWithInterface`. This Is
|
|
||||||
# mostly useful for adding new `override` style functions,
|
|
||||||
# e.g. `overrideScope`.
|
|
||||||
makeOverridableWithInterface = interface: f: origArgs: let
|
makeOverridableWithInterface = interface: f: origArgs: let
|
||||||
|
|
||||||
addOverrideFuncs = {val, args, ...}: overridePackage:
|
addOverrideFuncs = {val, args, ...}: overridePackage:
|
||||||
(lib.optionalAttrs (builtins.isAttrs val) (val // {
|
(lib.optionalAttrs (builtins.isAttrs val) (val // {
|
||||||
extend = f: overridePackage (self: super: {
|
extend = f: overridePackage (_: self: super: {
|
||||||
val = super.val // f self.val super.val;
|
val = super.val // f self.val super.val;
|
||||||
});
|
});
|
||||||
|
|
||||||
overrideDerivation = newArgs: overridePackage (self: super: {
|
overrideDerivation = newArgs: overridePackage (_: self: super: {
|
||||||
val = lib.overrideDerivation super.val newArgs;
|
val = lib.overrideDerivation super.val newArgs;
|
||||||
});
|
});
|
||||||
|
|
||||||
${if val ? overrideAttrs then "overrideAttrs" else null} = fdrv:
|
${if val ? overrideAttrs then "overrideAttrs" else null} = fdrv:
|
||||||
overridePackage (self: super: {
|
overridePackage (_: self: super: {
|
||||||
val = super.val.overrideAttrs fdrv;
|
val = super.val.overrideAttrs fdrv;
|
||||||
});
|
});
|
||||||
})) // (lib.optionalAttrs (builtins.isFunction val) {
|
})) // (lib.optionalAttrs (builtins.isFunction val) {
|
||||||
|
@ -81,15 +75,15 @@ rec {
|
||||||
}) // {
|
}) // {
|
||||||
inherit overridePackage;
|
inherit overridePackage;
|
||||||
|
|
||||||
override = newArgs: overridePackage (self: super: {
|
override = newArgs: overridePackage (_: self: super: {
|
||||||
args = super.args //
|
args = super.args //
|
||||||
(if builtins.isFunction newArgs then newArgs super.args else newArgs);
|
(if builtins.isFunction newArgs then newArgs super.args else newArgs);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
in lib.makeExtensibleWithInterface (x: o: interface (addOverrideFuncs x o) o) (self: {
|
in lib.makeExtensibleWithInterface (x: o: interface (addOverrideFuncs x o) o) (output: self: {
|
||||||
args = origArgs;
|
args = origArgs;
|
||||||
val = f self.args self.val;
|
val = f output self.args self.val;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,35 +139,37 @@ rec {
|
||||||
it exposes a deeper structure. It provides `self` and `super`
|
it exposes a deeper structure. It provides `self` and `super`
|
||||||
views of both the arguments and return value of the function,
|
views of both the arguments and return value of the function,
|
||||||
allowing you to change both in one override; you can even have
|
allowing you to change both in one override; you can even have
|
||||||
overrides for one based on overrides for the other. The type of
|
overrides for one based on overrides for the other. It also
|
||||||
`self`, `super`, and the return value are all:
|
provides the `output` view, which is the view of `self` after
|
||||||
`{ args :: argumentsToF, val :: returnValueOfF }`
|
passing it through the `makeOverridable` interface and adding all
|
||||||
|
the `overrideX` functions. `output` is necessary when your
|
||||||
|
overrides depend on the overridable structure of `output`.
|
||||||
|
|
||||||
nix-repl> obj = makeOverridable ({a, b}: {inherit a b;}) {a = 1; b = 3;}
|
nix-repl> obj = makeOverridable ({a, b}: {inherit a b;}) {a = 1; b = 3;}
|
||||||
|
|
||||||
nix-repl> obj = obj.overridePackage (self: super: { args = super.args // {b = self.val.a;}; })
|
nix-repl> obj = obj.overridePackage (output: self: super: { args = super.args // {b = self.val.a;}; })
|
||||||
|
|
||||||
nix-repl> obj.b
|
nix-repl> obj.b
|
||||||
1
|
1
|
||||||
|
|
||||||
nix-repl> obj = obj.overridePackage (self: super: { val = super.val // {a = self.args.a + 10;}; })
|
nix-repl> obj = obj.overridePackage (output: self: super: { val = super.val // {a = self.args.a + 10;}; })
|
||||||
|
|
||||||
nix-repl> obj.b
|
nix-repl> obj.b
|
||||||
11
|
11
|
||||||
|
|
||||||
*/
|
*/
|
||||||
makeOverridable = fn: makeOverridableWithInterface (x: _: x) (args: _: fn args);
|
makeOverridable = fn: makeOverridableWithInterface (x: _: x) (_: args: _: fn args);
|
||||||
|
|
||||||
callPackageCommon = functionArgs: scope: f: args:
|
callPackageCommon = functionArgs: scope: f: args:
|
||||||
let
|
let
|
||||||
intersect = builtins.intersectAttrs functionArgs;
|
intersect = builtins.intersectAttrs functionArgs;
|
||||||
interface = val: overridePackage: val // {
|
interface = val: overridePackage: val // {
|
||||||
overrideScope = newScope: overridePackage (self: super: {
|
overrideScope = newScope: overridePackage (_: self: super: {
|
||||||
scope = super.scope.extend newScope;
|
scope = super.scope.extend newScope;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
in (makeOverridableWithInterface interface f (intersect scope // args))
|
in (makeOverridableWithInterface interface f (intersect scope // args))
|
||||||
.overridePackage (self: super: {
|
.overridePackage (output: self: super: {
|
||||||
inherit scope;
|
inherit scope;
|
||||||
# Don't use super.args because that contains the original scope.
|
# Don't use super.args because that contains the original scope.
|
||||||
args = intersect self.scope // args;
|
args = intersect self.scope // args;
|
||||||
|
@ -219,15 +215,16 @@ rec {
|
||||||
*/
|
*/
|
||||||
callPackageWith = autoArgs: fn: args:
|
callPackageWith = autoArgs: fn: args:
|
||||||
let f = if builtins.isFunction fn then fn else import fn;
|
let f = if builtins.isFunction fn then fn else import fn;
|
||||||
in callPackageCommon (builtins.functionArgs f) autoArgs (x: _: f x) args;
|
in callPackageCommon (builtins.functionArgs f) autoArgs (output: x: _: f x) args;
|
||||||
|
|
||||||
|
|
||||||
# Like `callPackageWith`, but provides the function with the `self`
|
# Like `callPackageWith`, but provides the function with a `self`
|
||||||
# argument. `fn` is called with the new `self` whenever an override
|
# view of the output, which has the override functions
|
||||||
|
# injected. `fn` is called with the new output whenever an override
|
||||||
# or extension is added.
|
# or extension is added.
|
||||||
callPackageWithSelfWith = autoArgs: fn: args:
|
callPackageWithOutputWith = autoArgs: fn: args:
|
||||||
let f = if builtins.isFunction fn then fn else import fn;
|
let f = if builtins.isFunction fn then fn else import fn;
|
||||||
in callPackageCommon (builtins.functionArgs f) autoArgs f args;
|
in callPackageCommon (builtins.functionArgs f) autoArgs (output: args: _: f args output ) args;
|
||||||
|
|
||||||
|
|
||||||
/* Like callPackage, but for a function that returns an attribute
|
/* Like callPackage, but for a function that returns an attribute
|
||||||
|
|
|
@ -71,19 +71,34 @@ rec {
|
||||||
|
|
||||||
# Same as `makeExtensible` but the name of the extending attribute is
|
# Same as `makeExtensible` but the name of the extending attribute is
|
||||||
# customized.
|
# customized.
|
||||||
makeExtensibleWithCustomName = extenderName: makeExtensibleWithInterface
|
makeExtensibleWithCustomName = extenderName: f: makeExtensibleWithInterface
|
||||||
(fixedPoint: extend: fixedPoint // { ${extenderName} = extend; });
|
(fixedPoint: extend: fixedPoint // { ${extenderName} = ext: extend (_: ext); })
|
||||||
|
(_: f);
|
||||||
|
|
||||||
# Similar to `makeExtensible`, but expects you to implement the
|
# A version of `makeExtensible` that allows the function being fixed
|
||||||
# final interface for the result. Specifically, it takes an extra
|
# to return a different interface than the interface returned to the
|
||||||
# argument: a function that takes the final result and the `extend`
|
# user. Along with `self` and `super` views of the internal
|
||||||
# function as arguments, and returns a transformed result
|
# interface, a `self` view of the output interface is also
|
||||||
# (preferably one that contains the `extend` function). This is
|
# provided. `extend` is not added to the output by default. This is
|
||||||
# mainly useful for getting to choose what to name the `extend`
|
# the job of the interface.
|
||||||
# function in the resulting attribute set. But it's also useful for
|
#
|
||||||
# having an internal structure that extensions can see, but the user
|
# nix-repl> foo = {a, b}: {c = a + b;}
|
||||||
# facing code cannot.
|
#
|
||||||
makeExtensibleWithInterface = interface: fext: interface
|
# nix-repl> interface = {args, val, ...}: extend: val // {inherit extend;}
|
||||||
(fix' fext)
|
#
|
||||||
(f: makeExtensibleWithInterface interface (extends f fext));
|
# nix-repl> obj = makeExtensibleWithInterface interface (output: self: { args = {a = 1; b = 2;}; val = foo self.args; })
|
||||||
|
#
|
||||||
|
# nix-repl> obj.c
|
||||||
|
# 3
|
||||||
|
#
|
||||||
|
# nix-repl> obj = obj.extend (output: self: super: { args = super.args // { b = output.d; }; })
|
||||||
|
#
|
||||||
|
# nix-repl> obj = obj.extend (output: self: super: { val = super.val // { d = 10; }; })
|
||||||
|
#
|
||||||
|
# nix-repl> { inherit (obj) c d; }
|
||||||
|
# { c = 11; d = 10; }
|
||||||
|
makeExtensibleWithInterface = interface: f: let i = interface
|
||||||
|
(fix' (f i))
|
||||||
|
(fext: makeExtensibleWithInterface interface (i': (extends (fext i') (f i'))));
|
||||||
|
in i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
, configurationNix ? import ./configuration-nix.nix
|
, configurationNix ? import ./configuration-nix.nix
|
||||||
}:
|
}:
|
||||||
|
|
||||||
self: # Provided by `callPackageWithSelf`
|
self: # Provided by `callPackageWithOutput`
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{ pkgs, callPackage, callPackageWithSelf, stdenv, buildPlatform, targetPlatform }:
|
{ pkgs, callPackage, callPackageWithOutput, stdenv, buildPlatform, targetPlatform }:
|
||||||
|
|
||||||
let # These are attributes in compiler and packages that don't support integer-simple.
|
let # These are attributes in compiler and packages that don't support integer-simple.
|
||||||
integerSimpleExcludes = [
|
integerSimpleExcludes = [
|
||||||
|
@ -118,79 +118,79 @@ in rec {
|
||||||
packages = {
|
packages = {
|
||||||
|
|
||||||
# Support for this compiler is broken, because it can't deal with directory-based package databases.
|
# Support for this compiler is broken, because it can't deal with directory-based package databases.
|
||||||
# ghc6104 = callPackageWithSelf ../development/haskell-modules { ghc = compiler.ghc6104; };
|
# ghc6104 = callPackageWithOutput ../development/haskell-modules { ghc = compiler.ghc6104; };
|
||||||
ghc6123 = callPackageWithSelf ../development/haskell-modules {
|
ghc6123 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc6123;
|
ghc = compiler.ghc6123;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-6.12.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-6.12.x.nix { };
|
||||||
};
|
};
|
||||||
ghc704 = callPackageWithSelf ../development/haskell-modules {
|
ghc704 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc704;
|
ghc = compiler.ghc704;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.0.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.0.x.nix { };
|
||||||
};
|
};
|
||||||
ghc722 = callPackageWithSelf ../development/haskell-modules {
|
ghc722 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc722;
|
ghc = compiler.ghc722;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.2.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.2.x.nix { };
|
||||||
};
|
};
|
||||||
ghc742 = callPackageWithSelf ../development/haskell-modules {
|
ghc742 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc742;
|
ghc = compiler.ghc742;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.4.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.4.x.nix { };
|
||||||
};
|
};
|
||||||
ghc763 = callPackageWithSelf ../development/haskell-modules {
|
ghc763 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc763;
|
ghc = compiler.ghc763;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.6.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.6.x.nix { };
|
||||||
};
|
};
|
||||||
ghc783 = callPackageWithSelf ../development/haskell-modules {
|
ghc783 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc783;
|
ghc = compiler.ghc783;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.8.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.8.x.nix { };
|
||||||
};
|
};
|
||||||
ghc784 = callPackageWithSelf ../development/haskell-modules {
|
ghc784 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc784;
|
ghc = compiler.ghc784;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.8.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.8.x.nix { };
|
||||||
};
|
};
|
||||||
ghc7102 = callPackageWithSelf ../development/haskell-modules {
|
ghc7102 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc7102;
|
ghc = compiler.ghc7102;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.10.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.10.x.nix { };
|
||||||
};
|
};
|
||||||
ghc7103 = callPackageWithSelf ../development/haskell-modules {
|
ghc7103 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc7103;
|
ghc = compiler.ghc7103;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.10.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.10.x.nix { };
|
||||||
};
|
};
|
||||||
ghc801 = callPackageWithSelf ../development/haskell-modules {
|
ghc801 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc801;
|
ghc = compiler.ghc801;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.0.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.0.x.nix { };
|
||||||
};
|
};
|
||||||
ghc802 = callPackageWithSelf ../development/haskell-modules {
|
ghc802 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc802;
|
ghc = compiler.ghc802;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.0.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.0.x.nix { };
|
||||||
};
|
};
|
||||||
ghc821 = callPackageWithSelf ../development/haskell-modules {
|
ghc821 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc821;
|
ghc = compiler.ghc821;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.2.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.2.x.nix { };
|
||||||
};
|
};
|
||||||
ghcHEAD = callPackageWithSelf ../development/haskell-modules {
|
ghcHEAD = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghcHEAD;
|
ghc = compiler.ghcHEAD;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-head.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-head.nix { };
|
||||||
};
|
};
|
||||||
# TODO Support for multiple variants here
|
# TODO Support for multiple variants here
|
||||||
ghcCross = callPackageWithSelf ../development/haskell-modules {
|
ghcCross = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghcHEAD.crossCompiler;
|
ghc = compiler.ghcHEAD.crossCompiler;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-head.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-head.nix { };
|
||||||
};
|
};
|
||||||
ghcCross821 = callPackageWithSelf ../development/haskell-modules {
|
ghcCross821 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghc821.crossCompiler;
|
ghc = compiler.ghc821.crossCompiler;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.2.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.2.x.nix { };
|
||||||
};
|
};
|
||||||
ghcjs = callPackageWithSelf ../development/haskell-modules {
|
ghcjs = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghcjs;
|
ghc = compiler.ghcjs;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.10.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-7.10.x.nix { };
|
||||||
packageSetConfig = callPackage ../development/haskell-modules/configuration-ghcjs.nix { };
|
packageSetConfig = callPackage ../development/haskell-modules/configuration-ghcjs.nix { };
|
||||||
};
|
};
|
||||||
ghcjsHEAD = callPackageWithSelf ../development/haskell-modules {
|
ghcjsHEAD = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghcjsHEAD;
|
ghc = compiler.ghcjsHEAD;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.0.x.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.0.x.nix { };
|
||||||
packageSetConfig = callPackage ../development/haskell-modules/configuration-ghcjs.nix { };
|
packageSetConfig = callPackage ../development/haskell-modules/configuration-ghcjs.nix { };
|
||||||
};
|
};
|
||||||
ghcHaLVM240 = callPackageWithSelf ../development/haskell-modules {
|
ghcHaLVM240 = callPackageWithOutput ../development/haskell-modules {
|
||||||
ghc = compiler.ghcHaLVM240;
|
ghc = compiler.ghcHaLVM240;
|
||||||
compilerConfig = callPackage ../development/haskell-modules/configuration-halvm-2.4.0.nix { };
|
compilerConfig = callPackage ../development/haskell-modules/configuration-halvm-2.4.0.nix { };
|
||||||
};
|
};
|
||||||
|
|
|
@ -79,11 +79,11 @@ in
|
||||||
# `newScope' for sets of packages in `pkgs' (see e.g. `gnome' below).
|
# `newScope' for sets of packages in `pkgs' (see e.g. `gnome' below).
|
||||||
callPackage = pkgs.newScope {};
|
callPackage = pkgs.newScope {};
|
||||||
|
|
||||||
callPackageWithSelf = pkgs.newScopeWithSelf {};
|
callPackageWithOutput = pkgs.newScopeWithOutput {};
|
||||||
|
|
||||||
callPackages = lib.callPackagesWith splicedPackages;
|
callPackages = lib.callPackagesWith splicedPackages;
|
||||||
|
|
||||||
newScope = extra: lib.callPackageWith (splicedPackages // extra);
|
newScope = extra: lib.callPackageWith (splicedPackages // extra);
|
||||||
|
|
||||||
newScopeWithSelf = extra: lib.callPackageWithSelfWith (splicedPackages // extra);
|
newScopeWithOutput = extra: lib.callPackageWithOutputWith (splicedPackages // extra);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue