Convert darwin home-manager config to flakes

(Sorry for the incoherence of this question; I’ve gone slightly mad after spending all evening on this. I also expect my setup to be extremely borked in a number of ways other than the one I’m asking about, because after several months I have still managed not to pick up any fluency or intuition for Nix at all.)

I am trying to convert my Darwin home-manager config to use flakes. The PR is Use flakes by Smaug123 · Pull Request #6 · Smaug123/nix-dotfiles · GitHub, and the commit at which I see this particular problem is Use flakes by Smaug123 · Pull Request #6 · Smaug123/nix-dotfiles · GitHub.

darwin-rebuild build --flake .#patrick


warning: Git tree '/Users/patrick/.nixpkgs' is dirty
building the system configuration...
warning: Git tree '/Users/patrick/.nixpkgs' is dirty
error: in pure evaluation mode, 'fetchTarball' requires a 'sha256' argument
(use '--show-trace' to show detailed location information)                

For a start, ~/.nixpkgs is clean according to Git, so I don’t know why I’m being told (twice!) that it’s dirty.

But I have no idea what it’s trying to fetchTarball, and --show-trace is as usual impenetrable (and doesn’t mention fetchTarball at all).

I’m sure there’s an obvious way to get this working, which I will find after a few weeks of thinking and mashing the keyboard; but the ideal answer would be someone pushing it to my PR :stuck_out_tongue:

For convenience, here is the flake.nix (nix-dotfiles/flake.nix at bf760287b3804640ca67afb1e4a63201fb3acb15 · Smaug123/nix-dotfiles · GitHub):

  description = "Patrick's Darwin Nix setup";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    darwin = {
      url = "github:lnl7/nix-darwin/master";
      inputs.nixpkgs.follows = "nixpkgs";
    emacs.url = "github:nix-community/emacs-overlay/master";

  outputs = { self, darwin, nixpkgs, home-manager, emacs }: {
    darwinConfigurations = {
        patrick = darwin.lib.darwinSystem {
          system = "aarch64-darwin";
          modules = [ ./darwin-configuration.nix ];

Darwin-configuration (nix-dotfiles/darwin-configuration.nix at bf760287b3804640ca67afb1e4a63201fb3acb15 · Smaug123/nix-dotfiles · GitHub):

{ pkgs, inputs, ... }:

  inherit (inputs) home-manager emacs;

let python = import ./python.nix { inherit pkgs; }; in


  nix.useDaemon = true;

  home-manager.useGlobalPkgs = true;
  home-manager.useUserPackages = true;
  home-manager.users.Patrick = import ./home.nix { emacs = emacs; pkgs = pkgs; };

  # List packages installed in system profile. To search by name, run:
  # $ nix-env -qaP | grep wget

  environment.systemPackages =

  # This line is required; otherwise, on shell startup, you won't have Nix stuff in the PATH.
  programs.zsh.enable = true;

  # Use a custom configuration.nix location.
  # $ darwin-rebuild switch -I darwin-config=$HOME/.config/nixpkgs/darwin/configuration.nix
  environment.darwinConfig = "$HOME/.nixpkgs/darwin-configuration.nix";

  nixpkgs.overlays = import ./overlays.nix;

  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (pkgs.lib.getName pkg) [

  # Auto upgrade nix package and the daemon service.
  services.nix-daemon.enable = true;
  nix.package = pkgs.nixFlakes;
  nix.gc.automatic = true;

  # Sandbox causes failure:
  nix.useSandbox = false;

  nix.extraOptions = ''
    auto-optimise-store = true
    experimental-features = nix-command flakes

  # Used for backwards compatibility, please read the changelog before changing.
  # $ darwin-rebuild changelog
  system.stateVersion = 4;

home.nix (nix-dotfiles/home.nix at bf760287b3804640ca67afb1e4a63201fb3acb15 · Smaug123/nix-dotfiles · GitHub):

{ pkgs, emacs, ... }:

let username = "Patrick"; in
let dotnet = pkgs.dotnet-sdk_6; in

  imports = [ ./rider ];

  rider = { enable = true; username = username; dotnet = dotnet; };

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;

  # Home Manager needs a bit of information about you and the
  # paths it should manage.
  home.username = username;

  # This value determines the Home Manager release that your
  # configuration is compatible with. This helps avoid breakage
  # when a new Home Manager release introduces backwards
  # incompatible changes.
  # You can update Home Manager without changing this value. See
  # the Home Manager release notes for a list of state version
  # changes in each release.
  home.stateVersion = "22.05";

  home.packages =

At various other points, I’ve had more success, e.g. Use flakes by Smaug123 · Pull Request #6 · Smaug123/nix-dotfiles · GitHub got me as far as “attribute rust-analyzer missing” in the build of nix-dotfiles/home.nix at fd95ecf38fa4a326d5108e56f61b4ee90568646c · Smaug123/nix-dotfiles · GitHub. That seems more obviously “something someone can easily help with”: why is the rust-analyzer attribute on my nixpkgs from the flake not making it all the way down to my home.nix?

That’s normal if you haven’t committed the changes in your working directory. I usually just ignore it while I’m working on a flake.

overlays.nix is using fetchTarball to fetch nix-community/emacs-overlay. Have you tried referencing their flake instead?

My working directory was definitely clean according to git status; I checked multiple times, and also my zsh prompt tells me passively. This happened on bf76028 but is no longer happening at later commits, so I’m happy to ignore that mystery.

Ah, thanks - it would have been lovely if any part of the stack trace had shown me that!

In the interests of getting anything working, I’ve just removed emacs entirely. Nix continues to surprise me at every command with the impenetrability of its error messages (which home-manager did warn me about, in fairness!), but I’m once again not at the stage where I have run out of things to try, so I’ll come back when I’m fully stuck again.