Skip to content

Commit

Permalink
Merge remote-tracking branch 'other/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 28, 2024
2 parents 31a9902 + 734091e commit d15f6f6
Showing 21 changed files with 2,388 additions and 651 deletions.
126 changes: 114 additions & 12 deletions lib/attrsets.nix
Original file line number Diff line number Diff line change
@@ -1764,6 +1764,7 @@ rec {
/**
Get a package output.
If no output is found, fallback to `.out` and then to the default.
The function is idempotent: `getOutput "b" (getOutput "a" p) == getOutput "a" p`.
# Inputs
@@ -1779,15 +1780,15 @@ rec {
# Type
```
getOutput :: String -> Derivation -> String
getOutput :: String -> :: Derivation -> Derivation
```
# Examples
:::{.example}
## `lib.attrsets.getOutput` usage example
```nix
getOutput "dev" pkgs.openssl
"${getOutput "dev" pkgs.openssl}"
=> "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-dev"
```
@@ -1798,6 +1799,49 @@ rec {
then pkg.${output} or pkg.out or pkg
else pkg;

/**
Get the first of the `outputs` provided by the package, or the default.
This function is alligned with `_overrideFirst()` from the `multiple-outputs.sh` setup hook.
Like `getOutput`, the function is idempotent.
# Inputs
`outputs`
: 1\. Function argument
`pkg`
: 2\. Function argument
# Type
```
getFirstOutput :: [String] -> Derivation -> Derivation
```
# Examples
:::{.example}
## `lib.attrsets.getFirstOutput` usage example
```nix
"${getFirstOutput [ "include" "dev" ] pkgs.openssl}"
=> "/nix/store/00000000000000000000000000000000-openssl-1.0.1r-dev"
```
:::
*/
getFirstOutput =
candidates: pkg:
let
outputs = builtins.filter (name: hasAttr name pkg) candidates;
output = builtins.head outputs;
in
if pkg.outputSpecified or false || outputs == [ ] then
pkg
else
pkg.${output};

/**
Get a package's `bin` output.
If the output does not exist, fallback to `.out` and then to the default.
@@ -1811,16 +1855,16 @@ rec {
# Type
```
getBin :: Derivation -> String
getBin :: Derivation -> Derivation
```
# Examples
:::{.example}
## `lib.attrsets.getBin` usage example
```nix
getBin pkgs.openssl
=> "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r"
"${getBin pkgs.openssl}"
=> "/nix/store/00000000000000000000000000000000-openssl-1.0.1r"
```
:::
@@ -1841,22 +1885,51 @@ rec {
# Type
```
getLib :: Derivation -> String
getLib :: Derivation -> Derivation
```
# Examples
:::{.example}
## `lib.attrsets.getLib` usage example
```nix
getLib pkgs.openssl
"${getLib pkgs.openssl}"
=> "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-lib"
```
:::
*/
getLib = getOutput "lib";

/**
Get a package's `static` output.
If the output does not exist, fallback to `.lib`, then to `.out`, and then to the default.
# Inputs
`pkg`
: The package whose `static` output will be retrieved.
# Type
```
getStatic :: Derivation -> Derivation
```
# Examples
:::{.example}
## `lib.attrsets.getStatic` usage example
```nix
"${lib.getStatic pkgs.glibc}"
=> "/nix/store/00000000000000000000000000000000-glibc-2.39-52-static"
```
:::
*/
getStatic = getFirstOutput [ "static" "lib" "out" ];


/**
Get a package's `dev` output.
@@ -1871,22 +1944,51 @@ rec {
# Type
```
getDev :: Derivation -> String
getDev :: Derivation -> Derivation
```
# Examples
:::{.example}
## `lib.attrsets.getDev` usage example
```nix
getDev pkgs.openssl
"${getDev pkgs.openssl}"
=> "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-dev"
```
:::
*/
getDev = getOutput "dev";

/**
Get a package's `include` output.
If the output does not exist, fallback to `.dev`, then to `.out`, and then to the default.
# Inputs
`pkg`
: The package whose `include` output will be retrieved.
# Type
```
getInclude :: Derivation -> Derivation
```
# Examples
:::{.example}
## `lib.attrsets.getInclude` usage example
```nix
"${getInclude pkgs.openssl}"
=> "/nix/store/00000000000000000000000000000000-openssl-1.0.1r-dev"
```
:::
*/
getInclude = getFirstOutput [ "include" "dev" "out" ];


/**
Get a package's `man` output.
@@ -1901,15 +2003,15 @@ rec {
# Type
```
getMan :: Derivation -> String
getMan :: Derivation -> Derivation
```
# Examples
:::{.example}
## `lib.attrsets.getMan` usage example
```nix
getMan pkgs.openssl
"${getMan pkgs.openssl}"
=> "/nix/store/9rz8gxhzf8sw4kf2j2f1grr49w8zx5vj-openssl-1.0.1r-man"
```
@@ -1929,7 +2031,7 @@ rec {
# Type
```
chooseDevOutputs :: [Derivation] -> [String]
chooseDevOutputs :: [Derivation] -> [Derivation]
```
*/
chooseDevOutputs = builtins.map getDev;
8 changes: 4 additions & 4 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -86,8 +86,8 @@ let
mapAttrs' mapAttrsToList attrsToList concatMapAttrs mapAttrsRecursive
mapAttrsRecursiveCond genAttrs isDerivation toDerivation optionalAttrs
zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil
recursiveUpdate matchAttrs mergeAttrsList overrideExisting showAttrPath getOutput
getBin getLib getDev getMan chooseDevOutputs zipWithNames zip
recursiveUpdate matchAttrs mergeAttrsList overrideExisting showAttrPath getOutput getFirstOutput
getBin getLib getStatic getDev getInclude getMan chooseDevOutputs zipWithNames zip
recurseIntoAttrs dontRecurseIntoAttrs cartesianProduct cartesianProductOfSets
mapCartesianProduct updateManyAttrsByPath listToAttrs hasAttr getAttr isAttrs intersectAttrs removeAttrs;
inherit (self.lists) singleton forEach map foldr fold foldl foldl' imap0 imap1
@@ -105,7 +105,7 @@ let
hasInfix hasPrefix hasSuffix stringToCharacters stringAsChars escape
escapeShellArg escapeShellArgs
isStorePath isStringLike
isValidPosixName toShellVar toShellVars
isValidPosixName toShellVar toShellVars trim trimWith
escapeRegex escapeURL escapeXML replaceChars lowerChars
upperChars toLower toUpper addContextFrom splitString
removePrefix removeSuffix versionOlder versionAtLeast
@@ -123,7 +123,7 @@ let
inherit (self.derivations) lazyDerivation optionalDrvAttr;
inherit (self.meta) addMetaAttrs dontDistribute setName updateName
appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
hiPrioSet getLicenseFromSpdxId getExe getExe';
hiPrioSet getLicenseFromSpdxId getLicenseFromSpdxIdOr getExe getExe';
inherit (self.filesystem) pathType pathIsDirectory pathIsRegularFile
packagesFromDirectoryRecursive;
inherit (self.sources) cleanSourceFilter
5 changes: 3 additions & 2 deletions lib/deprecated/misc.nix
Original file line number Diff line number Diff line change
@@ -29,9 +29,10 @@ let
nameValuePair
tail
toList
warn
;

inherit (lib.attrsets) removeAttrs;
inherit (lib.attrsets) removeAttrs mapAttrsToList;

# returns default if env var is not set
maybeEnv = name: default:
@@ -212,7 +213,7 @@ let
else closePropagationSlow;

# calls a function (f attr value ) for each record item. returns a list
mapAttrsFlatten = f: r: map (attr: f attr r.${attr}) (attrNames r);
mapAttrsFlatten = warn "lib.misc.mapAttrsFlatten is deprecated, please use lib.attrsets.mapAttrsToList instead." mapAttrsToList;

# attribute set containing one attribute
nvs = name: value: listToAttrs [ (nameValuePair name value) ];
2 changes: 1 addition & 1 deletion lib/fileset/README.md
Original file line number Diff line number Diff line change
@@ -236,7 +236,7 @@ File sets cannot add single files to the store, they can only import files under
Arguments:
- (+) There's no point in using this library for a single file, since you can't do anything other than add it to the store or not.
And it would be unclear how the library should behave if the one file wouldn't be added to the store:
`toSource { root = ./file.nix; fileset = <empty>; }` has no reasonable result because returing an empty store path wouldn't match the file type, and there's no way to have an empty file store path, whatever that would mean.
`toSource { root = ./file.nix; fileset = <empty>; }` has no reasonable result because returning an empty store path wouldn't match the file type, and there's no way to have an empty file store path, whatever that would mean.

### `fileFilter` takes a path

46 changes: 25 additions & 21 deletions lib/licenses.nix
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
{ lib }:

lib.mapAttrs (lname: lset: let
defaultLicense = {
shortName = lname;
free = true; # Most of our licenses are Free, explicitly declare unfree additions as such!
deprecated = false;
};

mkLicense = licenseDeclaration: let
applyDefaults = license: defaultLicense // license;
applySpdx = license:
if license ? spdxId
then license // { url = "https://spdx.org/licenses/${license.spdxId}.html"; }
else license;
applyRedistributable = license: { redistributable = license.free; } // license;
in lib.pipe licenseDeclaration [
applyDefaults
applySpdx
applyRedistributable
];
in mkLicense lset) ({
let
inherit (lib) optionalAttrs;

mkLicense = lname: {
shortName ? lname,
# Most of our licenses are Free, explicitly declare unfree additions as such!
free ? true,
deprecated ? false,
spdxId ? null,
url ? null,
fullName ? null,
redistributable ? free
}@attrs: {
inherit shortName free deprecated redistributable;
} // optionalAttrs (attrs ? spdxId) {
inherit spdxId;
url = "https://spdx.org/licenses/${spdxId}.html";
} // optionalAttrs (attrs ? url) {
inherit url;
} // optionalAttrs (attrs ? fullName) {
inherit fullName;
};

in
lib.mapAttrs mkLicense ({
/* License identifiers from spdx.org where possible.
* If you cannot find your license here, then look for a similar license or
* add it to this list. The URL mentioned above is a good source for inspiration.
Loading

0 comments on commit d15f6f6

Please sign in to comment.