Unverified Commit 36a13f9f authored by Vladimír Čunát's avatar Vladimír Čunát
Browse files

staging-next 2024-08-23 (#336718)

parents f89e8650 20766c84
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
@@ -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.
+1 −1
Original line number Diff line number Diff line
@@ -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).

+12 −4
Original line number Diff line number Diff line
@@ -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
@@ -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

@@ -1073,7 +1081,7 @@ rec {

    ```nix
    escapeShellArgs ["one" "two three" "four'five"]
    => "'one' 'two three' 'four'\\''five'"
    => "one 'two three' 'four'\\''five'"
    ```

    :::
+24 −4
Original line number Diff line number Diff line
@@ -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";
@@ -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'
    '';
  };
@@ -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 {
+4 −0
Original line number Diff line number Diff line
@@ -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.
Loading