Skip to content

Commit

Permalink
Merge branch 'NixOS:master' into pkg/snx-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Shavyn authored Jan 30, 2025
2 parents b40e607 + 84c6e0c commit 2e0ac2a
Show file tree
Hide file tree
Showing 509 changed files with 9,124 additions and 4,402 deletions.
5 changes: 2 additions & 3 deletions ci/eval/compare/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ let
groupByPlatform
extractPackageNames
getLabels
uniqueStrings
;

getAttrs = dir: builtins.fromJSON (builtins.readFile "${dir}/outpaths.json");
Expand All @@ -81,7 +80,7 @@ let
# - values: lists of `packagePlatformPath`s
diffAttrs = diff beforeAttrs afterAttrs;

rebuilds = uniqueStrings (diffAttrs.added ++ diffAttrs.changed);
rebuilds = diffAttrs.added ++ diffAttrs.changed;
rebuildsPackagePlatformAttrs = convertToPackagePlatformAttrs rebuilds;

changed-paths =
Expand Down Expand Up @@ -110,7 +109,7 @@ let
);

maintainers = import ./maintainers.nix {
changedattrs = lib.unique (map (a: a.packagePath) rebuildsPackagePlatformAttrs);
changedattrs = lib.attrNames (lib.groupBy (a: a.name) rebuildsPackagePlatformAttrs);
changedpathsjson = touchedFilesJson;
};
in
Expand Down
59 changes: 15 additions & 44 deletions ci/eval/compare/maintainers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ let
changedpaths = builtins.fromJSON (builtins.readFile changedpathsjson);

anyMatchingFile =
filename:
let
matching = builtins.filter (changed: lib.strings.hasSuffix changed filename) changedpaths;
in
(builtins.length matching) > 0;
filename: builtins.any (changed: lib.strings.hasSuffix changed filename) changedpaths;

anyMatchingFiles = files: (builtins.length (builtins.filter anyMatchingFile files)) > 0;
anyMatchingFiles = files: builtins.any anyMatchingFile files;

