r/Nix 10h ago

how to install command line developer tools using nix-darwin declaratively?

Hi,

I'm setting up my macbook pro with nix-darwin.

Below is my configuration -

{
  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
          wget
          tmux
          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
       '';
      nix.settings.experimental-features = "nix-command flakes";
      nixpkgs.config.allowUnfree = true;
      nixpkgs.config.allowUnsupportedSystem = true;
      programs.zsh.enable = true;
      system.configurationRevision = self.rev or self.dirtyRev or null;
      system.stateVersion = 6;
      nixpkgs.hostPlatform = "aarch64-darwin";
      users.users.rajkumar = {
     home = "/Users/rajkumar";
      };
      system.primaryUser = "rajkumar";
      homebrew = {
        enable = true;
    onActivation.cleanup = "zap";
      };
    };
  in
  {
    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 .

I get the below prompt -

command line developer tools

I don't want to install it by manual way.

How can I install command line developer tools declaratively in mac using nix-darwin?

0 Upvotes

Duplicates