Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

External Usage

This flake exposes its modules for consumption by other configurations (like nix-work), allowing for a layered configuration approach where dotfiles.nix provides the base.

Exported Modules

  • sharedModules: Core system configuration, packages, and shared Home Manager modules.
  • macModules: macOS-specific system modules and settings.

Output Structure

The flake outputs are structured to be easily consumed:

outputs = { ... }: {
  sharedModules = [ ... ]; # Base modules
  macModules = [ ... ];    # macOS modules
  lib = { ... };           # Helper library
};

Example: nix-work Consumption

To build a work configuration on top of this base:

{
  inputs.base.url = "github:ojsef39/dotfiles.nix";

  outputs = { base, ... }: {
    darwinConfigurations.workMac = darwin.lib.darwinSystem {
      modules =
        base.outputs.sharedModules
        ++ base.outputs.macModules
        ++ [
          ./work-specific-config.nix
        ];
      specialArgs = {
        baseLib = base.lib;
      };
    };
  };
}

Remote building

(with 1Password as SSH Agent)

nix build .#darwinConfigurations.mac.system --builders 'ssh://<user>@<ip> x86_64-linux,aarch64-darwin'

Caution

Make sure you ran sudo ssh <user>@<ip> first and accept the host key dialog, otherwise remote build will fail as that runs as root (nix daemon).

This only works because of modules/darwin/system/system.nix:

    activationScripts = {
      preActivation.text = ''
        plist="/Library/LaunchDaemons/systems.determinate.nix-daemon.plist"
        desired="/Users/${vars.user.name}/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"

        current=$(/usr/libexec/PlistBuddy -c "Print :EnvironmentVariables:SSH_AUTH_SOCK" "$plist" 2>/dev/null || echo "")

        if [ "$current" != "$desired" ]; then
          /usr/libexec/PlistBuddy -c "Add :EnvironmentVariables dict" "$plist" 2>/dev/null || true
          /usr/libexec/PlistBuddy -c "Set :EnvironmentVariables:SSH_AUTH_SOCK '$desired'" "$plist" 2>/dev/null || \
          /usr/libexec/PlistBuddy -c "Add :EnvironmentVariables:SSH_AUTH_SOCK string '$desired'" "$plist"

          if launchctl print system/systems.determinate.nix-daemon &>/dev/null; then
            launchctl unload /Library/LaunchDaemons/systems.determinate.nix-daemon.plist
            launchctl load /Library/LaunchDaemons/systems.determinate.nix-daemon.plist
          fi
        fi
      '';

      # example for linux
      # systemd.services.nix-daemon = {
      #   environment = {
      #     SSH_AUTH_SOCK = "/run/user/${builtins.toString config.users.users.${username}.uid}/${
      #       config.home-manager.users.${username}.services.ssh-agent.socket
      #     }";
      #   };
      # };
    };
  };