Skip to content

Commit

Permalink
staging-next 2024-08-23 (#336718)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcunat committed Aug 31, 2024
2 parents f89e865 + 20766c8 commit 36a13f9
Show file tree
Hide file tree
Showing 266 changed files with 7,440 additions and 7,127 deletions.
59 changes: 59 additions & 0 deletions doc/languages-frameworks/go.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,65 @@ The following is an example expression using `buildGoModule`:
}
```

### Obtaining and overriding `vendorHash` for `buildGoModule` {#buildGoModule-vendorHash}

We can use `nix-prefetch` to obtain the actual hash. The following command gets the value of `vendorHash` for package `pet`:

```sh
cd path/to/nixpkgs
nix-prefetch -E "{ sha256 }: ((import ./. { }).my-package.overrideAttrs { vendorHash = sha256; }).goModules"
```

To obtain the hash without external tools, set `vendorHash = lib.fakeHash;` and run the build. ([more details here](#sec-source-hashes)).

`vendorHash` can be overridden with `overrideAttrs`. Override the above example like this:

```nix
{
pet_0_4_0 = pet.overrideAttrs (
finalAttrs: previousAttrs: {
version = "0.4.0";
src = fetchFromGitHub {
inherit (previousAttrs.src) owner repo;
rev = "v${finalAttrs.version}";
hash = "sha256-gVTpzmXekQxGMucDKskGi+e+34nJwwsXwvQTjRO6Gdg=";
};
vendorHash = "sha256-dUvp7FEW09V0xMuhewPGw3TuAic/sD7xyXEYviZ2Ivs=";
}
);
}
```

### Overriding `goModules` {#buildGoModule-goModules-override}

Overriding `<pkg>.goModules` by calling `goModules.overrideAttrs` is unsupported. Still, it is possible to override the `vendorHash` (`goModules`'s `outputHash`) and the `pre`/`post` hooks for both the build and patch phases of the primary and `goModules` derivation. Alternatively, the primary derivation provides an overridable `passthru.overrideModAttrs` function to store the attribute overlay implicitly taken by `goModules.overrideAttrs`. Here's an example usage of `overrideModAttrs`:

```nix
{
pet-overridden = pet.overrideAttrs (
finalAttrs: previousAttrs: {
passthru = previousAttrs.passthru // {
# If the original package has an `overrideModAttrs` attribute set, you'd
# want to extend it, and not replace it. Hence we use
# `lib.composeExtensions`. If you are sure the `overrideModAttrs` of the
# original package trivially does nothing, you can safely replace it
# with your own by not using `lib.composeExtensions`.
overrideModAttrs = lib.composeExtensions previousAttrs.passthru.overrideModAttrs (
finalModAttrs: previousModAttrs: {
# goModules-specific overriding goes here
postBuild = ''
# Here you have access to the `vendor` directory.
substituteInPlace vendor/github.com/example/repo/file.go \
--replace-fail "panic(err)" ""
'';
}
);
};
}
);
}
```

## `buildGoPackage` (legacy) {#ssec-go-legacy}

The function `buildGoPackage` builds legacy Go programs, not supporting Go modules.
Expand Down
2 changes: 1 addition & 1 deletion doc/languages-frameworks/ruby.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Using Ruby {#using-ruby}

Several versions of Ruby interpreters are available on Nix, as well as over 250 gems and many applications written in Ruby. The attribute `ruby` refers to the default Ruby interpreter, which is currently MRI 3.1. It's also possible to refer to specific versions, e.g. `ruby_3_y`, `jruby`, or `mruby`.
Several versions of Ruby interpreters are available on Nix, as well as over 250 gems and many applications written in Ruby. The attribute `ruby` refers to the default Ruby interpreter, which is currently MRI 3.3. It's also possible to refer to specific versions, e.g. `ruby_3_y`, `jruby`, or `mruby`.

In the Nixpkgs tree, Ruby packages can be found throughout, depending on what they do, and are called from the main package set. Ruby gems, however are separate sets, and there's one default set for each interpreter (currently MRI only).

Expand Down
16 changes: 12 additions & 4 deletions lib/strings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,8 @@ rec {
replaceStrings (builtins.attrNames toEscape) (lib.mapAttrsToList (_: c: "%${fixedWidthString 2 "0" (lib.toHexString c)}") toEscape);

/**
Quote `string` to be used safely within the Bourne shell.
Quote `string` to be used safely within the Bourne shell if it has any
special characters.
# Inputs
Expand All @@ -1051,10 +1052,17 @@ rec {
:::
*/
escapeShellArg = arg: "'${replaceStrings ["'"] ["'\\''"] (toString arg)}'";
escapeShellArg = arg:
let
string = toString arg;
in
if match "[[:alnum:],._+:@%/-]+" string == null
then "'${replaceStrings ["'"] ["'\\''"] string}'"
else string;

/**
Quote all arguments to be safely passed to the Bourne shell.
Quote all arguments that have special characters to be safely passed to the
Bourne shell.
# Inputs
Expand All @@ -1073,7 +1081,7 @@ rec {
```nix
escapeShellArgs ["one" "two three" "four'five"]
=> "'one' 'two three' 'four'\\''five'"
=> "one 'two three' 'four'\\''five'"
```
:::
Expand Down
28 changes: 24 additions & 4 deletions lib/tests/misc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,26 @@ runTests {
expected = [ "A" "B" ];
};

testEscapeShellArg = {
expr = strings.escapeShellArg "esc'ape\nme";
expected = "'esc'\\''ape\nme'";
};

testEscapeShellArgEmpty = {
expr = strings.escapeShellArg "";
expected = "''";
};

testEscapeShellArgs = {
expr = strings.escapeShellArgs ["one" "two three" "four'five"];
expected = "one 'two three' 'four'\\''five'";
};

testEscapeShellArgsUnicode = {
expr = strings.escapeShellArg "á";
expected = "'á'";
};

testSplitStringsDerivation = {
expr = take 3 (strings.splitString "/" (derivation {
name = "name";
Expand Down Expand Up @@ -569,12 +589,12 @@ runTests {
'';
expected = ''
STRing01='just a '\'''string'\''''
declare -a _array_=('with' 'more strings')
declare -a _array_=(with 'more strings')
declare -A assoc=(['with some']='strings
possibly newlines
')
drv='/drv'
path='/path'
drv=/drv
path=/path
stringable='hello toString'
'';
};
Expand Down Expand Up @@ -1754,7 +1774,7 @@ runTests {
verbose = true;
};

expected = "'-X' 'PUT' '--data' '{\"id\":0}' '--retry' '3' '--url' 'https://example.com/foo' '--url' 'https://example.com/bar' '--verbose'";
expected = "-X PUT --data '{\"id\":0}' --retry 3 --url https://example.com/foo --url https://example.com/bar --verbose";
};

testSanitizeDerivationNameLeadingDots = testSanitizeDerivationName {
Expand Down
4 changes: 4 additions & 0 deletions nixos/doc/manual/release-notes/rl-2411.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@
[buildRustPackage: Compiling Rust applications with Cargo](https://nixos.org/manual/nixpkgs/unstable/#compiling-rust-applications-with-cargo)
for more information.

- The `vendorHash` of Go packages built with `buildGoModule` can now be overridden with `overrideAttrs`.
`goModules`, `modRoot`, `vendorHash`, `deleteVendor`, and `proxyVendor` are now passed as derivation attributes.
`goModules` and `vendorHash` are no longer placed under `passthru`.

- `hareHook` has been added as the language framework for Hare. From now on, it,
not the `hare` package, should be added to `nativeBuildInputs` when building
Hare programs.
Expand Down
8 changes: 7 additions & 1 deletion nixos/modules/config/fonts/fontconfig.nix
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,14 @@ let
mkdir -p $dst
# fonts.conf
ln -s ${pkg.out}/etc/fonts/fonts.conf \
cp ${pkg.out}/etc/fonts/fonts.conf \
$dst/../fonts.conf
# horrible sed hack to add the line that was accidentally removed
# from the default config in #324516
# FIXME: fix that, revert this
sed "5i <include ignore_missing="yes">/etc/fonts/conf.d</include>" -i $dst/../fonts.conf
# TODO: remove this legacy symlink once people stop using packages built before #95358 was merged
mkdir -p $out/etc/fonts/2.11
ln -s /etc/fonts/fonts.conf \
Expand Down
3 changes: 2 additions & 1 deletion pkgs/applications/accessibility/squeekboard/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
, gtk3
, wayland
, wayland-protocols
, wayland-scanner
, libbsd
, libxml2
, libxkbcommon
Expand Down Expand Up @@ -44,7 +45,7 @@ stdenv.mkDerivation rec {
ninja
pkg-config
glib
wayland
wayland-scanner
wrapGAppsHook3
rustPlatform.cargoSetupHook
cargo
Expand Down
19 changes: 11 additions & 8 deletions pkgs/applications/editors/emacs/build-support/elpa.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@
{ lib, stdenv, emacs, texinfo, writeText }:

let
handledArgs = [ "meta" ];
genericBuild = import ./generic.nix { inherit lib stdenv emacs texinfo writeText; };
libBuildHelper = import ./lib-build-helper.nix;

in

libBuildHelper.extendMkDerivation' genericBuild (finalAttrs:

{ pname
, version
, src
, dontUnpack ? true
, meta ? {}
, ...
}@args:

genericBuild ({
{

elpa2nix = args.elpa2nix or ./elpa2nix.el;

dontUnpack = true;
inherit dontUnpack;

installPhase = ''
installPhase = args.installPhase or ''
runHook preInstall
emacs --batch -Q -l ${./elpa2nix.el} \
emacs --batch -Q -l "$elpa2nix" \
-f elpa2nix-install-package \
"$src" "$out/share/emacs/site-lisp/elpa"
Expand All @@ -34,4 +37,4 @@ genericBuild ({
} // meta;
}

// removeAttrs args handledArgs)
)
32 changes: 16 additions & 16 deletions pkgs/applications/editors/emacs/build-support/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

let
inherit (lib) optionalAttrs;
handledArgs = [ "buildInputs" "nativeBuildInputs" "packageRequires" "propagatedUserEnvPkgs" "meta" ]
++ lib.optionals (emacs.withNativeCompilation or false) [ "postInstall" ];

setupHook = writeText "setup-hook.sh" ''
source ${./emacs-funcs.sh}
Expand All @@ -21,13 +19,16 @@ let
fi
'';

libBuildHelper = import ./lib-build-helper.nix;

in

{ pname
, version
, buildInputs ? []
libBuildHelper.extendMkDerivation' stdenv.mkDerivation (finalAttrs:

{ buildInputs ? []
, nativeBuildInputs ? []
, packageRequires ? []
, propagatedBuildInputs ? []
, propagatedUserEnvPkgs ? []
, postInstall ? ""
, meta ? {}
Expand All @@ -36,10 +37,10 @@ in
, ...
}@args:

stdenv.mkDerivation (finalAttrs: ({
name = "emacs-${pname}-${finalAttrs.version}";
{
name = args.name or "emacs-${finalAttrs.pname}-${finalAttrs.version}";

unpackCmd = ''
unpackCmd = args.unpackCmd or ''
case "$curSrc" in
*.el)
# keep original source filename without the hash
Expand All @@ -55,14 +56,13 @@ stdenv.mkDerivation (finalAttrs: ({
esac
'';

buildInputs = packageRequires ++ buildInputs;
inherit packageRequires;
buildInputs = finalAttrs.packageRequires ++ buildInputs;
nativeBuildInputs = [ emacs texinfo ] ++ nativeBuildInputs;
propagatedBuildInputs = packageRequires;
propagatedUserEnvPkgs = packageRequires ++ propagatedUserEnvPkgs;

inherit setupHook;
propagatedBuildInputs = finalAttrs.packageRequires ++ propagatedBuildInputs;
propagatedUserEnvPkgs = finalAttrs.packageRequires ++ propagatedUserEnvPkgs;

doCheck = false;
setupHook = args.setupHook or setupHook;

meta = {
broken = false;
Expand All @@ -74,7 +74,7 @@ stdenv.mkDerivation (finalAttrs: ({

// optionalAttrs (emacs.withNativeCompilation or false) {

addEmacsNativeLoadPath = true;
addEmacsNativeLoadPath = args.addEmacsNativeLoadPath or true;

inherit turnCompilationWarningToError ignoreCompilationError;

Expand All @@ -97,4 +97,4 @@ stdenv.mkDerivation (finalAttrs: ({
'' + postInstall;
}

// removeAttrs args handledArgs))
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
extendMkDerivation' =
mkDerivationBase: attrsOverlay: fpargs:
(mkDerivationBase fpargs).overrideAttrs attrsOverlay;
}
Loading

0 comments on commit 36a13f9

Please sign in to comment.