zhaofengli / nix-homebrew

Homebrew installation manager for nix-darwin
MIT License
274 stars 13 forks source link

Installation problem #5

Open jcszymansk opened 1 year ago

jcszymansk commented 1 year ago

I tried to use nix-homebrew to manage my brew installation which in turn manages brews and casks. So far it was managed with nix-darwin homebrew.* options.

After installing brews are causing no problems, but after every darwin-rebuild switch --flake . brew attempts to reinstall all casks and then finishes with the following error:

Error: Refusing to untap homebrew/cask because it contains the following installed formulae or casks:

I have also tried removing homebrew completely and installing it from scratch with nix-homebrew, to no avail, the effect is exactly the same.

My darwin configuration is as follows:

      darwinConfigurations."adapa" = darwin.lib.darwinSystem {
        system = "x86_64-darwin";
        modules = [
          nix-homebrew.darwinModules.nix-homebrew
          {
            nix-homebrew = {
              enable = true;
              user = "jsz";
              taps = with inputs; {
                "homebrew/homebrew-core" = homebrew-core;
                "homebrew/homebrew-cask" = homebrew-cask;
              };
              mutableTaps = false;
            };
          }
          ./systems/adapa/configuration.nix
        ];
      };

and homebrew related configuration in configuration.nix:

  homebrew = {
    enable = true;

    onActivation = {
      cleanup = "uninstall";
      # this sucks, as the entire homebrew does. gah
      autoUpdate = true;
      upgrade = true;
    };

    global.autoUpdate = false;

    masApps = {
      "Microsoft To Do" = 1274495053;
    };

    brews = [
      "libxml2"
      "libxslt"
      "sox"
    ];

    caskArgs.no_quarantine = true;

    casks = [
     "macfuse"
     "quicksilver"
     "firefox"
     "flux"
     "maestral"
     "eclipse-jee"
     "maccy"
     "docker"
     "virtualbox"
     "soapui"
    ];
  };
gshpychka commented 10 months ago

Same here, although this does not seem to be affecting anything. @zhaofengli is this expected?

gshpychka commented 10 months ago

Figured it out - this is because nix-darwin's homebrew module is trying to untap all taps due to its taps attribute being empty by default.

Passing all taps to it solves the issue for me. In nix-darwin's homebrew:

    taps = builtins.attrNames config.nix-homebrew.taps;
robwilkerson commented 1 month ago

Okay, I'm going to go ahead and apologize for being a NixOS n00b here, but where does this line sit...contextually? The error doesn't seem to break anything, but I'd like to avoid future confusion and also better understand the config.

