NixOS / NixOS/nix

Darwin builds forking off processes never finish

Open
#8,232 7 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug idea approved sandbox
Dominant language
C++
Stars
17.7k
Forks
2k
Avg merge
1d 16h
Merged PRs (30d)
80

Description

Describe the bug

I have some Nix build forking off a long-running process in the background. In that specific example, a postgresql database.

The build process starts the database, does some insertions and queries in it, then renders a document into $out (end of build script).

On Linux, after all steps in the build script have been finished, the build exits, and the output can be observed.

On Darwin, the build process gets stuck indefinitely.

A workaround is to manually register cleanup traps in bash.

Steps To Reproduce

Build the following on x86_64-linux vs aarch64-darwin:

let
  pkgs = import <nixpkgs> { };
in
pkgs.callPackage
  (
    with import <nixpkgs> { };
    { stdenv, ... }:

    stdenv.mkDerivation {
      pname = "foo";
      version = "1";
      buildCommand = ''
        sleep infinity &
        
        echo foo > $out
      '';
    }
  )
{ }

Expected behavior

I'd expect in both cases the build to end, and the sleep process to be killed at the end of the build script.

nix-env --version output

nix-env (Nix) 2.13.3

Priorities

Add 👍 to issues you find important.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided derivation on x86_64-linux and aarch64-darwin, then trace the platform-specific build-process cleanup behavior. Compare how the background sleep process is handled on each platform; done means the Darwin build exits and the background process is terminated without manual cleanup traps.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, cpp, macos
Domain
build-system, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.