Nix-darwin is broken

I’m trying to rebuild my nix-darwin packages on an M1 MacBook pro, and that fails. In the meantime I haven’t changed anything, so I consider my flake unlikely as a potential cause of this.

Here’s the set of shell commands I use to update:

cd ~/nix-darwin-config
nix flake update
darwin-rebuild switch --flake .

# For now I omit garbage collection, as that seems to delete the derivations referred to in the error:
# DURATION=60d
# nix-collect-garbage --delete-older-than $DURATION

For completeness, here’s my flake:

{
  description = "Example Darwin system flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nix-darwin.url = "github:LnL7/nix-darwin";
    nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ self, nix-darwin, nixpkgs }:
  let
    configuration = { pkgs, ... }: {
      # List packages installed in system profile. To search by name, run:
      # $ nix-env -qaP | grep wget
      environment.systemPackages = with pkgs; [
        aspell
        bandwhich # Bandwidth monitor
        bat
        bottom # replacement for top
        broot # file navigation tool
        cargo-audit
        cargo-bloat
        cargo-edit
        cargo-expand # Rust macro expansion utility
        cargo-outdated # Find outdated Rust crate dependencies
        cargo-make # build tool on top of cargo
        cargo-msrv # Find the Minimum Supported Rust Version for a crate
        cargo-ndk # Android build support for Rust
        cargo-watch # Execute commands when Rust project files change
        cargo-workspaces
        diesel-cli
        dua
        dust
        emacs
        eza # nicer replacement for ls
        fd
        ffmpeg  # TODO: broken on MacOS, at least for now
        git
        graphviz
        htop
        hyperfine
        lldb
        mplayer
        nerdfonts
        nodejs_21
        nushell # A newfangled, more FP-oriented shell
        powerline-fonts
        resvg
        ripgrep
        rustup
        tokei
        vim
        wasm-pack # A tool to make WASM & Rust play nicely
        wezterm
        wget
        youtube-dl
        yt-dlp
        zellij
      ];

      system.defaults = {
        dock.autohide = true;
        dock.mru-spaces = false;
        dock.show-recents = false; # Don't show recent applications in the Dock
        finder.AppleShowAllExtensions = true;
        finder.FXPreferredViewStyle = "Nlsv";
        finder.ShowPathbar = true;
        finder.ShowStatusBar = true;
        screencapture.location = "~/Screenshots";
        screensaver.askForPasswordDelay = 1; # Require a password in the screensaver after 1 second
        # universalaccess.reduceTransparency = true;
      };

      # Auto upgrade nix package and the daemon service.
      services.nix-daemon.enable = true;
      # nix.package = pkgs.nix;

      # Cross-compile GNU/Linux binaries, or even full GNU/Linux system images
      nix.linux-builder.enable = true;

      nix.settings.trusted-users = ["j"];

      # Necessary for using flakes on this system.
      nix.settings.experimental-features = "nix-command flakes";

      # Create /etc/zshrc that loads the nix-darwin environment.
      programs.zsh.enable = true;  # default shell on catalina
      # programs.fish.enable = true;

      # Enable sudo authentication using fingerprint biometrics
      security.pam.enableSudoTouchIdAuth = true;

      # Set Git commit hash for darwin-version.
      system.configurationRevision = self.rev or self.dirtyRev or null;

      # Used for backwards compatibility, please read the changelog before changing.
      # $ darwin-rebuild changelog
      system.stateVersion = 4;

      # The platform the configuration will be used on.
      nixpkgs.hostPlatform = "aarch64-darwin";
    };
  in
  {
    # Build darwin flake using:
    # $ darwin-rebuild build --flake .#simple
    darwinConfigurations."cassio" = nix-darwin.lib.darwinSystem {
      modules = [ configuration ];
    };

    # Expose the package set, including overlays, for convenience.
    darwinPackages = self.darwinConfigurations."cassio".pkgs;
  };
}

The error I get looks like this:

