Running home manager independently of nix-darwin

I’ve got a flake that looks like this:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
    home-manager = {
      url = "github:nix-community/home-manager/release-24.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nix-darwin = {
      url = "github:LnL7/nix-darwin/nix-darwin-24.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, home-manager, nix-darwin }@inputs: {
    darwinConfigurations = {
      matrixbook = nix-darwin.lib.darwinSystem {
        system = "aarch64-darwin";
        modules = [
          ./matrixbook/configuration.nix
          home-manager.darwinModules.home-manager
          {
            home-manager = {
              useGlobalPkgs = true;
              useUserPackages = true;
              extraSpecialArgs = { inherit inputs; };
              users."user" = import ./home-manager/common.nix;
              sharedModules = [
                ./home-manager/darwin-home.nix
                ./home-manager/wezterm-config.nix
                ./home-manager/zellij-config.nix
                ./home-manager/nixpkgs.nix
                ./home-manager/nushell.nix
              ];
            };
          }
        ];
        specialArgs = { inherit inputs; inherit self; };
      };
    };
    darwinPackages = self.darwinConfigurations."matrixbook".pkgs;
  };
}

If I run this command, my changes are applied, hurray!

sudo nix run nix-darwin -- switch --flake .

But at my new job I have to jump through some hoops to run sudo commands. Certainly some changes require sudo, but I’d expect that certain other changes do not. For the latter sort, I’d like to be able to apply my changes without invoking sudo.

Naively, I’d hope for this to work:

nix run home-manager -- switch --flake .

But apparently I am missing something, because I get errors like this:

❯  nix run home-manager -- switch --flake .
error: flake 'git+file:///Users/user/src/configs' does not provide attribute 'packages.aarch64-darwin.homeConfigurations', 'legacyPackages.aarch64-darwin.homeConfigurations' or 'homeConfigurations'
error: flake 'git+file:///Users/user/src/configs' does not provide attribute 'packages.aarch64-darwin.homeConfigurations', 'legacyPackages.aarch64-darwin.homeConfigurations' or 'homeConfigurations'
error: flake 'git+file:///Users/user/src/configs' does not provide attribute 'packages.aarch64-darwin.homeConfigurations', 'legacyPackages.aarch64-darwin.homeConfigurations' or 'homeConfigurations'
error: flake 'git+file:///Users/user/src/configs' does not provide attribute 'packages.aarch64-darwin.homeConfigurations."user".activationPackage', 'legacyPackages.aarch64-darwin.homeConfigurations."user".activationPackage' or 'homeConfigurations."user".activationPackage'

Is there a different command I can use, or an alteration to my flake structure, which will let me make some changes without requiring sudo?

This is what your flake needs to provide for this to work.
Also 24.11 is long dead, switch to 25.05.

1 Like

Thanks, that’s what I needed to hear. I ended up with this:

outputs = { self, nixpkgs, nix-darwin, home-manager }:
  let
    username = "user";
    homeDirectory = "/Users/user";
    system = "aarch64-darwin";
    extraSpecialArgs = { inherit username homeDirectory; };
    sharedModules = [
      ./home-manager/wezterm-config.nix
      ./home-manager/zellij-config.nix
      ./home-manager/nushell.nix
      ...
    ];
  in
  {
    homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.${system};
      modules = sharedModules;
      inherit extraSpecialArgs;
    };
    darwinConfigurations."hostname" = nix-darwin.lib.darwinSystem {
      inherit system;
      specialArgs = { inherit self nixpkgs home-manager; };
      modules = [
        ./hostname/configuration.nix
        home-manager.darwinModules.home-manager
        {
          home-manager = {
            useUserPackages = true;
            useGlobalPkgs = true;
            inherit extraSpecialArgs;
            users.${username} = {
              imports = sharedModules;
            };
          };
        }
      ];
    };
  };