# Working setup with a \`post-build-hook\` daemon?

**URL:** https://discourse.nixos.org/t/working-setup-with-a-post-build-hook-daemon/48731
**Category:** Help
**Created:** [July 9, 2024, 10:41am UTC](https://discourse.nixos.org/t/working-setup-with-a-post-build-hook-daemon/48731 "2024-07-09T10:41:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fricklerhandwerk](https://discourse.nixos.org/user_avatar/discourse.nixos.org/fricklerhandwerk/32/2029_2.png) [@fricklerhandwerk](https://discourse.nixos.org/u/fricklerhandwerk)
#### Post date: [July 9, 2024, 10:41am UTC](https://discourse.nixos.org/t/working-setup-with-a-post-build-hook-daemon/48731/1 "2024-07-09T10:41:08Z")

</div>

Is there any open-source implementation of a functioning post-build hook daemon, as sketched in [Setting up post-build hooks — nix.dev documentation](https://nix.dev/guides/recipes/post-build-hook)?

- There seems to be no NixOS module for such a thing
- This discussion did not hint at any: [Automatically upload built derivations to cache?](https://discourse.nixos.org/t/automatically-upload-built-derivations-to-cache/25428)
- Hydra seems to make an efficient integration possible: [Derivations built on remote machines not copied to binary cache](https://discourse.nixos.org/t/derivations-built-on-remote-machines-not-copied-to-binary-cache/29376) (but Hydra is not great to work with)
- Long discussion on how to do it: [Developing a system that replaces nix remote build](https://discourse.nixos.org/t/developing-a-system-that-replaces-nix-remote-build/22388)
  - Documentation by @rickynils: [Running Remote Builds - nixbuild.net documentation](https://docs.nixbuild.net/remote-builds/)
  - Unfinished prototype by @jsoo1: [GitHub - jsoo1/remote-build-queue](https://github.com/jsoo1/remote-build-queue)

---

<div class="post-metadata">

### Author: ![dermetfan](https://discourse.nixos.org/user_avatar/discourse.nixos.org/dermetfan/32/289_2.png) [@dermetfan](https://discourse.nixos.org/u/dermetfan)
#### Post date: [July 9, 2024, 12:18pm UTC](https://discourse.nixos.org/t/working-setup-with-a-post-build-hook-daemon/48731/3 "2024-07-09T12:18:28Z")

</div>

We use this in a Hydra cluster of ~10 machines:

```nix
nix.settings.post-build-hook = lib.getExe (pkgs.writeShellApplication {
  name = "upload";
  runtimeInputs = with pkgs; [ts nix findutils];
  text = ''
    set -uf

    export AWS_SHARED_CREDENTIALS_FILE=${lib.escapeShellArg config.age.secrets.r2.path}

    if [[-n "''${OUT_PATHS:-}"]]; then
      export TS_MAXFINISHED=1000
      export TS_SLOTS=10

      echo "upload $OUT_PATHS"
      printf "%s" "$OUT_PATHS" \
      | xargs ts nix copy --to 's3://FOO?secret-key=${config.age.secrets.nix.path}&endpoint=foo.r2.cloudflarestorage.com&region=auto&compression=zstd'
    fi
  '';
});

```

---

<div class="post-metadata">

### Author: ![jsoo1](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jsoo1/32/5623_2.png) [@jsoo1](https://discourse.nixos.org/u/jsoo1)
#### Post date: [July 9, 2024, 1:53pm UTC](https://discourse.nixos.org/t/working-setup-with-a-post-build-hook-daemon/48731/4 "2024-07-09T13:53:35Z")

</div>

Are you looking for a post-build hook or a build hook? I was working on a build hook - which does the load balancing for remote builds.

Post-build hooks are often used to upload to an s3 bucket or similar.

---

<div class="post-metadata">

### Author: ![fricklerhandwerk](https://discourse.nixos.org/user_avatar/discourse.nixos.org/fricklerhandwerk/32/2029_2.png) [@fricklerhandwerk](https://discourse.nixos.org/u/fricklerhandwerk)
#### Post date: [July 9, 2024, 2:41pm UTC](https://discourse.nixos.org/t/working-setup-with-a-post-build-hook-daemon/48731/5 "2024-07-09T14:41:52Z")

</div>

Here I’m asking for `post-build-hook` for uploading build results to a cache. But the general idea for build hooks is similar, and distributed builds are related to caching in the sense that you usually want both in some combination.
