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

Open command ignores --args #17

Open
2 tasks
gaufde opened this issue Jan 6, 2025 · 4 comments
Open
2 tasks

Open command ignores --args #17

gaufde opened this issue Jan 6, 2025 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@gaufde
Copy link

gaufde commented Jan 6, 2025

I am using nix-darwin to install PyCharm:

{
  description = "nix-darwin system flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nix-darwin.url = "github:LnL7/nix-darwin";
    nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
    home-manager.url = "github:nix-community/home-manager/master";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    mac-app-util.url = "github:hraban/mac-app-util";
    nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew";
  };

  outputs = inputs@{ self, nix-darwin, nixpkgs, mac-app-util, nix-homebrew, home-manager }:
    let
      mkDarwinSystem = { systemParams ? { } }:
        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.jetbrains.pycharm-professional
              ];

            homebrew = {
              enable = true;
              brews = [
                "mas"
              ];
              casks = [
                "firefox"
              ];
              onActivation.cleanup = "zap";
            };

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

            # Home manager (see https://www.youtube.com/watch?v=k9yKm_k5cVA&t=184s).
            users.users.gaufde.home = "/Users/gaufde";
            home-manager.backupFileExtension = "backup";
            nix.configureBuildUsers = true;
            nix.useDaemon = true;

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

            # Enable alternative shell support in nix-darwin.
            programs.zsh.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";
          };
        in
        nix-darwin.lib.darwinSystem {
          modules = [
            configuration
            mac-app-util.darwinModules.default
            nix-homebrew.darwinModules.nix-homebrew
            {
              nix-homebrew = {
                enable = true;
                enableRosetta = true;
                user = "gaufde";
              };
            }
            home-manager.darwinModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.users.gaufde = import ./home.nix;
              _module.args.systemParams = systemParams;
            }
          ];
        };
    in
    {
      # Build darwin flake using:
      # $ darwin-rebuild build --flake .#m1macbookpro
      darwinConfigurations = {
        # Default configuration
        "m1macbookpro" = mkDarwinSystem {
          systemParams = {
            restore = false;
          };
        };

        # Restore configuration
        "m1macbookpro-restore" = mkDarwinSystem {
          systemParams = {
            restore = true;
          };
        };
      };

      darwinPackages = self.darwinConfigurations."m1macbookpro".pkgs;
    };
}

This seems to work since spotlight is able to find PyCharm. However, I like to open my projects in PyCharm like this:

open -nb "com.jetbrains.pycharm" --args "/Users/gaufde/Path/To/ProjectDir"

Unfortunately, this only opens the PyCharm app. The path argument seems to be ignored. If I use the homebrew cask to install PyCharm instead, then the above script works perfectly.

I am very new to Nix still, and so I'm not super familiar with all the pieces yet. But, is this functionality something that I should expect to work with mac-app-util configured the way it is above?

 nix-info -m
 - system: `"aarch64-darwin"`
 - host os: `Darwin 23.6.0, macOS 14.7.2`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.24.11`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/store/rr1allmsx88garhjfkfsj14z3d9qf8b6-source`
  • I have substituted 7 sections in this template.
  • I have tested this with the nixpkgs-unstable branch and the problem persists
@hraban
Copy link
Owner

hraban commented Jan 6, 2025

Yep this is a known problem and I'm not sure it can be solved using just applescript. I tried my hand at this in https://github.com/hraban/mac-app-util/tree/pure-osascript but it didn't seem to pan out. I'm working on seeing if maybe a fully compiled swift app can do this.

It's not a priority for me, and not to be too lawyery about it, but: it's not listed as a feature of this app :) the primary goal is "launch an application from spotlight." It would of course be nice to support generic open ... too, but since I don't really use that myself, I'm in no particular hurry :D

Anyway, valid point, not saying it's WONTFIX, but definitely not jumping on this any time soon :)

@gaufde
Copy link
Author

gaufde commented Jan 6, 2025

Thanks for the fast response!

It's not a priority for me, and not to be too lawyery about it, but: it's not listed as a feature of this app :) the primary goal is "launch an application from spotlight." It would of course be nice to support generic open ... too, but since I don't really use that myself, I'm in no particular hurry :D

I totally understand, I just wanted to ask since it seems related to this app's purpose.

Do you know what the underlying issue is? There is a gist that tries to solve the spotlight problem a different way: https://gist.github.com/elliottminns/211ef645ebd484eb9a5228570bb60ec3, but is full open ... support something that is generally tricky with symlinks/aliases?

I think that if needed, I can move all my GUI-based apps to brew to solve this issue.

@hraban
Copy link
Owner

hraban commented Jan 6, 2025

That uses mkalias which is a fundamentally different approach which is incompatible with certain apps , and yields very inconsistent results with spotlight indexing unfortunately. I cut my teeth on this with applescript and I have a very strong feeling the only way forward is a full-blown objective-c / swift app which does the trampolining. I've just written literally zero lines of either of those ever so it's gonna take a while to even get that ball rolling I'm afraid :/

@hraban hraban added the documentation Improvements or additions to documentation label Jan 6, 2025
@hraban
Copy link
Owner

hraban commented Jan 6, 2025

I should probably at least add an explicit note in the readme about "why not mkalias" because it's a recurring question.

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

No branches or pull requests

2 participants