forked from auxolotl/core
Compare commits
3 commits
contributo
...
main
Author | SHA1 | Date | |
---|---|---|---|
8be7956fc0 | |||
isabel roses | c13b60bc67 | ||
Julie Tyché Bettens | 9ed579059e |
28
default.nix
Normal file
28
default.nix
Normal file
|
@ -0,0 +1,28 @@
|
|||
let requiredVersion = import ./lib/minver.nix; in
|
||||
|
||||
if ! builtins ? nixVersion || builtins.compareVersions requiredVersion builtins.nixVersion == 1 then
|
||||
|
||||
abort ''
|
||||
|
||||
This version of Nixpkgs requires Nix >= ${requiredVersion}, please upgrade:
|
||||
|
||||
- If you are running NixOS, `nixos-rebuild' can be used to upgrade your system.
|
||||
|
||||
- Alternatively, with Nix > 2.0 `nix upgrade-nix' can be used to imperatively
|
||||
upgrade Nix. You may use `nix-env --version' to check which version you have.
|
||||
|
||||
- If you installed Nix using the install script (https://nixos.org/nix/install),
|
||||
it is safe to upgrade by running it again:
|
||||
|
||||
curl -L https://nixos.org/nix/install | sh
|
||||
|
||||
For more information, please see the NixOS release notes at
|
||||
https://nixos.org/nixos/manual or locally at
|
||||
${toString ./nixos/doc/manual/release-notes}.
|
||||
|
||||
If you need further help, see https://nixos.org/nixos/support.html
|
||||
''
|
||||
|
||||
else
|
||||
|
||||
import ./pkgs/top-level/impure.nix
|
45
flake.nix
45
flake.nix
|
@ -1,5 +1,46 @@
|
|||
{
|
||||
outputs = { self, ... }:
|
||||
{}
|
||||
;
|
||||
let
|
||||
forAllSystems = self.lib.genAttrs self.lib.systems.flakeExposed;
|
||||
in
|
||||
{
|
||||
lib = import ./lib;
|
||||
|
||||
auxPackages = forAllSystems (system:
|
||||
(
|
||||
let requiredVersion = import ./lib/minver.nix; in
|
||||
|
||||
if ! builtins ? nixVersion || builtins.compareVersions requiredVersion builtins.nixVersion == 1 then
|
||||
abort ''
|
||||
This version of Nixpkgs requires Nix >= ${requiredVersion}, please upgrade:
|
||||
|
||||
- If you are running NixOS, `nixos-rebuild' can be used to upgrade your system.
|
||||
|
||||
- Alternatively, with Nix > 2.0 `nix upgrade-nix' can be used to imperatively
|
||||
upgrade Nix. You may use `nix-env --version' to check which version you have.
|
||||
|
||||
- If you installed Nix using the install script (https://nixos.org/nix/install),
|
||||
it is safe to upgrade by running it again:
|
||||
|
||||
curl -L https://nixos.org/nix/install | sh
|
||||
|
||||
For more information, please see the NixOS release notes at
|
||||
https://nixos.org/nixos/manual or locally at
|
||||
${toString ./nixos/doc/manual/release-notes}.
|
||||
|
||||
If you need further help, see https://nixos.org/nixos/support.html
|
||||
''
|
||||
else
|
||||
import ./pkgs/top-level/default.nix { localSystem = system; }
|
||||
)
|
||||
);
|
||||
|
||||
legacyPackages = forAllSystems (system: import ./. { inherit system; });
|
||||
|
||||
# To test, run nix build .#tests.x86_64-linux.release
|
||||
tests = forAllSystems (system: {
|
||||
systems = import ./lib/tests/systems.nix;
|
||||
release = import ./lib/tests/release.nix { pkgs = self.auxPackages.${system}; };
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ This file evaluates to an attribute set containing two separate kinds of attribu
|
|||
Example: `lib.take` is an alias for `lib.lists.take`.
|
||||
|
||||
Most files in this directory are definitions of sub-libraries, but there are a few others:
|
||||
- [`minver.nix`](minver.nix): A string of the minimum version of Nix that is required to evaluate Nixpkgs.
|
||||
- [`tests`](tests): Tests, see [Running tests](#running-tests)
|
||||
- [`release.nix`](tests/release.nix): A derivation aggregating all tests
|
||||
- [`misc.nix`](tests/misc.nix): Evaluation unit tests for most sub-libraries
|
|
@ -2025,4 +2025,16 @@ rec {
|
|||
intersection;
|
||||
in
|
||||
(x // y) // mask;
|
||||
|
||||
# DEPRECATED
|
||||
zipWithNames = warn
|
||||
"lib.zipWithNames is a deprecated alias of lib.zipAttrsWithNames." zipAttrsWithNames;
|
||||
|
||||
# DEPRECATED
|
||||
zip = warn
|
||||
"lib.zip is a deprecated alias of lib.zipAttrsWith." zipAttrsWith;
|
||||
|
||||
# DEPRECATED
|
||||
cartesianProductOfSets = warnIf (isInOldestRelease 2405)
|
||||
"lib.cartesianProductOfSets is a deprecated alias of lib.cartesianProduct." cartesianProduct;
|
||||
}
|
171
lib/default.nix
Normal file
171
lib/default.nix
Normal file
|
@ -0,0 +1,171 @@
|
|||
/* Library of low-level helper functions for nix expressions.
|
||||
*
|
||||
* Please implement (mostly) exhaustive unit tests
|
||||
* for new functions in `./tests.nix`.
|
||||
*/
|
||||
let
|
||||
|
||||
inherit (import ./fixed-points.nix { inherit lib; }) makeExtensible;
|
||||
|
||||
lib = makeExtensible (self: let
|
||||
callLibs = file: import file { lib = self; };
|
||||
in {
|
||||
|
||||
# often used, or depending on very little
|
||||
trivial = callLibs ./trivial.nix;
|
||||
fixedPoints = callLibs ./fixed-points.nix;
|
||||
|
||||
# datatypes
|
||||
attrsets = callLibs ./attrsets.nix;
|
||||
lists = callLibs ./lists.nix;
|
||||
strings = callLibs ./strings.nix;
|
||||
stringsWithDeps = callLibs ./strings-with-deps.nix;
|
||||
|
||||
# packaging
|
||||
customisation = callLibs ./customisation.nix;
|
||||
derivations = callLibs ./derivations.nix;
|
||||
maintainers = import ../maintainers/maintainer-list.nix;
|
||||
teams = callLibs ../maintainers/team-list.nix;
|
||||
meta = callLibs ./meta.nix;
|
||||
versions = callLibs ./versions.nix;
|
||||
|
||||
# module system
|
||||
modules = callLibs ./modules.nix;
|
||||
options = callLibs ./options.nix;
|
||||
types = callLibs ./types.nix;
|
||||
|
||||
# constants
|
||||
licenses = callLibs ./licenses.nix;
|
||||
sourceTypes = callLibs ./source-types.nix;
|
||||
systems = callLibs ./systems;
|
||||
|
||||
# serialization
|
||||
cli = callLibs ./cli.nix;
|
||||
gvariant = callLibs ./gvariant.nix;
|
||||
generators = callLibs ./generators.nix;
|
||||
|
||||
# misc
|
||||
asserts = callLibs ./asserts.nix;
|
||||
debug = callLibs ./debug.nix;
|
||||
misc = callLibs ./deprecated/misc.nix;
|
||||
|
||||
# domain-specific
|
||||
fetchers = callLibs ./fetchers.nix;
|
||||
|
||||
# Eval-time filesystem handling
|
||||
path = callLibs ./path;
|
||||
filesystem = callLibs ./filesystem.nix;
|
||||
fileset = callLibs ./fileset;
|
||||
sources = callLibs ./sources.nix;
|
||||
|
||||
# back-compat aliases
|
||||
platforms = self.systems.doubles;
|
||||
|
||||
# linux kernel configuration
|
||||
kernel = callLibs ./kernel.nix;
|
||||
|
||||
inherit (builtins) add addErrorContext attrNames concatLists
|
||||
deepSeq elem elemAt filter genericClosure genList getAttr
|
||||
hasAttr head isAttrs isBool isInt isList isPath isString length
|
||||
lessThan listToAttrs pathExists readFile replaceStrings seq
|
||||
stringLength sub substring tail trace;
|
||||
inherit (self.trivial) id const pipe concat or and xor bitAnd bitOr bitXor
|
||||
bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max
|
||||
importJSON importTOML warn warnIf warnIfNot throwIf throwIfNot checkListOfEnum
|
||||
info showWarnings nixpkgsVersion version isInOldestRelease
|
||||
mod compare splitByAndCompare
|
||||
functionArgs setFunctionArgs isFunction toFunction mirrorFunctionArgs
|
||||
toHexString toBaseDigits inPureEvalMode;
|
||||
inherit (self.fixedPoints) fix fix' converge extends composeExtensions
|
||||
composeManyExtensions makeExtensible makeExtensibleWithCustomName;
|
||||
inherit (self.attrsets) attrByPath hasAttrByPath setAttrByPath
|
||||
getAttrFromPath attrVals attrValues getAttrs catAttrs filterAttrs
|
||||
filterAttrsRecursive foldlAttrs foldAttrs collect nameValuePair mapAttrs
|
||||
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
|
||||
recurseIntoAttrs dontRecurseIntoAttrs cartesianProduct cartesianProductOfSets
|
||||
mapCartesianProduct updateManyAttrsByPath;
|
||||
inherit (self.lists) singleton forEach foldr fold foldl foldl' imap0 imap1
|
||||
ifilter0 concatMap flatten remove findSingle findFirst any all count
|
||||
optional optionals toList range replicate partition zipListsWith zipLists
|
||||
reverseList listDfs toposort sort sortOn naturalSort compareLists take
|
||||
drop sublist last init crossLists unique allUnique intersectLists
|
||||
subtractLists mutuallyExclusive groupBy groupBy';
|
||||
inherit (self.strings) concatStrings concatMapStrings concatImapStrings
|
||||
intersperse concatStringsSep concatMapStringsSep
|
||||
concatImapStringsSep concatLines makeSearchPath makeSearchPathOutput
|
||||
makeLibraryPath makeIncludePath makeBinPath optionalString
|
||||
hasInfix hasPrefix hasSuffix stringToCharacters stringAsChars escape
|
||||
escapeShellArg escapeShellArgs
|
||||
isStorePath isStringLike
|
||||
isValidPosixName toShellVar toShellVars
|
||||
escapeRegex escapeURL escapeXML replaceChars lowerChars
|
||||
upperChars toLower toUpper addContextFrom splitString
|
||||
removePrefix removeSuffix versionOlder versionAtLeast
|
||||
getName getVersion
|
||||
cmakeOptionType cmakeBool cmakeFeature
|
||||
mesonOption mesonBool mesonEnable
|
||||
nameFromURL enableFeature enableFeatureAs withFeature
|
||||
withFeatureAs fixedWidthString fixedWidthNumber
|
||||
toInt toIntBase10 readPathsFromFile fileContents;
|
||||
inherit (self.stringsWithDeps) textClosureList textClosureMap
|
||||
noDepEntry fullDepEntry packEntry stringAfter;
|
||||
inherit (self.customisation) overrideDerivation makeOverridable
|
||||
callPackageWith callPackagesWith extendDerivation hydraJob
|
||||
makeScope makeScopeWithSplicing makeScopeWithSplicing';
|
||||
inherit (self.derivations) lazyDerivation optionalDrvAttr;
|
||||
inherit (self.meta) addMetaAttrs dontDistribute setName updateName
|
||||
appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
|
||||
hiPrioSet getLicenseFromSpdxId getExe getExe';
|
||||
inherit (self.filesystem) pathType pathIsDirectory pathIsRegularFile
|
||||
packagesFromDirectoryRecursive;
|
||||
inherit (self.sources) cleanSourceFilter
|
||||
cleanSource sourceByRegex sourceFilesBySuffices
|
||||
commitIdFromGitRepo cleanSourceWith pathHasContext
|
||||
canCleanSource pathIsGitRepo;
|
||||
inherit (self.modules) evalModules setDefaultModuleLocation
|
||||
unifyModuleSyntax applyModuleArgsIfFunction mergeModules
|
||||
mergeModules' mergeOptionDecls mergeDefinitions
|
||||
pushDownProperties dischargeProperties filterOverrides
|
||||
sortProperties fixupOptionType mkIf mkAssert mkMerge mkOverride
|
||||
mkOptionDefault mkDefault mkImageMediaOverride mkForce mkVMOverride
|
||||
mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions
|
||||
mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule
|
||||
mkRenamedOptionModule mkRenamedOptionModuleWith
|
||||
mkMergedOptionModule mkChangedOptionModule
|
||||
mkAliasOptionModule mkDerivedConfig doRename
|
||||
mkAliasOptionModuleMD;
|
||||
evalOptionValue = lib.warn "External use of `lib.evalOptionValue` is deprecated. If your use case isn't covered by non-deprecated functions, we'd like to know more and perhaps support your use case well, instead of providing access to these low level functions. In this case please open an issue in https://github.com/nixos/nixpkgs/issues/." self.modules.evalOptionValue;
|
||||
inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions
|
||||
mergeDefaultOption mergeOneOption mergeEqualOption mergeUniqueOption
|
||||
getValues getFiles
|
||||
optionAttrSetToDocList optionAttrSetToDocList'
|
||||
scrubOptionValue literalExpression literalExample
|
||||
showOption showOptionWithDefLocs showFiles
|
||||
unknownModule mkOption mkPackageOption mkPackageOptionMD
|
||||
mdDoc literalMD;
|
||||
inherit (self.types) isType setType defaultTypeMerge defaultFunctor
|
||||
isOptionType mkOptionType;
|
||||
inherit (self.asserts)
|
||||
assertMsg assertOneOf;
|
||||
inherit (self.debug) traceIf traceVal traceValFn
|
||||
traceSeq traceSeqN traceValSeq
|
||||
traceValSeqFn traceValSeqN traceValSeqNFn traceFnSeqN
|
||||
runTests testAllTrue;
|
||||
inherit (self.misc) maybeEnv defaultMergeArg defaultMerge foldArgs
|
||||
maybeAttrNullable maybeAttr ifEnable checkFlag getValue
|
||||
checkReqs uniqList uniqListExt condConcat lazyGenericClosure
|
||||
innerModifySumArgs modifySumArgs innerClosePropagation
|
||||
closePropagation mapAttrsFlatten nvs setAttr setAttrMerge
|
||||
mergeAttrsWithFunc mergeAttrsConcatenateValues
|
||||
mergeAttrsNoOverride mergeAttrByFunc mergeAttrsByFuncDefaults
|
||||
mergeAttrsByFuncDefaultsClean mergeAttrBy
|
||||
fakeHash fakeSha256 fakeSha512
|
||||
nixType imap;
|
||||
inherit (self.versions)
|
||||
splitVersion;
|
||||
});
|
||||
in lib
|
|
@ -8,7 +8,6 @@
|
|||
# derivation like fetchurl is allowed to do so since its result is
|
||||
# by definition pure.
|
||||
"http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy"
|
||||
"HTTP_PROXY" "HTTPS_PROXY" "FTP_PROXY" "ALL_PROXY" "NO_PROXY"
|
||||
];
|
||||
|
||||
}
|
|
@ -8,7 +8,6 @@
|
|||
# [nixpkgs]$ lib/fileset/tests.sh
|
||||
# or:
|
||||
# [nixpkgs]$ nix-build lib/tests/release.nix
|
||||
|
||||
set -euo pipefail
|
||||
shopt -s inherit_errexit dotglob
|
||||
|
309
lib/fixed-points.nix
Normal file
309
lib/fixed-points.nix
Normal file
|
@ -0,0 +1,309 @@
|
|||
{ lib, ... }:
|
||||
rec {
|
||||
/*
|
||||
`fix f` computes the fixed point of the given function `f`. In other words, the return value is `x` in `x = f x`.
|
||||
|
||||
`f` must be a lazy function.
|
||||
This means that `x` must be a value that can be partially evaluated,
|
||||
such as an attribute set, a list, or a function.
|
||||
This way, `f` can use one part of `x` to compute another part.
|
||||
|
||||
**Relation to syntactic recursion**
|
||||
|
||||
This section explains `fix` by refactoring from syntactic recursion to a call of `fix` instead.
|
||||
|
||||
For context, Nix lets you define attributes in terms of other attributes syntactically using the [`rec { }` syntax](https://nixos.org/manual/nix/stable/language/constructs.html#recursive-sets).
|
||||
|
||||
```nix
|
||||
nix-repl> rec {
|
||||
foo = "foo";
|
||||
bar = "bar";
|
||||
foobar = foo + bar;
|
||||
}
|
||||
{ bar = "bar"; foo = "foo"; foobar = "foobar"; }
|
||||
```
|
||||
|
||||
This is convenient when constructing a value to pass to a function for example,
|
||||
but an equivalent effect can be achieved with the `let` binding syntax:
|
||||
|
||||
```nix
|
||||
nix-repl> let self = {
|
||||
foo = "foo";
|
||||
bar = "bar";
|
||||
foobar = self.foo + self.bar;
|
||||
}; in self
|
||||
{ bar = "bar"; foo = "foo"; foobar = "foobar"; }
|
||||
```
|
||||
|
||||
But in general you can get more reuse out of `let` bindings by refactoring them to a function.
|
||||
|
||||
```nix
|
||||
nix-repl> f = self: {
|
||||
foo = "foo";
|
||||
bar = "bar";
|
||||
foobar = self.foo + self.bar;
|
||||
}
|
||||
```
|
||||
|
||||
This is where `fix` comes in, it contains the syntactic recursion that's not in `f` anymore.
|
||||
|
||||
```nix
|
||||
nix-repl> fix = f:
|
||||
let self = f self; in self;
|
||||
```
|
||||
|
||||
By applying `fix` we get the final result.
|
||||
|
||||
```nix
|
||||
nix-repl> fix f
|
||||
{ bar = "bar"; foo = "foo"; foobar = "foobar"; }
|
||||
```
|
||||
|
||||
Such a refactored `f` using `fix` is not useful by itself.
|
||||
See [`extends`](#function-library-lib.fixedPoints.extends) for an example use case.
|
||||
There `self` is also often called `final`.
|
||||
|
||||
Type: fix :: (a -> a) -> a
|
||||
|
||||
Example:
|
||||
fix (self: { foo = "foo"; bar = "bar"; foobar = self.foo + self.bar; })
|
||||
=> { bar = "bar"; foo = "foo"; foobar = "foobar"; }
|
||||
|
||||
fix (self: [ 1 2 (elemAt self 0 + elemAt self 1) ])
|
||||
=> [ 1 2 3 ]
|
||||
*/
|
||||
fix = f: let x = f x; in x;
|
||||
|
||||
/*
|
||||
A variant of `fix` that records the original recursive attribute set in the
|
||||
result, in an attribute named `__unfix__`.
|
||||
|
||||
This is useful in combination with the `extends` function to
|
||||
implement deep overriding.
|
||||
*/
|
||||
fix' = f: let x = f x // { __unfix__ = f; }; in x;
|
||||
|
||||
/*
|
||||
Return the fixpoint that `f` converges to when called iteratively, starting
|
||||
with the input `x`.
|
||||
|
||||
```
|
||||
nix-repl> converge (x: x / 2) 16
|
||||
0
|
||||
```
|
||||
|
||||
Type: (a -> a) -> a -> a
|
||||
*/
|
||||
converge = f: x:
|
||||
let
|
||||
x' = f x;
|
||||
in
|
||||
if x' == x
|
||||
then x
|
||||
else converge f x';
|
||||
|
||||
/*
|
||||
Extend a function using an overlay.
|
||||
|
||||
Overlays allow modifying and extending fixed-point functions, specifically ones returning attribute sets.
|
||||
A fixed-point function is a function which is intended to be evaluated by passing the result of itself as the argument.
|
||||
This is possible due to Nix's lazy evaluation.
|
||||
|
||||
|
||||
A fixed-point function returning an attribute set has the form
|
||||
|
||||
```nix
|
||||
final: { # attributes }
|
||||
```
|
||||
|
||||
where `final` refers to the lazily evaluated attribute set returned by the fixed-point function.
|
||||
|
||||
An overlay to such a fixed-point function has the form
|
||||
|
||||
```nix
|
||||
final: prev: { # attributes }
|
||||
```
|
||||
|
||||
where `prev` refers to the result of the original function to `final`, and `final` is the result of the composition of the overlay and the original function.
|
||||
|
||||
Applying an overlay is done with `extends`:
|
||||
|
||||
```nix
|
||||
let
|
||||
f = final: { # attributes };
|
||||
overlay = final: prev: { # attributes };
|
||||
in extends overlay f;
|
||||
```
|
||||
|
||||
To get the value of `final`, use `lib.fix`:
|
||||
|
||||
```nix
|
||||
let
|
||||
f = final: { # attributes };
|
||||
overlay = final: prev: { # attributes };
|
||||
g = extends overlay f;
|
||||
in fix g
|
||||
```
|
||||
|
||||
:::{.note}
|
||||
The argument to the given fixed-point function after applying an overlay will *not* refer to its own return value, but rather to the value after evaluating the overlay function.
|
||||
|
||||
The given fixed-point function is called with a separate argument than if it was evaluated with `lib.fix`.
|
||||
:::
|
||||
|
||||
:::{.example}
|
||||
|
||||
# Extend a fixed-point function with an overlay
|
||||
|
||||
Define a fixed-point function `f` that expects its own output as the argument `final`:
|
||||
|
||||
```nix-repl
|
||||
f = final: {
|
||||
# Constant value a
|
||||
a = 1;
|
||||
|
||||
# b depends on the final value of a, available as final.a
|
||||
b = final.a + 2;
|
||||
}
|
||||
```
|
||||
|
||||
Evaluate this using [`lib.fix`](#function-library-lib.fixedPoints.fix) to get the final result:
|
||||
|
||||
```nix-repl
|
||||
fix f
|
||||
=> { a = 1; b = 3; }
|
||||
```
|
||||
|
||||
An overlay represents a modification or extension of such a fixed-point function.
|
||||
Here's an example of an overlay:
|
||||
|
||||
```nix-repl
|
||||
overlay = final: prev: {
|
||||
# Modify the previous value of a, available as prev.a
|
||||
a = prev.a + 10;
|
||||
|
||||
# Extend the attribute set with c, letting it depend on the final values of a and b
|
||||
c = final.a + final.b;
|
||||
}
|
||||
```
|
||||
|
||||
Use `extends overlay f` to apply the overlay to the fixed-point function `f`.
|
||||
This produces a new fixed-point function `g` with the combined behavior of `f` and `overlay`:
|
||||
|
||||
```nix-repl
|
||||
g = extends overlay f
|
||||
```
|
||||
|
||||
The result is a function, so we can't print it directly, but it's the same as:
|
||||
|
||||
```nix-repl
|
||||
g' = final: {
|
||||
# The constant from f, but changed with the overlay
|
||||
a = 1 + 10;
|
||||
|
||||
# Unchanged from f
|
||||
b = final.a + 2;
|
||||
|
||||
# Extended in the overlay
|
||||
c = final.a + final.b;
|
||||
}
|
||||
```
|
||||
|
||||
Evaluate this using [`lib.fix`](#function-library-lib.fixedPoints.fix) again to get the final result:
|
||||
|
||||
```nix-repl
|
||||
fix g
|
||||
=> { a = 11; b = 13; c = 24; }
|
||||
```
|
||||
:::
|
||||
|
||||
Type:
|
||||
extends :: (Attrs -> Attrs -> Attrs) # The overlay to apply to the fixed-point function
|
||||
-> (Attrs -> Attrs) # A fixed-point function
|
||||
-> (Attrs -> Attrs) # The resulting fixed-point function
|
||||
|
||||
Example:
|
||||
f = final: { a = 1; b = final.a + 2; }
|
||||
|
||||
fix f
|
||||
=> { a = 1; b = 3; }
|
||||
|
||||
fix (extends (final: prev: { a = prev.a + 10; }) f)
|
||||
=> { a = 11; b = 13; }
|
||||
|
||||
fix (extends (final: prev: { b = final.a + 5; }) f)
|
||||
=> { a = 1; b = 6; }
|
||||
|
||||
fix (extends (final: prev: { c = final.a + final.b; }) f)
|
||||
=> { a = 1; b = 3; c = 4; }
|
||||
*/
|
||||
extends =
|
||||
# The overlay to apply to the fixed-point function
|
||||
overlay:
|
||||
# The fixed-point function
|
||||
f:
|
||||
# Wrap with parenthesis to prevent nixdoc from rendering the `final` argument in the documentation
|
||||
# The result should be thought of as a function, the argument of that function is not an argument to `extends` itself
|
||||
(
|
||||
final:
|
||||
let
|
||||
prev = f final;
|
||||
in
|
||||
prev // overlay final prev
|
||||
);
|
||||
|
||||
/*
|
||||
Compose two extending functions of the type expected by 'extends'
|
||||
into one where changes made in the first are available in the
|
||||
'super' of the second
|
||||
*/
|
||||
composeExtensions =
|
||||
f: g: final: prev:
|
||||
let fApplied = f final prev;
|
||||
prev' = prev // fApplied;
|
||||
in fApplied // g final prev';
|
||||
|
||||
/*
|
||||
Compose several extending functions of the type expected by 'extends' into
|
||||
one where changes made in preceding functions are made available to
|
||||
subsequent ones.
|
||||
|
||||
```
|
||||
composeManyExtensions : [packageSet -> packageSet -> packageSet] -> packageSet -> packageSet -> packageSet
|
||||
^final ^prev ^overrides ^final ^prev ^overrides
|
||||
```
|
||||
*/
|
||||
composeManyExtensions =
|
||||
lib.foldr (x: y: composeExtensions x y) (final: prev: {});
|
||||
|
||||
/*
|
||||
Create an overridable, recursive attribute set. For example:
|
||||
|
||||
```
|
||||
nix-repl> obj = makeExtensible (self: { })
|
||||
|
||||
nix-repl> obj
|
||||
{ __unfix__ = «lambda»; extend = «lambda»; }
|
||||
|
||||
nix-repl> obj = obj.extend (self: super: { foo = "foo"; })
|
||||
|
||||
nix-repl> obj
|
||||
{ __unfix__ = «lambda»; extend = «lambda»; foo = "foo"; }
|
||||
|
||||
nix-repl> obj = obj.extend (self: super: { foo = super.foo + " + "; bar = "bar"; foobar = self.foo + self.bar; })
|
||||
|
||||
nix-repl> obj
|
||||
{ __unfix__ = «lambda»; bar = "bar"; extend = «lambda»; foo = "foo + "; foobar = "foo + bar"; }
|
||||
```
|
||||
*/
|
||||
makeExtensible = makeExtensibleWithCustomName "extend";
|
||||
|
||||
/*
|
||||
Same as `makeExtensible` but the name of the extending attribute is
|
||||
customized.
|
||||
*/
|
||||
makeExtensibleWithCustomName = extenderName: rattrs:
|
||||
fix' (self: (rattrs self) // {
|
||||
${extenderName} = f: makeExtensibleWithCustomName extenderName (extends f rattrs);
|
||||
});
|
||||
}
|
|
@ -53,53 +53,6 @@ rec {
|
|||
|
||||
inherit type isGVariant;
|
||||
|
||||
intConstructors = [
|
||||
{
|
||||
name = "mkInt32";
|
||||
type = type.int32;
|
||||
min = -2147483648;
|
||||
max = 2147483647;
|
||||
}
|
||||
{
|
||||
name = "mkUint32";
|
||||
type = type.uint32;
|
||||
min = 0;
|
||||
max = 4294967295;
|
||||
}
|
||||
{
|
||||
name = "mkInt64";
|
||||
type = type.int64;
|
||||
# Nix does not support such large numbers.
|
||||
min = null;
|
||||
max = null;
|
||||
}
|
||||
{
|
||||
name = "mkUint64";
|
||||
type = type.uint64;
|
||||
min = 0;
|
||||
# Nix does not support such large numbers.
|
||||
max = null;
|
||||
}
|
||||
{
|
||||
name = "mkInt16";
|
||||
type = type.int16;
|
||||
min = -32768;
|
||||
max = 32767;
|
||||
}
|
||||
{
|
||||
name = "mkUint16";
|
||||
type = type.uint16;
|
||||
min = 0;
|
||||
max = 65535;
|
||||
}
|
||||
{
|
||||
name = "mkUchar";
|
||||
type = type.uchar;
|
||||
min = 0;
|
||||
max = 255;
|
||||
}
|
||||
];
|
||||
|
||||
/* Returns the GVariant value that most closely matches the given Nix value.
|
||||
If no GVariant value can be found unambiguously then error is thrown.
|
||||
|
||||
|
@ -117,20 +70,8 @@ rec {
|
|||
mkArray v
|
||||
else if isGVariant v then
|
||||
v
|
||||
else if builtins.isInt v then
|
||||
let
|
||||
validConstructors = builtins.filter ({ min, max, ... }: (min == null || min <= v) && (max == null || v <= max)) intConstructors;
|
||||
in
|
||||
throw ''
|
||||
The GVariant type for number “${builtins.toString v}” is unclear.
|
||||
Please wrap the value with one of the following, depending on the value type in GSettings schema:
|
||||
|
||||
${lib.concatMapStringsSep "\n" ({ name, type, ...}: "- `lib.gvariant.${name}` for `${type}`") validConstructors}
|
||||
''
|
||||
else if builtins.isAttrs v then
|
||||
throw "Cannot construct GVariant value from an attribute set. If you want to construct a dictionary, you will need to create an array containing items constructed with `lib.gvariant.mkDictionaryEntry`."
|
||||
else
|
||||
throw "The GVariant type of “${builtins.typeOf v}” can't be inferred.";
|
||||
throw "The GVariant type of ${v} can't be inferred.";
|
||||
|
||||
/* Returns the GVariant array from the given type of the elements and a Nix list.
|
||||
|
1312
lib/licenses.nix
Normal file
1312
lib/licenses.nix
Normal file
File diff suppressed because it is too large
Load diff
2
lib/minver.nix
Normal file
2
lib/minver.nix
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Expose the minimum required version for evaluating Nixpkgs
|
||||
"2.3"
|
|
@ -397,6 +397,8 @@ rec {
|
|||
if ! isString text then throw "literalExpression expects a string."
|
||||
else { _type = "literalExpression"; inherit text; };
|
||||
|
||||
literalExample = lib.warn "lib.literalExample is deprecated, use lib.literalExpression instead, or use lib.literalMD for a non-Nix description." literalExpression;
|
||||
|
||||
/* Transition marker for documentation that's already migrated to markdown
|
||||
syntax. Has been a no-op for some while and been removed from nixpkgs.
|
||||
Kept here to alert downstream users who may not be aware of the migration's
|
19
lib/source-types.nix
Normal file
19
lib/source-types.nix
Normal file
|
@ -0,0 +1,19 @@
|
|||
{ lib }:
|
||||
|
||||
let
|
||||
defaultSourceType = tname: {
|
||||
shortName = tname;
|
||||
isSource = false;
|
||||
};
|
||||
in lib.mapAttrs (tname: tset: defaultSourceType tname // tset) {
|
||||
|
||||
fromSource = {
|
||||
isSource = true;
|
||||
};
|
||||
|
||||
binaryNativeCode = {};
|
||||
|
||||
binaryBytecode = {};
|
||||
|
||||
binaryFirmware = {};
|
||||
}
|
|
@ -81,8 +81,6 @@ let
|
|||
&& final.parsed.kernel == platform.parsed.kernel;
|
||||
isCompatible = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details";
|
||||
# Derived meta-data
|
||||
useLLVM = final.isFreeBSD;
|
||||
|
||||
libc =
|
||||
/**/ if final.isDarwin then "libSystem"
|
||||
else if final.isMinGW then "msvcrt"
|
|
@ -13,7 +13,7 @@ let
|
|||
"x86_64-darwin" "i686-darwin" "aarch64-darwin" "armv7a-darwin"
|
||||
|
||||
# FreeBSD
|
||||
"i686-freebsd" "x86_64-freebsd"
|
||||
"i686-freebsd13" "x86_64-freebsd13"
|
||||
|
||||
# Genode
|
||||
"aarch64-genode" "i686-genode" "x86_64-genode"
|
|
@ -328,7 +328,7 @@ rec {
|
|||
# BSDs
|
||||
|
||||
x86_64-freebsd = {
|
||||
config = "x86_64-unknown-freebsd";
|
||||
config = "x86_64-unknown-freebsd13";
|
||||
useLLVM = true;
|
||||
};
|
||||
|
|
@ -326,7 +326,11 @@ rec {
|
|||
# the normalized name for macOS.
|
||||
macos = { execFormat = macho; families = { inherit darwin; }; name = "darwin"; };
|
||||
ios = { execFormat = macho; families = { inherit darwin; }; };
|
||||
freebsd = { execFormat = elf; families = { inherit bsd; }; name = "freebsd"; };
|
||||
# A tricky thing about FreeBSD is that there is no stable ABI across
|
||||
# versions. That means that putting in the version as part of the
|
||||
# config string is paramount.
|
||||
freebsd12 = { execFormat = elf; families = { inherit bsd; }; name = "freebsd"; version = 12; };
|
||||
freebsd13 = { execFormat = elf; families = { inherit bsd; }; name = "freebsd"; version = 13; };
|
||||
linux = { execFormat = elf; families = { }; };
|
||||
netbsd = { execFormat = elf; families = { inherit bsd; }; };
|
||||
none = { execFormat = unknown; families = { }; };
|
|
@ -432,6 +432,7 @@ runTests {
|
|||
"${builtins.storeDir}/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11";
|
||||
in {
|
||||
storePath = isStorePath goodPath;
|
||||
# storePathDerivation = isStorePath (import ../.. { system = "x86_64-linux"; }).hello;
|
||||
storePathAppendix = isStorePath
|
||||
"${goodPath}/bin/python";
|
||||
nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath)));
|
||||
|
@ -445,6 +446,7 @@ runTests {
|
|||
};
|
||||
expected = {
|
||||
storePath = true;
|
||||
# storePathDerivation = true;
|
||||
storePathAppendix = false;
|
||||
nonAbsolute = false;
|
||||
asPath = true;
|
||||
|
@ -504,6 +506,11 @@ runTests {
|
|||
expected = true;
|
||||
};
|
||||
|
||||
# testHasInfixDerivation = {
|
||||
# expr = hasInfix "hello" (import ../.. { system = "x86_64-linux"; }).hello;
|
||||
# expected = true;
|
||||
# };
|
||||
|
||||
testHasInfixPath = {
|
||||
expr = hasInfix "tests" ./.;
|
||||
expected = true;
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue