Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splice.nix: inherit from lib #341067

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkgs/development/interpreters/python/cpython/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ let
pythonVersion = with sourceVersion; "${major}.${minor}";
sitePackages = "lib/${libPrefix}/site-packages";
inherit hasDistutilsCxxPatch pythonAttr;
pythonOnBuildForBuild = override pkgsBuildBuild.${pythonAttr};
pythonOnBuildForHost = override pkgsBuildHost.${pythonAttr};
pythonOnBuildForTarget = override pkgsBuildTarget.${pythonAttr};
pythonOnHostForHost = override pkgsHostHost.${pythonAttr};
pythonOnTargetForTarget = lib.optionalAttrs (lib.hasAttr pythonAttr pkgsTargetTarget) (override pkgsTargetTarget.${pythonAttr});
pythonOnBuildForBuild = pkgsBuildBuild.${pythonAttr};
pythonOnBuildForHost = pkgsBuildHost.${pythonAttr};
pythonOnBuildForTarget = pkgsBuildTarget.${pythonAttr};
pythonOnHostForHost = pkgsHostHost.${pythonAttr};
pythonOnTargetForTarget = lib.optionalAttrs (lib.hasAttr pythonAttr pkgsTargetTarget) (pkgsTargetTarget.${pythonAttr});
};

version = with sourceVersion; "${major}.${minor}.${patch}${suffix}";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18237,7 +18237,7 @@ with pkgs;

nixosOptionsDoc = attrs:
(import ../../nixos/lib/make-options-doc)
({ inherit pkgs lib; } // attrs);
({ inherit lib; pkgs = pkgs.__splicedPackages; } // attrs);

nix-eval-jobs = callPackage ../tools/package-management/nix-eval-jobs {
nix = nixVersions.nix_2_25;
Expand Down
4 changes: 3 additions & 1 deletion pkgs/top-level/impure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ assert args ? system -> !(args ? localSystem);

import ./. (builtins.removeAttrs args [ "system" ] // {
inherit config overlays localSystem;
})
} // (if ((localSystem.system or localSystem) == "x86_64-linux") then {
crossSystem = { config = "aarch64-unknown-linux-gnu"; };
} else {}) )
2 changes: 0 additions & 2 deletions pkgs/top-level/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ let
jobs.vim.x86_64-darwin
jobs.inkscape.x86_64-darwin
jobs.qt5.qtmultimedia.x86_64-darwin
jobs.darwin.linux-builder.x86_64-darwin
/*
jobs.tests.cc-wrapper.default.x86_64-darwin
jobs.tests.cc-wrapper.llvmPackages.clang.x86_64-darwin
Expand All @@ -270,7 +269,6 @@ let
jobs.vim.aarch64-darwin
jobs.inkscape.aarch64-darwin
jobs.qt5.qtmultimedia.aarch64-darwin
jobs.darwin.linux-builder.aarch64-darwin
/* consider adding tests, as suggested above for x86_64-darwin */
];
};
Expand Down
66 changes: 41 additions & 25 deletions pkgs/top-level/splice.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@
# For performance reasons, rather than uniformally splice in all cases, we only
# do so when `pkgs` and `buildPackages` are distinct. The `actuallySplice`
# parameter there the boolean value of that equality check.
lib: pkgs: actuallySplice:

lib:
let
inherit (lib)
attrByPath
callPackageWith
callPackagesWith
genAttrs
isAttrs
isDerivation
listToAttrs
makeScopeWithSplicing
makeScopeWithSplicing'
optional
optionalAttrs
splitString
;
Artturin marked this conversation as resolved.
Show resolved Hide resolved
in
pkgs: actuallySplice:

