snowfallorg / lib

Unified configuration for systems, packages, modules, shells, templates, and more with Nix Flakes.
https://snowfall.org
Other
407 stars 35 forks source link

Problem with nix-darwin #38

Closed YaroKasear closed 10 months ago

YaroKasear commented 10 months ago

I am having a problem getting this lib to work on Apple Silicon macOS with nix-darwin.

darwin-rebuild switch --flake ~/flakes/ yields error: flake 'git+file:///Users/yaro/flakes' does not provide attribute 'packages.aarch64-darwin.darwinConfigurations.Gwyn.system', 'legacyPackages.aarch64-darwin.darwinConfigurations.Gwyn.system' or 'darwinConfigurations.Gwyn.system'

My NixOS system has no problem at all with this. Am I missing something basic here?

flake.nix

{
  description = "The United Flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:NixOS/nixos-hardware/master";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nix-index-database = {
      url = "github:Mic92/nix-index-database";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nix-darwin = {
      url = "github:LnL7/nix-darwin";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    snowfall-lib = {
      url = "github:snowfallorg/lib";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    cowsay = {
      url = "github:snowfallorg/cowsay";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    wallpaper-generator = {
      url = "github:pinpox/wallpaper-generator";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs:
    inputs.snowfall-lib.mkFlake {
      inherit inputs;
      src = ./.;

      snowfall = {
        meta = {
          name = "united-flake";
          title = "The United Flake";
        };
        namespace = "united";
      };

      channels-config = {
        allowUnfree = true;
      };

      systems.modules.nixos = with inputs; [
        home-manager.nixosModules.home-manager
        nixos-hardware.nixosModules.common-pc
        sops-nix.nixosModules.sops
      ];

      systems.modules.darwin = with inputs; [
        home-manager.darwinModules.home-manager
      ];

      systems.hosts.loki.modules = with inputs; [
        nixos-hardware.nixosModules.common-pc-ssd
        nixos-hardware.nixosModules.common-cpu-amd
        nixos-hardware.nixosModules.common-cpu-amd-pstate
        nixos-hardware.nixosModules.common-gpu-nvidia-nonprime
      ];

      homes.users."yaro@loki".modules = with inputs; [
        nix-index-database.hmModules.nix-index
        sops-nix.homeManagerModules.sops
      ];

      homes.users."yaro@Gwyn".modules = with inputs; [
        nix-index-database.hmModules.nix-index
        sops-nix.homeManagerModules.sops
      ];
    };
}

systems/aarch64-darwin/Gwyn/default.nix

{ lib, pkgs, inputs, system, target, format, virtual, systems, config, ... }:

{
  environment.systemPackages = with pkgs; [ ];

  services.nix-daemon.enable = true;
  nix.package = pkgs.nix;

  nix.settings.experimental-features = "nix-command flakes";

  programs = {
    gnupg.agent = {
      enable = true;
      enableSSHSupport = true;
    };
    zsh.enable = true; 
  };

  system.configurationRevision = config.rev or config.dirtyRev or null;

  system.stateVersion = 4;

  nixpkgs.hostPlatform = lib.mkDefault "aarch64-darwin";

  users.users.yaro = {
    home = "/Users/yaro";
    shell = pkgs.zsh;
  };
}

I checked your configs and templates and didn't see anything setting the system variable. I am still working on migrating to snowfall-lib, but as far as I can tell, this should work.

jakehamilton commented 10 months ago

Would you be able to push up this version of your config in a repo on GitHub so I can take a look?

YaroKasear commented 10 months ago

Would you be able to push up this version of your config in a repo on GitHub so I can take a look?

I have it up here. https://github.com/YaroKasear/flakes/tree/main

For now I've reverted on my MacBook back to my pre-snowfall-lib configuration so I can still keep things working there. This library works great on my NixOS box even though I haven't fully migrated yet.

YaroKasear commented 10 months ago

Would you be able to push up this version of your config in a repo on GitHub so I can take a look?

I have it up here. https://github.com/YaroKasear/flakes/tree/main

For now I've reverted on my MacBook back to my pre-snowfall-lib configuration so I can still keep things working there. This library works great on my NixOS box even though I haven't fully migrated yet.

I forgot to update it with the capitalized hostname "Gwyn" instead of "gwyn." But the problem I reported is the same.

jakehamilton commented 10 months ago

Did you make sure to git add the system when trying to build it for the first time? The only problem I found in the flake is that the nix-darwin input needs to be named darwin, but Snowfall Lib logs an error mentioning that.

I was able to clone the repo, change nix-darwin to darwin, and then run darwin-rebuild build --flake .#Gwyn.

jakehamilton commented 10 months ago

I'll also mention that you do not need to add the home-manager module manually. Snowfall Lib will already do that for you 👍

YaroKasear commented 10 months ago

Did you make sure to git add the system when trying to build it for the first time? The only problem I found in the flake is that the nix-darwin input needs to be named darwin, but Snowfall Lib logs an error mentioning that.

I was able to clone the repo, change nix-darwin to darwin, and then run darwin-rebuild build --flake .#Gwyn.

Changed this to 'darwin' and even went as far as a git commit, and no dice.

I tried your variant of the command: darwin-rebuild build --flake .#Gwyn and got:

building the system configuration...
error: flake 'git+file:///Users/yaro/flakes?ref=refs/heads/main&rev=729b2a2e53a7b71e8ef78c2eb6dd32c21905c5fe' does not provide attribute 'packages.aarch64-darwin.darwinConfigurations.Gwyn.system', 'legacyPackages.aarch64-darwin.darwinConfigurations.Gwyn.system' or 'darwinConfigurations.Gwyn.system'
       Did you mean gwyn?

So I tried darwin-rebuild build --flake .#gwyn and got error: cached failure of attribute 'darwinConfigurations.gwyn.system'

Seems like no matter what this thing hates my hostname.

YaroKasear commented 10 months ago

Did you make sure to git add the system when trying to build it for the first time? The only problem I found in the flake is that the nix-darwin input needs to be named darwin, but Snowfall Lib logs an error mentioning that. I was able to clone the repo, change nix-darwin to darwin, and then run darwin-rebuild build --flake .#Gwyn.

Changed this to 'darwin' and even went as far as a git commit, and no dice.

I tried your variant of the command: darwin-rebuild build --flake .#Gwyn and got:

building the system configuration...
error: flake 'git+file:///Users/yaro/flakes?ref=refs/heads/main&rev=729b2a2e53a7b71e8ef78c2eb6dd32c21905c5fe' does not provide attribute 'packages.aarch64-darwin.darwinConfigurations.Gwyn.system', 'legacyPackages.aarch64-darwin.darwinConfigurations.Gwyn.system' or 'darwinConfigurations.Gwyn.system'
       Did you mean gwyn?

So I tried darwin-rebuild build --flake .#gwyn and got error: cached failure of attribute 'darwinConfigurations.gwyn.system'

Seems like no matter what this thing hates my hostname.

Okay, so I rm -rv'd the whole thing and cloned a new copy and this one worked. I am starting to suspect I ran into an annoying "quirk" of macOS here.

YaroKasear commented 10 months ago

So what I think happened is the fact that macOS doesn't make its file system case sensitive by default, so that whenever I tried to rename 'gwyn' to 'Gwyn' or the other way, the filesystem basically ignored it, but Nix actually cares about this case sensitivity.

I really appreciate your help.

jakehamilton commented 10 months ago

Ah, I've run into that exact same problem before! It can certainly be difficult to diagnose. Glad you got things working!