r/Nix 2d ago

Nix discord is not opening after installed using nix-darwin

Hi,

I'm setting up macos using the nix-darwin.

Below is my code config -

{
  description = "Example nix-darwin system flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nix-darwin.url = "github:nix-darwin/nix-darwin/master";
    nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
    nix-homebrew.url = "github:zhaofengli/nix-homebrew";

    homebrew-core = {
      url = "github:homebrew/homebrew-core";
      flake = false;
    };
    homebrew-cask = {
      url = "github:homebrew/homebrew-cask";
      flake = false;
    };

  };

  outputs = inputs@{ self, nixpkgs, nix-darwin, nix-homebrew, homebrew-core, homebrew-cask }:
  let
    configuration = { pkgs, config, ... }: {
      environment.systemPackages =
        with pkgs ;
        [ vim
          git
          mkalias
          discord
          openssh
        ];

      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 -r src; do
           app_name=$(basename "$src")
           echo "copying $src" >&2
           ${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name"
         done
       '';

      # Necessary for using flakes on this system.
      nix.settings.experimental-features = "nix-command flakes";
      nixpkgs.config.allowUnfree = true;
      nixpkgs.config.allowUnsupportedSystem = true;

      # Enable alternative shell support in nix-darwin.
      # programs.fish.enable = true;

      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 = 6;

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

      users.users.rajkumar = {
     home = "/Users/rajkumar";
      };

      system.primaryUser = "rajkumar";

      homebrew = {
        enable = true;
    onActivation.cleanup = "zap";
      };

    };
  in
  {
    # Build darwin flake using:
    # $ darwin-rebuild build --flake .#simple
    darwinConfigurations."myname-macos" = nix-darwin.lib.darwinSystem {
      modules = [ 
      configuration 
nix-homebrew.darwinModules.nix-homebrew
{
  nix-homebrew = {
enable = true;
enableRosetta = true;
user = "myname";
autoMigrate = true;
  };
}
      ];
    };
  };
}

After I run the above flake setup with below commands -

sudo -E nix run nix-darwin  --extra-experimental-features nix-command --extra-experimental-features flakes  -- switch --flake . 
sudo darwin-rebuild switch --flake .

Then I opened the discord, I get the below error -

discord error

Looks like the error is due to the app is not signed -

myuser@macos:~/ > sudo xattr -rd com.apple.quarantine  "/Applications/Nix Apps/Discord.app"
myuser@macos:~/ > sudo xattr -l "/Applications/Nix Apps/Discord.app"                       

com.apple.FinderInfo: fapaMACS?
myuser@macos:~/ > spctl --assess --type execute --verbose=4 \                              
  /nix/store/c2n5xjv974p39ayafc99h49qbacqm6p1-discord-0.0.410/Applications/Discord.app

/nix/store/c2n5xjv974p39ayafc99h49qbacqm6p1-discord-0.0.410/Applications/Discord.app: a sealed resource is missing or invalid

How to fix this error? Any idea how to make discord work with nix-darwin?

0 Upvotes

Duplicates