freebsd: Only export a limited number of attributes to top-level

This commit is contained in:
Audrey Dutcher 2024-05-02 09:00:36 -07:00 committed by John Ericson
parent da9c1825bc
commit d5972ed69f
4 changed files with 91 additions and 95 deletions

View File

@ -1,39 +0,0 @@
{
lib,
config,
freebsdBranches,
freebsdBranchesCross,
}:
let
branch =
let
fallbackBranch = "release/13.1.0";
envBranch = builtins.getEnv "NIXPKGS_FREEBSD_BRANCH";
selectedBranch =
if config.freebsdBranch != null then
config.freebsdBranch
else if envBranch != "" then
envBranch
else
null;
chosenBranch = if selectedBranch != null then selectedBranch else fallbackBranch;
in
if freebsdBranches ? ${chosenBranch} then
chosenBranch
else
throw ''
Unknown FreeBSD branch ${chosenBranch}!
FreeBSD branches normally look like one of:
* `release/<major>.<minor>.0` for tagged releases without security updates
* `releng/<major>.<minor>` for release update branches with security updates
* `stable/<major>` for stable versions working towards the next minor release
* `main` for the latest development version
Set one with the NIXPKGS_FREEBSD_BRANCH environment variable or by setting `nixpkgs.config.freebsdBranch`.
'';
in
{
freebsd = freebsdBranches.${branch};
freebsdCross = freebsdBranchesCross.${branch};
}

View File

@ -0,0 +1,87 @@
{
lib,
config,
makeScopeWithSplicing',
generateSplicesForMkScope,
callPackage,
crossLibcStdenv,
}:
let
versions = builtins.fromJSON (builtins.readFile ./versions.json);
badBranchError =
branch:
throw ''
Unknown FreeBSD branch ${branch}!
FreeBSD branches normally look like one of:
* `release/<major>.<minor>.0` for tagged releases without security updates
* `releng/<major>.<minor>` for release update branches with security updates
* `stable/<major>` for stable versions working towards the next minor release
* `main` for the latest development version
Set one with the NIXPKGS_FREEBSD_BRANCH environment variable or by setting `nixpkgs.config.freebsdBranch`.
'';
attributes =
let
supported13 = "release/13.1.0";
supported14 = "release/14.0.0";
branch =
let
fallbackBranch = supported13;
envBranch = builtins.getEnv "NIXPKGS_FREEBSD_BRANCH";
selectedBranch =
if config.freebsdBranch != null then
config.freebsdBranch
else if envBranch != "" then
envBranch
else
null;
chosenBranch = if selectedBranch != null then selectedBranch else fallbackBranch;
in
chosenBranch;
in
{
freebsd = versions.${branch} or (badBranchError branch);
freebsd13 = versions.${supported13} or (badBranchError supported13);
freebsd14 = versions.${supported14} or (badBranchError supported14);
};
# `./package-set.nix` should never know the name of the package set we
# are constructing; just this function is allowed to know that. This
# is why we:
#
# - do the splicing for cross compilation here
#
# - construct the *anonymized* `buildFreebsd` attribute to be passed
# to `./package-set.nix`.
callFreeBSDWithAttrs =
extraArgs: attribute: sourceData:
let
otherSplices = generateSplicesForMkScope [ attribute ];
in
makeScopeWithSplicing' {
inherit otherSplices;
f = callPackage ./package-set.nix (
{
buildFreebsd = otherSplices.selfBuildHost;
inherit sourceData;
versionData = sourceData.version;
patchesRoot = ./patches/${sourceData.version.revision};
}
// extraArgs
);
};
exportedAttrSetsNative = lib.mapAttrs (callFreeBSDWithAttrs { }) attributes;
exportedAttrSetsCross = lib.mapAttrs' (
name: sourceData:
lib.nameValuePair (name + "Cross") (
callFreeBSDWithAttrs { stdenv = crossLibcStdenv; } name sourceData
)
) attributes;
in
exportedAttrSetsNative // exportedAttrSetsCross

View File

@ -1,46 +0,0 @@
{
lib,
config,
makeScopeWithSplicing',
generateSplicesForMkScope,
callPackage,
crossLibcStdenv,
}:
let
versions = builtins.fromJSON (builtins.readFile ./versions.json);
# `./package-set.nix` should never know the name of the package set we
# are constructing; just this function is allowed to know that. This
# is why we:
#
# - do the splicing for cross compilation here
#
# - construct the *anonymized* `buildFreebsd` attribute to be passed
# to `./package-set.nix`.
callFreeBSDWithAttrs =
extraArgs: branch: sourceData:
let
otherSplices = generateSplicesForMkScope [
"freebsdBranches"
branch
];
in
makeScopeWithSplicing' {
inherit otherSplices;
f = callPackage ./package-set.nix (
{
buildFreebsd = otherSplices.selfBuildHost;
inherit sourceData;
versionData = sourceData.version;
patchesRoot = ./patches/${sourceData.version.revision};
}
// extraArgs
);
};
in
{
freebsdBranches = lib.mapAttrs (callFreeBSDWithAttrs { }) versions;
freebsdBranchesCross = lib.mapAttrs (callFreeBSDWithAttrs { stdenv = crossLibcStdenv; }) versions;
}

View File

@ -40910,16 +40910,10 @@ with pkgs;
name = "bsd-setup-hook";
} ../os-specific/bsd/setup-hook.sh;
inherit (callPackage ../os-specific/bsd/freebsd/versions.nix {}) freebsdBranches freebsdBranchesCross;
freebsd13 = freebsdBranches."release/13.2.0";
freebsd14 = freebsdBranches."release/14.0.0";
freebsdGit = freebsdBranches.main;
freebsd13Cross = freebsdBranchesCross."release/13.0.0";
freebsd14Cross = freebsdBranchesCross."release/14.0.0";
freebsdGitCross = freebsdBranchesCross.main;
inherit (callPackage ../os-specific/bsd/freebsd/default-branch.nix {}) freebsd freebsdCross;
inherit (callPackage ../os-specific/bsd/freebsd {})
freebsd freebsdCross
freebsd13 freebsd13Cross
freebsd14 freebsd14Cross;
netbsd = callPackage ../os-specific/bsd/netbsd { };
netbsdCross = callPackage ../os-specific/bsd/netbsd {