enrichedAttrs = builtins.map (path: {
path = path;
name = builtins.concatStringsSep "." path;
enrichedAttrs = builtins.map (name: {
path = lib.splitString "." name;
name = name;
}) changedattrs;

validPackageAttributes = builtins.filter (
Expand All @@ -45,14 +41,6 @@ let
pkg: pkg // { maintainers = (pkg.package.meta or { }).maintainers or [ ]; }
) attrsWithPackages;

attrsWeCanPing = builtins.filter (
pkg:
if (builtins.length pkg.maintainers) > 0 then
true
else
builtins.trace "Package has no maintainers: ${pkg.name}" false
) attrsWithMaintainers;

relevantFilenames =
drv:
(lib.lists.unique (
Expand Down Expand Up @@ -88,33 +76,16 @@ let

attrsWithModifiedFiles = builtins.filter (pkg: anyMatchingFiles pkg.filenames) attrsWithFilenames;

listToPing = lib.lists.flatten (
builtins.map (
pkg:
builtins.map (maintainer: {
id = maintainer.githubId;
packageName = pkg.name;
dueToFiles = pkg.filenames;
}) pkg.maintainers
) attrsWithModifiedFiles
);

byMaintainer = lib.lists.foldr (
ping: collector:
collector
// {
"${toString ping.id}" = [
{ inherit (ping) packageName dueToFiles; }
] ++ (collector."${toString ping.id}" or [ ]);
}
) { } listToPing;

textForPackages =
packages: lib.strings.concatStringsSep ", " (builtins.map (pkg: pkg.packageName) packages);

textPerMaintainer = lib.attrsets.mapAttrs (
maintainer: packages: "- @${maintainer} for ${textForPackages packages}"
) byMaintainer;
listToPing = lib.concatMap (
pkg:
builtins.map (maintainer: {
id = maintainer.githubId;
packageName = pkg.name;
dueToFiles = pkg.filenames;
}) pkg.maintainers
) attrsWithModifiedFiles;

byMaintainer = lib.groupBy (ping: toString ping.id) listToPing;

packagesPerMaintainer = lib.attrsets.mapAttrs (
maintainer: packages: builtins.map (pkg: pkg.packageName) packages
Expand Down
1 change: 1 addition & 0 deletions doc/hooks/tauri.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ In Nixpkgs, `cargo-tauri.hook` overrides the default build and install phases.
rustPlatform.buildRustPackage rec {
# . . .
useFetchCargoVendor = true;
cargoHash = "...";
# Assuming our app's frontend uses `npm` as a package manager
Expand Down
77 changes: 35 additions & 42 deletions doc/languages-frameworks/rust.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ Rust applications are packaged by using the `buildRustPackage` helper from `rust
rustPlatform.buildRustPackage rec {
pname = "ripgrep";
version = "12.1.1";
version = "14.1.1";
src = fetchFromGitHub {
owner = "BurntSushi";
repo = pname;
rev = version;
hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M=";
hash = "sha256-gyWnahj1A+iXUQlQ1O1H1u7K5euYQOld9qWm99Vjaeg=";
};
cargoHash = "sha256-jtBw4ahSl88L0iuCXxQgZVm1EcboWRJMNtjxLVTtzts=";
useFetchCargoVendor = true;
cargoHash = "sha256-9atn5qyBDy4P6iUoHFhg+TV6Ur71fiah4oTJbBMeEy4=";
meta = {
description = "Fast line-oriented regex search tool, similar to ag and ack";
Expand Down Expand Up @@ -63,18 +64,7 @@ hash using `nix-hash --to-sri --type sha256 "<original sha256>"`.
}
```

Exception: If the application has cargo `git` dependencies, the `cargoHash`
approach will not work by default. In this case, you can set `useFetchCargoVendor = true`
to use an improved fetcher that supports handling `git` dependencies.

```nix
{
useFetchCargoVendor = true;
cargoHash = "sha256-RqPVFovDaD2rW31HyETJfQ0qVwFxoGEvqkIgag3H6KU=";
}
```

If this method still does not work, you can resort to copying the `Cargo.lock` file into nixpkgs
If this method does not work, you can resort to copying the `Cargo.lock` file into nixpkgs
and importing it as described in the [next section](#importing-a-cargo.lock-file).

Both types of hashes are permitted when contributing to nixpkgs. The
Expand Down Expand Up @@ -119,7 +109,8 @@ rustPlatform.buildRustPackage rec {
hash = "sha256-aDQA4A5mScX9or3Lyiv/5GyAehidnpKKE0grhbP1Ctc=";
};
cargoHash = "sha256-tbrTbutUs5aPSV+yE0IBUZAAytgmZV7Eqxia7g+9zRs=";
useFetchCargoVendor = true;
cargoHash = "sha256-iDYh52rj1M5Uupvbx2WeDd/jvQZ+2A50V5rp5e2t7q4=";
cargoDepsName = pname;
# ...
Expand Down Expand Up @@ -443,14 +434,14 @@ hooks that can be used to integrate Cargo in non-Rust packages.

Since network access is not allowed in sandboxed builds, Rust crate
dependencies need to be retrieved using a fetcher. `rustPlatform`
provides the `fetchCargoTarball` fetcher, which vendors all
provides the `fetchCargoVendor` fetcher, which vendors all
dependencies of a crate. For example, given a source path `src`
containing `Cargo.toml` and `Cargo.lock`, `fetchCargoTarball`
containing `Cargo.toml` and `Cargo.lock`, `fetchCargoVendor`
can be used as follows:

```nix
{
cargoDeps = rustPlatform.fetchCargoTarball {
cargoDeps = rustPlatform.fetchCargoVendor {
inherit src;
hash = "sha256-BoHIN/519Top1NUBjpB/oEMqi86Omt3zTQcXFWqrek0=";
};
Expand Down Expand Up @@ -482,7 +473,7 @@ In case the lockfile contains cargo `git` dependencies, you can use
```

If a `Cargo.lock` file is available, you can alternatively use the
`importCargoLock` function. In contrast to `fetchCargoTarball`, this
`importCargoLock` function. In contrast to `fetchCargoVendor`, this
function does not require a hash (unless git dependencies are used)
and fetches every dependency as a separate fixed-output derivation.
`importCargoLock` can be used as follows:
Expand Down Expand Up @@ -521,12 +512,13 @@ you of the correct hash.
`rustPlatform` provides the following hooks to automate Cargo builds:

* `cargoSetupHook`: configure Cargo to use dependencies vendored
through `fetchCargoTarball`. This hook uses the `cargoDeps`
environment variable to find the vendored dependencies. If a project
already vendors its dependencies, the variable `cargoVendorDir` can
be used instead. When the `Cargo.toml`/`Cargo.lock` files are not in
`sourceRoot`, then the optional `cargoRoot` is used to specify the
Cargo root directory relative to `sourceRoot`.
through `fetchCargoVendor` or `importCargoLock`. This hook uses the
`cargoDeps` environment variable to find the vendored
dependencies. If a project already vendors its dependencies, the
variable `cargoVendorDir` can be used instead. When the
`Cargo.toml`/`Cargo.lock` files are not in `sourceRoot`, then the
optional `cargoRoot` is used to specify the Cargo root directory
relative to `sourceRoot`.
* `cargoBuildHook`: use Cargo to build a crate. If the crate to be
built is a crate in e.g. a Cargo workspace, the relative path to the
crate to build can be set through the optional `buildAndTestSubdir`
Expand Down Expand Up @@ -557,7 +549,7 @@ you of the correct hash.
#### Python package using `setuptools-rust` {#python-package-using-setuptools-rust}

For Python packages using `setuptools-rust`, you can use
`fetchCargoTarball` and `cargoSetupHook` to retrieve and set up Cargo
`fetchCargoVendor` and `cargoSetupHook` to retrieve and set up Cargo
dependencies. The build itself is then performed by
`buildPythonPackage`.

Expand Down Expand Up @@ -586,9 +578,9 @@ buildPythonPackage rec {
hash = "sha256-rQ2hRV52naEf6PvRsWVCTN7B1oXAQGmnpJw4iIdhamw=";
};
cargoDeps = rustPlatform.fetchCargoTarball {
cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src sourceRoot;
hash = "sha256-miW//pnOmww2i6SOGbkrAIdc/JMDT4FJLqdMFojZeoY=";
hash = "sha256-RO1m8wEd5Ic2M9q+zFHeCJWhCr4Sv3CEWd08mkxsBec=";
};
sourceRoot = "${src.name}/bindings/python";
Expand All @@ -609,7 +601,7 @@ directory. In such cases, the `cargoRoot` attribute can be used to
specify the crate's directory relative to `sourceRoot`. In the
following example, the crate is in `src/rust`, as specified in the
`cargoRoot` attribute. Note that we also need to specify the correct
path for `fetchCargoTarball`.
path for `fetchCargoVendor`.

```nix
Expand All @@ -629,10 +621,10 @@ buildPythonPackage rec {
hash = "sha256-xGDilsjLOnls3MfVbGKnj80KCUCczZxlis5PmHzpNcQ=";
};
cargoDeps = rustPlatform.fetchCargoTarball {
cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src;
sourceRoot = "${pname}-${version}/${cargoRoot}";
hash = "sha256-PS562W4L1NimqDV2H0jl5vYhL08H9est/pbIxSdYVfo=";
hash = "sha256-ctUt8maCjnGddKPf+Ii++wKsAXA1h+JM6zKQNXXwJqQ=";
};
cargoRoot = "src/rust";
Expand All @@ -644,9 +636,9 @@ buildPythonPackage rec {
#### Python package using `maturin` {#python-package-using-maturin}

Python packages that use [Maturin](https://github.com/PyO3/maturin)
can be built with `fetchCargoTarball`, `cargoSetupHook`, and
can be built with `fetchCargoVendor`, `cargoSetupHook`, and
`maturinBuildHook`. For example, the following (partial) derivation
builds the `retworkx` Python package. `fetchCargoTarball` and
builds the `retworkx` Python package. `fetchCargoVendor` and
`cargoSetupHook` are used to fetch and set up the crate dependencies.
`maturinBuildHook` is used to perform the build.

Expand All @@ -669,9 +661,9 @@ buildPythonPackage rec {
hash = "sha256-11n30ldg3y3y6qxg3hbj837pnbwjkqw3nxq6frds647mmmprrd20=";
};
cargoDeps = rustPlatform.fetchCargoTarball {
cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src;
hash = "sha256-heOBK8qi2nuc/Ib+I/vLzZ1fUUD/G/KTw9d7M4Hz5O0=";
hash = "sha256-QsPCQhNZKYCAogQriQX6pBYQUDAIUsEdRX/63dAqTzg=";
};
nativeBuildInputs = with rustPlatform; [ cargoSetupHook maturinBuildHook ];
Expand All @@ -682,7 +674,7 @@ buildPythonPackage rec {

#### Rust package built with `meson` {#rust-package-built-with-meson}

Some projects, especially GNOME applications, are built with the Meson Build System instead of calling Cargo directly. Using `rustPlatform.buildRustPackage` may successfully build the main program, but related files will be missing. Instead, you need to set up Cargo dependencies with `fetchCargoTarball` and `cargoSetupHook` and leave the rest to Meson. `rust` and `cargo` are still needed in `nativeBuildInputs` for Meson to use.
Some projects, especially GNOME applications, are built with the Meson Build System instead of calling Cargo directly. Using `rustPlatform.buildRustPackage` may successfully build the main program, but related files will be missing. Instead, you need to set up Cargo dependencies with `fetchCargoVendor` and `cargoSetupHook` and leave the rest to Meson. `rust` and `cargo` are still needed in `nativeBuildInputs` for Meson to use.

```nix
{ lib
Expand Down Expand Up @@ -713,9 +705,9 @@ stdenv.mkDerivation rec {
hash = "sha256-PrNPprSS98yN8b8yw2G6hzTSaoE65VbsM3q7FVB4mds=";
};
cargoDeps = rustPlatform.fetchCargoTarball {
cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src;
hash = "sha256-8fa3fa+sFi5H+49B5sr2vYPkp9C9s6CcE0zv4xB8gww=";
hash = "sha256-eR1ZGtTZQNhofFUEjI7IX16sMKPJmAl7aIFfPJukecg=";
};
nativeBuildInputs = [
Expand Down Expand Up @@ -998,16 +990,17 @@ in
rustPlatform.buildRustPackage rec {
pname = "ripgrep";
version = "12.1.1";
version = "14.1.1";
src = fetchFromGitHub {
owner = "BurntSushi";
repo = "ripgrep";
rev = version;
hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M=";
hash = "sha256-gyWnahj1A+iXUQlQ1O1H1u7K5euYQOld9qWm99Vjaeg=";
};
cargoHash = "sha256-l1vL2ZdtDRxSGvP0X/l3nMw8+6WF67KPutJEzUROjg8=";
useFetchCargoVendor = true;
cargoHash = "sha256-9atn5qyBDy4P6iUoHFhg+TV6Ur71fiah4oTJbBMeEy4=";
doCheck = false;
Expand Down
Loading

0 comments on commit 2e0ac2a

Please sign in to comment.