Unable to use services
Karrq opened this issue · comments
I tried enabling emacs-plus' service, but an error occurs when the service is configured.
setting up user launchd services...
Homebrew bundle...
Using emacs-plus
Error: cannot load such file -- /Homebrew/service
/nix/store/ys4kqcgld76ys01x4m6czj2l7kbn66f8-source/lib/service/formula_wrapper.rb:206:in `require_relative'
/nix/store/ys4kqcgld76ys01x4m6czj2l7kbn66f8-source/lib/service/formula_wrapper.rb:206:in `load_service'
/nix/store/ys4kqcgld76ys01x4m6czj2l7kbn66f8-source/lib/service/formula_wrapper.rb:67:in `service_startup?'
/nix/store/ys4kqcgld76ys01x4m6czj2l7kbn66f8-source/lib/service/services_cli.rb:280:in `service_load'
/nix/store/ys4kqcgld76ys01x4m6czj2l7kbn66f8-source/lib/service/services_cli.rb:122:in `block in start'
/nix/store/ys4kqcgld76ys01x4m6czj2l7kbn66f8-source/lib/service/services_cli.rb:97:in `each'
/nix/store/ys4kqcgld76ys01x4m6czj2l7kbn66f8-source/lib/service/services_cli.rb:97:in `start'
/nix/store/ys4kqcgld76ys01x4m6czj2l7kbn66f8-source/lib/service/commands/restart.rb:31:in `run'
/opt/homebrew/Library/Taps/homebrew/homebrew-services/cmd/services.rb:126:in `services'
/opt/homebrew/Library/Homebrew/brew.rb:94:in `<main>'
I have the same error when just using brew services
to list the available services
You need to add the homebrew/homebrew-services
tap manually in your config, just like the others.
I actually did, I added homebrew-services
to my flake inputs and then specified "homebrew/homebrew-services" = inputs.homebrew-services"
in my nix-homebrew.taps
These re my taps:
taps = with inputs; {
"homebrew/homebrew-bundle" = homebrew-bundle;
"homebrew/homebrew-core" = homebrew-core;
"homebrew/homebrew-cask" = homebrew-cask;
"homebrew/homebrew-services" = homebrew-services;
"d12frosted/homebrew-emacs-plus" = emacs-plus;
};
What about your nix-darwin.homebrew.taps
?
That's left null actually - I had an issue before when I tried specifying my taps there...
Try this, maybe it will help: https://github.com/gshpychka/dotfiles/blob/436e5e6399878b2c65d736d0a99ccdf3fb6d7a5b/machines/eve/homebrew.nix#L9
Well that didn't cause issue like I saw before, but I still can't use brew services
Well that didn't cause issue like I saw before, but I still can't use
brew services
why not?
Same error as before...
This is due to brew services
using ruby's require_relative
.
Homebrew/homebrew-services/lib/service/formula_wrapper.rb:204
# The purpose of this function is to lazy load the Homebrew::Service class
# and avoid nameclashes with the current Service module.
# It should be used instead of calling formula.service directly.
def load_service
require_relative "../../../../../Homebrew/service"
formula.service
end
The file it's looking for is /opt/homebrew/Library/Homebrew/service.rb
but when taps are in the Nix store it resolves to /nix/store/Homebrew/service.rb
. Using require_relative
seems like bad practice although I know next to nothing about ruby. I just edited the file and changed it to require_relative "/opt/homebrew/Library/Homebrew/service"
to see if that worked and it did.
I have no idea how to implement a real fix.
Okay, this feels like an absolutely ridiculous way to fix this, but I ended up applying a patch to the homebrew-services flake input. I'll include the patch and an abridged version of my configuration.
--- a/lib/service/formula_wrapper.rb 2024-06-08 17:48:09.693241764 -0500
+++ b/lib/service/formula_wrapper.rb 2024-06-08 17:49:08.262498938 -0500
@@ -201,7 +201,7 @@
# and avoid nameclashes with the current Service module.
# It should be used instead of calling formula.service directly.
def load_service
- require_relative "../../../../../Homebrew/service"
+ require_relative "/opt/homebrew/Library/Homebrew/service"
formula.service
end
In the flake inputs:
homebrew-services = {
url = "github:homebrew/homebrew-services";
flake = false;
};
In the outputs:
darwinConfigurations = nixpkgs.lib.genAttrs darwinSystems (
system: let
user = "harry";
homebrew-services-patched = nixpkgs.legacyPackages."${system}".applyPatches {
name = "homebrew-services-patched";
src = homebrew-services;
patches = [./homebrew-services.patch];
};
in
darwin.lib.darwinSystem {
modules = [
nix-homebrew.darwinModules.nix-homebrew
{
nix-homebrew = {
inherit user;
enable = true;
taps = {
"homebrew/homebrew-core" = homebrew-core;
"homebrew/homebrew-cask" = homebrew-cask;
"homebrew/homebrew-bundle" = homebrew-bundle;
"homebrew/homebrew-services" = homebrew-services-patched;
};
mutableTaps = false;
autoMigrate = true;
};
}
];
}
);
Obviously I have removed a lot of my configuration just to shorten things but you get the gist of it.