Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homebrew error with nix-darwin - "Error: invalid option: --no-lock" #1369

Open
victorhooi opened this issue Mar 5, 2025 · 9 comments
Open

Comments

@victorhooi
Copy link

I have a macOS 15.3.1 (Sequioia) machine. I've installed Nix using the Determinate Systems NIx installer (not the Determinate distro, but vanilla Nix) and installed nix-darwin per the nix-darwin README.

I then edited /etc/nix-darwin/flake.nix, to add a Homebrew section:

victorhooi@MacBook-Pro:/etc/nix-darwin/ > cat flake.nix 
{
  description = "Example nix-darwin system flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nix-darwin.url = "github:LnL7/nix-darwin/master";
    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 =
        [ pkgs.vim
        ];

      homebrew = {
        enable = true;
        # onActivation.cleanup = "uninstall";

        taps = [];
        brews = [ "cowsay" ];
        casks = [];
      };


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

      # Enable alternative shell support in nix-darwin.
      # programs.fish.enable = 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 = 6;

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

After running darwin-rebuild switch, I get an error from Homebrew about Error: invalid option: --no-lock:

victorhooi@MacBook-Pro:/etc/nix-darwin/ > darwin-rebuild switch
building the system configuration...
Password:
setting up user launchd services...
Homebrew bundle...
Usage: brew bundle [subcommand]

Bundler for non-Ruby dependencies from Homebrew, Homebrew Cask, Mac App Store,
Whalebrew and Visual Studio Code.

brew bundle [install]:
    Install and upgrade (by default) all dependencies from the Brewfile.

You can specify the Brewfile location using --file or by setting the
$HOMEBREW_BUNDLE_FILE environment variable.

You can skip the installation of dependencies by adding space-separated values
to one or more of the following environment variables:
$HOMEBREW_BUNDLE_BREW_SKIP, $HOMEBREW_BUNDLE_CASK_SKIP,
$HOMEBREW_BUNDLE_MAS_SKIP, $HOMEBREW_BUNDLE_WHALEBREW_SKIP,
$HOMEBREW_BUNDLE_TAP_SKIP.

brew bundle upgrade:
    Shorthand for brew bundle install --upgrade.

brew bundle dump:
    Write all installed casks/formulae/images/taps into a Brewfile in the
current directory.

brew bundle cleanup:
    Uninstall all dependencies not present in the Brewfile.

This workflow is useful for maintainers or testers who regularly install lots of
formulae.

Unless --force is passed, this returns a 1 exit code if anything would be
removed.

brew bundle check:
    Check if all dependencies present in the Brewfile are installed.

This provides a successful exit code if everything is up-to-date, making it
useful for scripting.

brew bundle list:
    List all dependencies present in the Brewfile.

By default, only Homebrew formula dependencies are listed.

brew bundle edit:
    Edit the Brewfile in your editor.

brew bundle exec command:
    Run an external command in an isolated build environment based on the
Brewfile dependencies.

This sanitized build environment ignores unrequested dependencies, which makes
sure that things you didn't specify in your Brewfile won't get picked up by
commands like bundle install, npm install, etc. It will also add compiler
flags which will help with finding keg-only dependencies like openssl,
icu4c, etc.

brew bundle sh:
    Run your shell in a brew bundle exec environment.

brew bundle env:
    Print the environment variables that would be set in a brew bundle exec
environment.

      --file                       Read the Brewfile from this location. Use
                                   --file=- to pipe to stdin/stdout.
      --global                     Read the Brewfile from
                                   $HOMEBREW_BUNDLE_FILE_GLOBAL (if set),
                                   ${XDG_CONFIG_HOME}/homebrew/Brewfile (if
                                   $XDG_CONFIG_HOME is set),
                                   ~/.homebrew/Brewfile or ~/.Brewfile
                                   otherwise.
  -v, --verbose                    install prints output from commands as they
                                   are run. check lists all missing
                                   dependencies.
      --no-upgrade                 install does not run brew upgrade on
                                   outdated dependencies. check does not check
                                   for outdated dependencies. Note they may
                                   still be upgraded by brew install if
                                   needed. This is enabled by default if
                                   $HOMEBREW_BUNDLE_NO_UPGRADE is set.
      --upgrade                    install runs brew upgrade on outdated
                                   dependencies, even if
                                   $HOMEBREW_BUNDLE_NO_UPGRADE is set. 
      --install                    Run install before continuing to other
                                   operations e.g. exec.
  -f, --force                      install runs with --force/--overwrite.
                                   dump overwrites an existing Brewfile.
                                   cleanup actually performs its cleanup
                                   operations.
      --cleanup                    install performs cleanup operation, same as
                                   running cleanup --force. This is enabled by
                                   default if $HOMEBREW_BUNDLE_INSTALL_CLEANUP
                                   is set and --global is passed.
      --all                        list all dependencies.
      --formula, --brews           list or dump Homebrew formula
                                   dependencies.
      --cask, --casks              list or dump Homebrew cask dependencies.
      --tap, --taps                list or dump Homebrew tap dependencies.
      --mas                        list or dump Mac App Store dependencies.
      --whalebrew                  list or dump Whalebrew dependencies.
      --vscode                     list or dump VSCode extensions.
      --no-vscode                  dump without VSCode extensions. This is
                                   enabled by default if
                                   $HOMEBREW_BUNDLE_DUMP_NO_VSCODE is set.
      --describe                   dump adds a description comment above each
                                   line, unless the dependency does not have a
                                   description. This is enabled by default if
                                   $HOMEBREW_BUNDLE_DUMP_DESCRIBE is set.
      --no-restart                 dump does not add restart_service to
                                   formula lines.
      --zap                        cleanup casks using the zap command
                                   instead of uninstall.
  -d, --debug                      Display any debugging information.
  -q, --quiet                      Make some output more quiet.
  -h, --help                       Show this message.
Error: invalid option: --no-lock
@bensleveritt
Copy link

Updating nix-darwin fixed it for me.

@Zeirison
Copy link

Zeirison commented Mar 5, 2025

@bensleveritt I have the same issue and I installed nix from scratch today, how exactly can I "update" nix-darwin?

I've already tried:

nix-channel --update
nix-env -u '*'
nix-collect-garbage --delete-old
nix run --refresh nix-darwin/nix-darwin-24.11#darwin-rebuild

Maybe the issue can only be solved by updating to "unstable", but I wouldn't want to.

Thanks!

@rafiv
Copy link

rafiv commented Mar 5, 2025

The Update now leads to the following error for me, when doing a rebuild:

error: builder for '/nix/store/syh7llgfnv7k8cy80aspinpqswwv6x49-darwin-system-25.05.991bb2f.drv' failed with exit code 1;
       last 7 log lines:
       >
       > In /nix/store/i90ysy96yh0ay5dwskihin2k4rjk3ipq-darwin-system-25.05.991bb2f/activate line 1355:
       > while read src; do
       >       ^--^ SC2162 (info): read without -r will mangle backslashes.
       >
       > For more information:
       >   https://www.shellcheck.net/wiki/SC2162 -- read without -r will mangle backs...
       For full logs, run 'nix log /nix/store/syh7llgfnv7k8cy80aspinpqswwv6x49-darwin-system-25.05.991bb2f.drv'.

@emilazy
Copy link
Collaborator

emilazy commented Mar 5, 2025

I have the same issue and I installed nix from scratch today, how exactly can I "update" nix-darwin?

I've already tried:

nix-channel --update
nix-env -u '*'
nix-collect-garbage --delete-old
nix run --refresh nix-darwin/nix-darwin-24.11#darwin-rebuild

Maybe the issue can only be solved by updating to "unstable", but I wouldn't want to.

Thanks!

@Zeirison If you’re using a flake, then run nix flake update in its directory.

The Update now leads to the following error for me, when doing a rebuild:

@rafiv This is code you’ve added to your activation scripts (apparently it’s something people have copy‐pasted from a YouTube video a lot or something?). Using read -r should fix it.

@RobbieMcKinstry
Copy link

I encountered this error out of the blue today. nix flake update solved it immediately 👍🏻 Thank you!

@honeyyadav
Copy link

Worked like a charm, thanks @RobbieMcKinstry

@iamppborah
Copy link

nix flake update worked! Thanks :)

@TimoBechtel
Copy link

For anyone coming from Google because of the "Error: invalid option: --no-lock"

The --no-lock option was removed from brew bundle :)

see:
Homebrew/homebrew-bundle@98d8ad7

Seems like it was a noop before so I assume it is safe to just remove the --no-lock flag.

(unrelated to nix / nix-darwin)

geggo98 added a commit to geggo98/dotfiles that referenced this issue Mar 9, 2025
- fix: Fix for "invalid option: --no-lock"
(LnL7/nix-darwin#1369)
@sukhmel
Copy link

sukhmel commented Mar 12, 2025

I encountered this error out of the blue today. nix flake update solved it immediately 👍🏻 Thank you!

I'd recommend trying nix flake update darwin first, as full update may update inputs you don't want updated.

For me almost every time I do full flakes update I have to then cherry-pick broken packages from older versions, but maybe that's just because I'm on unstable by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants