Skip to content

Commit

Permalink
Merge master into haskell-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Dec 12, 2023
2 parents 0b8c1b3 + 3df2965 commit e1f9606
Show file tree
Hide file tree
Showing 338 changed files with 3,522 additions and 2,276 deletions.
3 changes: 1 addition & 2 deletions doc/languages-frameworks/rust.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ repository:
lib.updateManyAttrsByPath [{
path = [ "packages" "stable" ];
update = old: old.overrideScope(final: prev: {
rustc = prev.rustc.overrideAttrs (_: {
rustc-unwrapped = prev.rustc-unwrapped.overrideAttrs (_: {
src = lib.cleanSource /git/scratch/rust;
# do *not* put passthru.isReleaseTarball=true here
});
Expand Down Expand Up @@ -1003,4 +1003,3 @@ nix-build $NIXPKGS -A package-broken-by-rust-changes
The `git submodule update --init` and `cargo vendor` commands above
require network access, so they can't be performed from within the
`rustc` derivation, unfortunately.

17 changes: 8 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
nixpkgs = self;
};

lib = import ./lib;
libVersionInfoOverlay = import ./lib/flake-version-info.nix self;
lib = (import ./lib).extend libVersionInfoOverlay;

forAllSystems = lib.genAttrs lib.systems.flakeExposed;
in
Expand All @@ -20,13 +21,7 @@

nixosSystem = args:
import ./nixos/lib/eval-config.nix (
args // {
modules = args.modules ++ [{
system.nixos.versionSuffix =
".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}";
system.nixos.revision = final.mkIf (self ? rev) self.rev;
}];
} // lib.optionalAttrs (! args?system) {
args // { inherit (self) lib; } // lib.optionalAttrs (! args?system) {
# Allow system to be set modularly in nixpkgs.system.
# We set it to null, to remove the "legacy" entrypoint's
# non-hermetic default.
Expand All @@ -53,7 +48,11 @@
# attribute it displays `omitted` instead of evaluating all packages,
# which keeps `nix flake show` on Nixpkgs reasonably fast, though less
# information rich.
legacyPackages = forAllSystems (system: import ./. { inherit system; });
legacyPackages = forAllSystems (system:
(import ./. { inherit system; }).extend (final: prev: {
lib = prev.lib.extend libVersionInfoOverlay;
})
);

nixosModules = {
notDetected = ./nixos/modules/installer/scan/not-detected.nix;
Expand Down
72 changes: 72 additions & 0 deletions lib/attrsets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ rec {

/* Return if an attribute from nested attribute set exists.
**Laws**:
1. ```nix
hasAttrByPath [] x == true
```
Example:
x = { a = { b = 3; }; }
hasAttrByPath ["a" "b"] x
=> true
hasAttrByPath ["z" "z"] x
=> false
hasAttrByPath [] (throw "no need")
=> true
Type:
hasAttrByPath :: [String] -> AttrSet -> Bool
Expand All @@ -80,6 +87,71 @@ rec {
in
hasAttrByPath' 0 e;

/*
Return the longest prefix of an attribute path that refers to an existing attribute in a nesting of attribute sets.
Can be used after [`mapAttrsRecursiveCond`](#function-library-lib.attrsets.mapAttrsRecursiveCond) to apply a condition,
although this will evaluate the predicate function on sibling attributes as well.
Note that the empty attribute path is valid for all values, so this function only throws an exception if any of its inputs does.
**Laws**:
1. ```nix
attrsets.longestValidPathPrefix [] x == []
```
2. ```nix
hasAttrByPath (attrsets.longestValidPathPrefix p x) x == true
```
Example:
x = { a = { b = 3; }; }
attrsets.longestValidPathPrefix ["a" "b" "c"] x
=> ["a" "b"]
attrsets.longestValidPathPrefix ["a"] x
=> ["a"]
attrsets.longestValidPathPrefix ["z" "z"] x
=> []
attrsets.longestValidPathPrefix ["z" "z"] (throw "no need")
=> []
Type:
attrsets.longestValidPathPrefix :: [String] -> Value -> [String]
*/
longestValidPathPrefix =
# A list of strings representing the longest possible path that may be returned.
attrPath:
# The nested attribute set to check.
v:
let
lenAttrPath = length attrPath;
getPrefixForSetAtIndex =
# The nested attribute set to check, if it is an attribute set, which
# is not a given.
remainingSet:
# The index of the attribute we're about to check, as well as
# the length of the prefix we've already checked.
remainingPathIndex:

if remainingPathIndex == lenAttrPath then
# All previously checked attributes exist, and no attr names left,
# so we return the whole path.
attrPath
else
let
attr = elemAt attrPath remainingPathIndex;
in
if remainingSet ? ${attr} then
getPrefixForSetAtIndex
remainingSet.${attr} # advance from the set to the attribute value
(remainingPathIndex + 1) # advance the path
else
# The attribute doesn't exist, so we return the prefix up to the
# previously checked length.
take remainingPathIndex attrPath;
in
getPrefixForSetAtIndex v 0;

/* Create a new attribute set with `value` set at the nested attribute location specified in `attrPath`.
Example:
Expand Down
20 changes: 20 additions & 0 deletions lib/flake-version-info.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This function produces a lib overlay to be used by the nixpkgs
# & nixpkgs/lib flakes to provide meaningful values for
# `lib.trivial.version` et al..
#
# Internal and subject to change, don't use this anywhere else!
# Instead, consider using a public interface, such as this flake here
# in this directory, `lib/`, or use the nixpkgs flake, which applies
# this logic for you in its `lib` output attribute.

self: # from the flake

finalLib: prevLib: # lib overlay

{
trivial = prevLib.trivial // {
versionSuffix =
".${finalLib.substring 0 8 (self.lastModifiedDate or "19700101")}.${self.shortRev or "dirty"}";
revisionWithDefault = default: self.rev or default;
};
}
7 changes: 6 additions & 1 deletion lib/flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
description = "Library of low-level helper functions for nix expressions.";

outputs = { self }: { lib = import ./.; };
outputs = { self }:
let
lib0 = import ./.;
in {
lib = lib0.extend (import ./flake-version-info.nix self);
};
}
43 changes: 23 additions & 20 deletions lib/strings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,12 @@ rec {
getName pkgs.youtube-dl
=> "youtube-dl"
*/
getName = x:
let
parse = drv: (parseDrvName drv).name;
in if isString x
then parse x
else x.pname or (parse x.name);
getName = let
parse = drv: (parseDrvName drv).name;
in x:
if isString x
then parse x
else x.pname or (parse x.name);

/* This function takes an argument that's either a derivation or a
derivation's "name" attribute and extracts the version part from that
Expand All @@ -732,12 +732,12 @@ rec {
getVersion pkgs.youtube-dl
=> "2016.01.01"
*/
getVersion = x:
let
parse = drv: (parseDrvName drv).version;
in if isString x
then parse x
else x.version or (parse x.name);
getVersion = let
parse = drv: (parseDrvName drv).version;
in x:
if isString x
then parse x
else x.version or (parse x.name);

/* Extract name with version from URL. Ask for separator which is
supposed to start extension.
Expand Down Expand Up @@ -771,12 +771,13 @@ rec {
cmakeOptionType "string" "ENGINE" "sdl2"
=> "-DENGINE:STRING=sdl2"
*/
cmakeOptionType = type: feature: value:
assert (lib.elem (lib.toUpper type)
[ "BOOL" "FILEPATH" "PATH" "STRING" "INTERNAL" ]);
assert (lib.isString feature);
assert (lib.isString value);
"-D${feature}:${lib.toUpper type}=${value}";
cmakeOptionType = let
types = [ "BOOL" "FILEPATH" "PATH" "STRING" "INTERNAL" ];
in type: feature: value:
assert (elem (toUpper type) types);
assert (isString feature);
assert (isString value);
"-D${feature}:${toUpper type}=${value}";

/* Create a -D<condition>={TRUE,FALSE} string that can be passed to typical
CMake invocations.
Expand Down Expand Up @@ -977,9 +978,11 @@ rec {
Many types of value are coercible to string this way, including int, float,
null, bool, list of similarly coercible values.
*/
isConvertibleWithToString = x:
isConvertibleWithToString = let
types = [ "null" "int" "float" "bool" ];
in x:
isStringLike x ||
elem (typeOf x) [ "null" "int" "float" "bool" ] ||
elem (typeOf x) types ||
(isList x && lib.all isConvertibleWithToString x);

/* Check whether a value can be coerced to a string.
Expand Down
45 changes: 45 additions & 0 deletions lib/tests/misc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,51 @@ runTests {
expected = false;
};

testHasAttrByPathNonStrict = {
expr = hasAttrByPath [] (throw "do not use");
expected = true;
};

testLongestValidPathPrefix_empty_empty = {
expr = attrsets.longestValidPathPrefix [ ] { };
expected = [ ];
};

testLongestValidPathPrefix_empty_nonStrict = {
expr = attrsets.longestValidPathPrefix [ ] (throw "do not use");
expected = [ ];
};

testLongestValidPathPrefix_zero = {
expr = attrsets.longestValidPathPrefix [ "a" (throw "do not use") ] { d = null; };
expected = [ ];
};

testLongestValidPathPrefix_zero_b = {
expr = attrsets.longestValidPathPrefix [ "z" "z" ] "remarkably harmonious";
expected = [ ];
};

testLongestValidPathPrefix_one = {
expr = attrsets.longestValidPathPrefix [ "a" "b" "c" ] { a = null; };
expected = [ "a" ];
};

testLongestValidPathPrefix_two = {
expr = attrsets.longestValidPathPrefix [ "a" "b" "c" ] { a.b = null; };
expected = [ "a" "b" ];
};

testLongestValidPathPrefix_three = {
expr = attrsets.longestValidPathPrefix [ "a" "b" "c" ] { a.b.c = null; };
expected = [ "a" "b" "c" ];
};

testLongestValidPathPrefix_three_extra = {
expr = attrsets.longestValidPathPrefix [ "a" "b" "c" ] { a.b.c.d = throw "nope"; };
expected = [ "a" "b" "c" ];
};

testFindFirstIndexExample1 = {
expr = lists.findFirstIndex (x: x > 3) (abort "index found, so a default must not be evaluated") [ 1 6 4 ];
expected = 1;
Expand Down
50 changes: 29 additions & 21 deletions lib/trivial.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{ lib }:

rec {
let
inherit (lib.trivial)
isFunction
isInt
functionArgs
pathExists
release
setFunctionArgs
toBaseDigits
version
versionSuffix
warn;
in {

## Simple (higher order) functions

Expand Down Expand Up @@ -58,9 +70,7 @@ rec {
of the next function, and the last function returns the
final value.
*/
pipe = val: functions:
let reverseApply = x: f: f x;
in builtins.foldl' reverseApply val functions;
pipe = builtins.foldl' (x: f: f x);

# note please don’t add a function like `compose = flip pipe`.
# This would confuse users, because the order of the functions
Expand Down Expand Up @@ -439,7 +449,7 @@ rec {
*/
functionArgs = f:
if f ? __functor
then f.__functionArgs or (lib.functionArgs (f.__functor f))
then f.__functionArgs or (functionArgs (f.__functor f))
else builtins.functionArgs f;

/* Check whether something is a function or something
Expand Down Expand Up @@ -510,22 +520,20 @@ rec {
toHexString 250 => "FA"
*/
toHexString = i:
let
toHexDigit = d:
if d < 10
then toString d
else
{
"10" = "A";
"11" = "B";
"12" = "C";
"13" = "D";
"14" = "E";
"15" = "F";
}.${toString d};
in
lib.concatMapStrings toHexDigit (toBaseDigits 16 i);
toHexString = let
hexDigits = {
"10" = "A";
"11" = "B";
"12" = "C";
"13" = "D";
"14" = "E";
"15" = "F";
};
toHexDigit = d:
if d < 10
then toString d
else hexDigits.${toString d};
in i: lib.concatMapStrings toHexDigit (toBaseDigits 16 i);

/* `toBaseDigits base i` converts the positive integer i to a list of its
digits in the given base. For example:
Expand Down
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,12 @@
githubId = 4717906;
name = "Jakub Skokan";
};
ajaxbits = {
email = "[email protected]";
github = "ajaxbits";
githubId = 45179933;
name = "Alex Jackson";
};
ajgrf = {
email = "[email protected]";
github = "ajgrf";
Expand Down
1 change: 1 addition & 0 deletions maintainers/team-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ with lib.maintainers; {
members = [
theuni
dpausp
frlan
leona
];
scope = "Team for Flying Circus employees who collectively maintain packages.";
Expand Down
Loading

0 comments on commit e1f9606

Please sign in to comment.