dustinlyons / nixos-config

General purpose Nix configuration for macOS / NixOS with starter templates + step-by-step guides ✨
BSD 3-Clause "New" or "Revised" License
1.63k stars 102 forks source link

How to upgrade everything installed (Mac OSX Sonoma)? #48

Closed oscarvarto closed 9 months ago

oscarvarto commented 9 months ago

Hi!

I have seen the video posted in the README about updating "dependencies" with one command. I am not sure the video is updated neither that this instruction will upgrade my installed packages.

Lastly, how can I clean up/collect some of the garbage that could be outdated in my installation, just like I would do in a NixOS installation?

dustinlyons commented 9 months ago

Hi, the video is out of date. I just moved the script to run under nix run .#build-switch.

Nix is self-contained, it only knows about what is defined in flake.nix. So if you're running brew commands Nix will have no knowledge of those. Adversely, it will mutate your system in a way that is not conducive to Nix (being self contained, defined by a flake.nix declaration). So you'll see weird behavior.

If you want to use Nix and brew, let Nix manage brew for you (like this config).

There is a big "leap" in Nix in that you're moving from imperative commands (typing commands into your terminal to do something), to defining what you're configuration should be and letting Nix do it for you (nix flake update; nix run .#build-switch).

Over the past year, I only run nix flake update and nix run .#build-switch to alter my system, outside of a few throw away applications.

dustinlyons commented 9 months ago

For example, I don't run brew commands. I run my main nix run .#build-switch command that runs brew for me.

See this link of where I define what brew package I want Nix to install for me: https://github.com/dustinlyons/nixos-config/blob/main/modules/darwin/home-manager.nix#L26

oscarvarto commented 9 months ago

I installed several (homebrew) things using your repo code. However, I didn't noticed that doing nix flake update then nix run .#build-switch upgraded my homebrew installed packages. For example, I have this in my modules/darwin/home-manager.nix:

  homebrew = {
    enable = true;
    brews = [
      {
        name = "d12frosted/emacs-plus/emacs-plus";
        args = [ "with-xwidgets" "with-native-comp" "with-poll" ];
        link = true;
      }
    ];
    casks = pkgs.callPackage ./casks.nix {};

    onActivation = {
      extraFlags = [ "--verbose" ];
    };

    masApps = {
      "Amazon Prime Video" = 545519333;
      "WhatsApp Messenger" = 310633997;
    };
  };

In a different (Mac OS X, intel Sonoma, no nix, used for work activities) computer with homebrew, I noticed my Emacs Plus formula was updated from 29.1 to 29.2. Even when I have been regularly "upgrading" (doing nix flake update then nix run .#build-switch) my nix installation, I never noticed that it tried to recompile my Emacs Plus installation, for example, until I manually executed brew upgrade && brew update && brew update --cask && brew cleanup today in the morning (CST time zone).

I have a section like this in my flake.nix:

             nix-homebrew = {
                enable = true;
                user = "${user}";
                taps = {
                  "homebrew/homebrew-core" = homebrew-core;
                  "homebrew/homebrew-cask" = homebrew-cask;
                  "homebrew/homebrew-cask-versions" = homebrew-cask-versions;
                  "homebrew/homebrew-bundle" = homebrew-bundle;
                  "d12frosted/homebrew-emacs-plus" = homebrew-emacs-plus;
                };
                mutableTaps = false;
                autoMigrate = true;
              };

Could I possibly be missing something @dustinlyons ?

Edit: Here is my current configuration, based on your code: https://github.com/oscarvarto/nixos-config

dustinlyons commented 9 months ago

Okay, sorry I left some previous comments but I don't think I understood the problem. Now I see. You're saying there are updates available, but Nix can't see them; only if you run brew do you see them.

I honestly don't know much about the internals of nix-homebrew. If you run nix flake update, my understanding is that your flake lock file gets updated with the latest hash for brew packages, casks, etc. You might ask this question over there.

In general, I try not to use brew packages and keep things in Nix land. When I do use brew or mas, I generally let those packages update however they want (auto update, or not using Nix.) But your question still stands-- why doesn't nix flake update bring in the latest brew versions, but using brew update does?

oscarvarto commented 9 months ago

Exactly, this is my actual question: why doesn't nix flake update bring in the latest brew versions, but using brew update does? However, I've decided to not use nix on Mac OSX, and use traditional installation of my stuff. Not worth the additional overhead/complexity for my use cases.

dustinlyons commented 9 months ago

@oscarvarto you may look at this option if you ever get back to Nix

https://daiderd.com/nix-darwin/manual/index.html#opt-homebrew.onActivation.autoUpdate