let
spliceReal =
{ pkgsBuildBuild
, pkgsBuildHost
Expand Down Expand Up @@ -47,12 +63,12 @@ let
augmentedValue = defaultValue
// {
__spliced =
(lib.optionalAttrs (pkgsBuildBuild ? ${name}) { buildBuild = valueBuildBuild; })
// (lib.optionalAttrs (pkgsBuildHost ? ${name}) { buildHost = valueBuildHost; })
// (lib.optionalAttrs (pkgsBuildTarget ? ${name}) { buildTarget = valueBuildTarget; })
// (lib.optionalAttrs (pkgsHostHost ? ${name}) { hostHost = valueHostHost; })
// (lib.optionalAttrs (pkgsHostTarget ? ${name}) { hostTarget = valueHostTarget; })
// (lib.optionalAttrs (pkgsTargetTarget ? ${name}) {
(optionalAttrs (pkgsBuildBuild ? ${name}) { buildBuild = valueBuildBuild; })
// (optionalAttrs (pkgsBuildHost ? ${name}) { buildHost = valueBuildHost; })
// (optionalAttrs (pkgsBuildTarget ? ${name}) { buildTarget = valueBuildTarget; })
// (optionalAttrs (pkgsHostHost ? ${name}) { hostHost = valueHostHost; })
// (optionalAttrs (pkgsHostTarget ? ${name}) { hostTarget = valueHostTarget; })
// (optionalAttrs (pkgsTargetTarget ? ${name}) {
targetTarget = valueTargetTarget;
});
};
Expand All @@ -63,22 +79,22 @@ let
let
inherit (builtins.tryEval value0) success value;
in
getOutputs (lib.optionalAttrs success value);
getOutputs = value: lib.genAttrs
(value.outputs or (lib.optional (value ? out) "out"))
getOutputs (optionalAttrs success value);
getOutputs = value: genAttrs
(value.outputs or (optional (value ? out) "out"))
(output: value.${output});
in
# The derivation along with its outputs, which we recur
# on to splice them together.
if lib.isDerivation defaultValue then augmentedValue // spliceReal {
if isDerivation defaultValue then augmentedValue // spliceReal {
pkgsBuildBuild = tryGetOutputs valueBuildBuild;
pkgsBuildHost = tryGetOutputs valueBuildHost;
pkgsBuildTarget = tryGetOutputs valueBuildTarget;
pkgsHostHost = tryGetOutputs valueHostHost;
pkgsHostTarget = getOutputs valueHostTarget;
pkgsTargetTarget = tryGetOutputs valueTargetTarget;
# Just recur on plain attrsets
} else if lib.isAttrs defaultValue then
} else if isAttrs defaultValue then
spliceReal
{
pkgsBuildBuild = valueBuildBuild;
Expand All @@ -92,7 +108,7 @@ let
} else defaultValue;
};
in
lib.listToAttrs (map merge (lib.attrNames mash));
listToAttrs (map merge (lib.attrNames mash));

splicePackages =
{ pkgsBuildBuild
Expand Down Expand Up @@ -147,13 +163,13 @@ in
# `newScope' for sets of packages in `pkgs' (see e.g. `gnome' below).
callPackage = pkgs.newScope { };

callPackages = lib.callPackagesWith pkgsForCall;
callPackages = callPackagesWith pkgsForCall;

newScope = extra: lib.callPackageWith (pkgsForCall // extra);
newScope = extra: callPackageWith (pkgsForCall // extra);

# prefill 2 fields of the function for convenience
makeScopeWithSplicing = lib.makeScopeWithSplicing splicePackages pkgs.newScope;
makeScopeWithSplicing' = lib.makeScopeWithSplicing' { inherit splicePackages; inherit (pkgs) newScope; };
makeScopeWithSplicing = makeScopeWithSplicing splicePackages pkgs.newScope;
makeScopeWithSplicing' = makeScopeWithSplicing' { inherit splicePackages; inherit (pkgs) newScope; };

# generate 'otherSplices' for 'makeScopeWithSplicing'
generateSplicesForMkScope = attrs:
Expand All @@ -162,18 +178,18 @@ in
if builtins.isList attrs
then attrs
else if builtins.isString attrs
then lib.splitString "." attrs
then splitString "." attrs
else throw "generateSplicesForMkScope must be passed a list of string or string"
);
bad = throw "attribute should be found";
in
{
selfBuildBuild = lib.attrByPath (split "pkgsBuildBuild") bad pkgs;
selfBuildHost = lib.attrByPath (split "pkgsBuildHost") bad pkgs;
selfBuildTarget = lib.attrByPath (split "pkgsBuildTarget") bad pkgs;
selfHostHost = lib.attrByPath (split "pkgsHostHost") bad pkgs;
selfHostTarget = lib.attrByPath (split "pkgsHostTarget") bad pkgs;
selfTargetTarget = lib.attrByPath (split "pkgsTargetTarget") { } pkgs;
selfBuildBuild = attrByPath (split "pkgsBuildBuild") bad pkgs;
selfBuildHost = attrByPath (split "pkgsBuildHost") bad pkgs;
selfBuildTarget = attrByPath (split "pkgsBuildTarget") bad pkgs;
selfHostHost = attrByPath (split "pkgsHostHost") bad pkgs;
selfHostTarget = attrByPath (split "pkgsHostTarget") bad pkgs;
selfTargetTarget = attrByPath (split "pkgsTargetTarget") { } pkgs;
};

# Haskell package sets need this because they reimplement their own
Expand Down
Loading