j@Cassio> ~/bin/update-nix-darwin.sh                                                                                                                                                                                ~
building the system configuration...
error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'darwin-system-24.05.20240415.2b80ce7+darwin4.36524ad'
         whose name attribute is located at /nix/store/z5q9bd70zix9j2gib5ijy31y4w0cw25l-source/pkgs/stdenv/generic/make-derivation.nix:331:7

       … while evaluating attribute 'activationScript' of derivation 'darwin-system-24.05.20240415.2b80ce7+darwin4.36524ad'

         at /nix/store/87clbsxcf2wawlhi49k96ffb805sa3v0-source/modules/system/default.nix:95:7:

           94|
           95|       activationScript = cfg.activationScripts.script.text;
             |       ^
           96|       activationUserScript = cfg.activationScripts.userScript.text;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'mdDoc' missing

       at /nix/store/87clbsxcf2wawlhi49k96ffb805sa3v0-source/modules/documentation/default.nix:121:21:

          120|       default = true;
          121|       description = lib.mdDoc ''
             |                     ^
          122|         Whether to install documentation distributed in packages' `/share/doc`.

It seems to be that the lib input passed to the darwin-system-24.05.20240415.2b80ce7+darwin4.36524ad derivation is missing mdDoc?

Can anybody help me out and tell me what exactly is broken here, and how to fix it? I’d of course like it fixed, but I’d also like to understand what is going wrong here.
Documentation on this kind of thing seems to be rather sparse.

2 Likes

Same on 2019 MacBook Pro x86_64-darwin

[Tracking] Remove all uses of `lib.mdDoc` · Issue #300735 · NixOS/nixpkgs · GitHub - Remove all uses of lib.mdDoc

treewide: remove lib.mdDoc by stuebinm · Pull Request #303841 · NixOS/nixpkgs · GitHub - treewide: remove lib.mdDoc

Encountering an mdDoc related error when updating nix-darwin via flake · Issue #933 · LnL7/nix-darwin · GitHub - Encountering an mdDoc related error when updating nix-darwin via flake

treewide: remove lib.mdDoc by wegank · Pull Request #932 · LnL7/nix-darwin · GitHub - treewide: remove lib.mdDoc

1 Like

Thanks, at least this gives me an idea of what’s going on.

This merged PR about the removal of lib.mdDoc at least shows that what’s going on here isn’t a bug per se, and rather maintenance that needs to be done.

From the fact that I hit this issue though, I infer a couple of things:

  • It will likely be resolved in time. The faster that happens, the better though.
  • It’s likely also present in NixOS, not just in nix-darwin

If this was any other kind of OS (e.g. LSB-based like Debian) I would have severe reservations about trying to update in the meantime. So this is one of those times where I really appreciate being able to perform rollbacks.

I can confirm that this is newly introduced - just hit it on my Mac when removing rustup.

Seems is not in Unstable yet
https://nixpk.gs/pr-tracker.html?pr=304277

There’s a PR for this on the nix-Darwin project, but it hasn’t been approved yet.

4 Likes

Also ran into this today when updating my work system configuration.

3 Likes

encountered this today as well

Thank’s for the link!

I switched to github:NixOs/nixpkgs/master and it works good now but do you know how often they sync master to nixpkgs/nixpkgs-unstable channel?

It seems like the fix has finished propagating through CI/CD.
Issue’s fixed :slight_smile:

1 Like

I am curious as to why people want to run nix on a Mac?

One case would be for devs who develop for iDevices, potentially among other targets. For them, MacOS usage isn’t optional. It’s just easier to manage (system-level e.g. openssl) dependencies, and also keep thing manageable, with Nix.

1 Like

Because the company provides a MacBook and one has to use that MacBook.

Another company I worked for had Managed Unbuntu.

With nix you carry your preferred software and settings with you. Saves a ton of time configuring gpg, ssh, emacs, firefox, alacritty, aws, git, tmux, vim and whatnot.

1 Like
  • macOS is very well optimized with their hardware leading to better battery life even before Apple Silicon
  • With Apple Silicon you get the most efficient laptop you can get (performance per watt)
  • For LLM every Mac now includes a “neural engine” part in their chips
  • If you do not need portability and mobility you can get Ma mini starting at $600
  • From OS stand point it’s pretty good for business tasks and includes everything you need from the beginning.
  • From Nix stand point you probably don’t really need Nix-darwin, if you get a new Mac you can automatically transfer all the files and settings which works perfectly. But if you have multiple Macs and you want to sync their configurations periodically you still might need Nix-darwin

But everything really depends on what exactly are you going to do with it.

2 Likes