outputs = inputs@{ self, nix-darwin, nixpkgs, nix-homebrew, homebrew-core, homebrew-cask, homebrew-bundle, homebrew-nikitabobko }:
  let
    configuration = { pkgs, config, ... }: {

      nixpkgs.config.allowUnfree = true;

      # List packages installed in system profile. To search by name, run:
      # $ nix-env -qaP | grep wget
      environment.systemPackages =
        [ 
          pkgs.vim
          # ALLTHETHINGS
        ];

      homebrew = {
        enable = true;

        brews = [
          "mas"
        ];

        casks = [
          # ALLTHETHINGS
        ];

        # App store apps (requires the "mas" brew above)
        masApps = {
          # ALLTHETHINGS
        };

        # Keep this declaritive by killing packages that aren't listed here
        onActivation.cleanup = "zap";
        onActivation.autoUpdate = true;
        onActivation.upgrade = true;
      };

      fonts.packages = with pkgs; [
          pkgs.meslo-lgs-nf # For use with Powerlevel10K
        ];

      # Configure nix to create Mac-supported aliases when adding
      # GUI apps in the /Applications directory; this allows them
      # to be indexed by Spotlight, Alfred, etc.
      # DOES NOT SEEM TO WORK (at least not for Alfred)
      system.activationScripts.applications.text = let
        env = pkgs.buildEnv {
          name = "system-applications";
          paths = config.environment.systemPackages;
          pathsToLink = "/Applications";
        };
      in
        pkgs.lib.mkForce ''
        # Set up applications.
        echo "setting up /Applications..." >&2
        rm -rf /Applications/Nix\ Apps
        mkdir -p /Applications/Nix\ Apps
        find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
        while read src; do
          app_name=$(basename "$src")
          echo "copying $src" >&2
          ${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name"
        done
            '';

      # 
      # SYSTEM SETTINGS
      # 

      # https://mynixos.com/nix-darwin/options
      system.keyboard.enableKeyMapping = true;
      system.keyboard.remapCapsLockToEscape = true;
      };

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

      # 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;

      # 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 = 5;

      # The platform the configuration will be used on.
      nixpkgs.hostPlatform = "aarch64-darwin";

      programs.zsh.promptInit = "source ${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/powerlevel10k.zsh-theme";
    };
  in
  {
    # Build darwin flake using:
    # $ darwin-rebuild build --flake .#simple
    darwinConfigurations."personal" = nix-darwin.lib.darwinSystem {
      modules = [ 
        configuration 
        nix-homebrew.darwinModules.nix-homebrew {
          nix-homebrew = {
            enable = true;
            enableRosetta = true; # Apple Silicon only
            user = "me";

            taps = {
              "homebrew/homebrew-core"   = inputs.homebrew-core;
              "homebrew/homebrew-cask"   = inputs.homebrew-cask;
              "homebrew/homebrew-bundle" = inputs.homebrew-bundle;
              "nikitabobko/homebrew-tap" = inputs.homebrew-nikitabobko;
            };

            # Enable fully-declarative tap management
            # With mutableTaps disabled, taps can no longer be added imperatively with `brew tap`.
            mutableTaps = false;
          };
          taps = builtins.attrNames config.nix-homebrew.taps;
        }
      ];
    };

    # Expose the package set, including overlays, for convenience.
    darwinPackages = self.darwinConfigurations."personal".pkgs;
  };
CerebralXor commented 1 month ago

@robwilkerson

Okay, I'm going to go ahead and apologize for being a NixOS n00b here, but where does this line sit...contextually? The error doesn't seem to break anything, but I'd like to avoid future confusion and also better understand the config.

Insert the lines marked below in to your config.

  outputs = inputs@{ self, nix-darwin, nixpkgs, nix-homebrew, homebrew-core, homebrew-cask, homebrew-bundle }:
  let
    # ...
  in
  {
    # Build darwin flake using:
    # $ darwin-rebuild build --flake .#macbook
    darwinConfigurations."macbook" = nix-darwin.lib.darwinSystem {
      modules = [
        ({ config, ... }: {                                                          # <--
          homebrew.taps = builtins.attrNames config.nix-homebrew.taps;               # <--
        })                                                                           # <--
        configuration
        nix-homebrew.darwinModules.nix-homebrew {
          nix-homebrew = {
            # Install Homebrew under the default prefix
            enable = true;
            # Apple Silicon Only: Also install Homebrew under the default Intel prefix for Rosetta 2
            enableRosetta = true;
            # User owning the Homebrew prefix
            user = "myuser";
            # Declarative tap management
            taps = {
              "homebrew/homebrew-bundle" = inputs.homebrew-bundle;
              "homebrew/homebrew-core" = homebrew-core;
              "homebrew/homebrew-cask" = homebrew-cask;
            };
            # With mutableTaps disabled, taps can no longer be added imperatively with `brew tap`.
            mutableTaps = false;
          };
        }
      ];
    };
robwilkerson commented 1 month ago

({ config, ... }: { # <-- homebrew.taps = builtins.attrNames config.nix-homebrew.taps; # <-- })

Thank you, @CerebralXor ! The error is no more.

I'm glad I asked the question. I hadn't had any luck in my searches and I can't even imagine how much trial & error it would've taken me to get to this solution. :-)