Home Explore Blog Models CI



nixpkgs

doc/build-helpers/special/makesetuphook.section.md
875c45fc40ec75a23c5130e633b1867fdd92e5c5d905625f0000000300000619
# pkgs.makeSetupHook {#sec-pkgs.makeSetupHook}

`pkgs.makeSetupHook` is a build helper that produces hooks that go in to `nativeBuildInputs`

## Usage {#sec-pkgs.makeSetupHook-usage}

```nix
pkgs.makeSetupHook {
  name = "something-hook";
  propagatedBuildInputs = [ pkgs.commandsomething ];
  depsTargetTargetPropagated = [ pkgs.libsomething ];
} ./script.sh
```

### setup hook that depends on the hello package and runs hello and @shell@ is substituted with path to bash {#sec-pkgs.makeSetupHook-usage-example}

```nix
pkgs.makeSetupHook
  {
    name = "run-hello-hook";
    # Put dependencies here if they have hooks or necessary dependencies propagated
    # otherwise prefer direct paths to executables.
    propagatedBuildInputs = [
      pkgs.hello
      pkgs.cowsay
    ];
    substitutions = {
      shell = "${pkgs.bash}/bin/bash";
      cowsay = "${pkgs.cowsay}/bin/cowsay";
    };
  }
  (
    writeScript "run-hello-hook.sh" ''
      #!@shell@
      # the direct path to the executable has to be here because
      # this will be run when the file is sourced
      # at which point '$PATH' has not yet been populated with inputs
      @cowsay@ cow

      _printHelloHook() {
        hello
      }
      preConfigureHooks+=(_printHelloHook)
    ''
  )
```

## Attributes {#sec-pkgs.makeSetupHook-attributes}

* `name` Set the name of the hook.
* `propagatedBuildInputs` Runtime dependencies (such as binaries) of the hook.
* `depsTargetTargetPropagated` Non-binary dependencies.
* `meta`
* `passthru`
* `substitutions` Variables for `substituteAll`

Chunks
db7794b0 (1st chunk of `doc/build-helpers/special/makesetuphook.section.md`)
Title: pkgs.makeSetupHook: NixOS Build Helper for Setup Hooks
Summary
This section introduces `pkgs.makeSetupHook`, a NixOS build helper designed to produce setup hooks that integrate into `nativeBuildInputs`. It details its usage, requiring attributes like `name`, `propagatedBuildInputs` for runtime dependencies, `depsTargetTargetPropagated` for non-binary dependencies, and a script. The text provides a practical example demonstrating how to create a hook that runs `hello` and `cowsay`, utilizing `substitutions` to dynamically insert paths to executables like `bash` and `cowsay` within the script. A list of key attributes for `pkgs.makeSetupHook` is also provided, including `name`, `propagatedBuildInputs`, and `substitutions`.