Skip to content

Running a locally patched version of nix darwin

Nathan Henrie edited this page Oct 26, 2022 · 1 revision

Occasionally one might want to run a patched version of nix-darwin, for example to take advantage of a pull request that has not yet been merged.

One approach is to use a local copy if the nix-darwin repo, with the relevant code checked out.

Alternatively, for e.g. the pull request at https://github.com/LnL7/nix-darwin/pull/550, one can append .patch to the URL: https://patch-diff.githubusercontent.com/raw/LnL7/nix-darwin/pull/550.patch

The patch could then be locally referenced from a flake like so (copied from this comment):

{
  description = "...";

  inputs = {
    nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-22.05-darwin";

    darwin = {
      url = "github:lnl7/nix-darwin";
      inputs.nixpkgs.follows = "nixpkgs-darwin";
    };
  };

  outputs = inputs @ { self, nixpkgs-darwin, ... }:
    let
      darwin =
        let
          src = nixpkgs.legacyPackages."aarch64-darwin".applyPatches {
            name = "nix-darwin";
            src = inputs.darwin;
            patches = [
              ./patches/nix-darwin-submodules.patch
            ];
          };
        in
        nixpkgs.lib.fix (self: (import "${src}/flake.nix").outputs { inherit self nixpkgs; });
      cfg = {
        config = {
          allowUnfree = true;
        };
      };
    in
    {
      darwinConfigurations."MyMachineName" =
        let
          system = "aarch64-darwin";
          darwinPkgs = nixpkgs-darwin.legacyPackages.${system};
        in
        darwin.lib.darwinSystem {
...
    };
}
Clone this wiki locally