LnL7 / nix-darwin

nix modules for darwin
MIT License
2.77k stars 429 forks source link

Flake: does not provide attributes 'packages.x86_64-darwin.darwinConfigurations.userName.system' #297

Closed happysalada closed 3 years ago

happysalada commented 3 years ago

Trying to use flakes for the first time. I'm getting the following error

flake 'git+file:///Users/raphael/.dotfiles?dir=nix' does not provide attribute 'packages.x86_64-darwin.darwinConfigurations.yt.system', 'legacyPackages.x86_64-darwin.darwinConfigurations.yt.system' or 'darwinConfigurations.yt.system'

Here is the configuration I am using

{
  description = "yt's darwin system";

  inputs = {
    # Package sets
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    nixpkgs-stable-darwin.url = "github:nixos/nixpkgs/nixpkgs-20.09-darwin";

    # Environment/system management
    darwin.url = "github:lnl7/nix-darwin";
    darwin.inputs.nixpkgs.follows = "nixpkgs";
    home-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";

    # Editor
    nix-doom-emacs.url = "github:vlaci/nix-doom-emacs/no-checks";

    # nix
    nixpkgs-update.url = "github:ryantm/nixpkgs-update";

    # Other sources
    flake-compat = { url = "github:edolstra/flake-compat"; flake = false; };
  };

  outputs = { self, nixpkgs, darwin, home-manager, nix-doom-emacs, flake-compat, nixpkgs-update, ... }@inputs: {

    # My `nix-darwin` configs
    darwinConfigurations.raphael = darwin.lib.darwinSystem {
      modules = [
        ./darwin.nix
        # `home-manager` module
        home-manager.darwinModules.home-manager
        {
          # `home-manager` config
          home-manager.useGlobalPkgs = true;
          home-manager.users.raphael = import ./home.nix {inherit nix-doom-emacs nixpkgs-update;};
        }
      ];
    };
  };
}

Here is what I have in darwin.nix

{ pkgs, ... }:
{
  environment = {
    systemPackages = with pkgs; [
      openssl
      gnupg
      exa # better ls
      ripgrep # better grep
      tealdeer # terser man
      fd # improved find
      procs # process monitor
      # tailscale # vpn management # not supported on macos
      # smartmontools # ssd health monitoring
      s3cmd # used for backups

      borgbackup # backup

      mdbook # for documentation sites

      # nix
      nodePackages.node2nix

    ];
    variables = {
      EDITOR = "emacsclient -c";
      LANG = "en_US.UTF-8";
    };
    darwinConfig = "$HOME/.dotfiles/nix/darwin.nix";
  };

  programs = {
    gnupg.agent = {
      enable = true;
      enableSSHSupport = true;
    };
    fish = {
      enable = true;
      useBabelfish = true;
      babelfishPackage = pkgs.babelfish;
    };
  };

  fonts = {
    enableFontDir = true;
    fonts = [ pkgs.fira-code ];
  };

  system.defaults = {
    NSGlobalDomain = {
      AppleMeasurementUnits = "Centimeters";
      AppleMetricUnits = 1;
      AppleShowScrollBars = "Automatic";
      AppleTemperatureUnit = "Celsius";
      AppleKeyboardUIMode = 3;
      ApplePressAndHoldEnabled = false;
      InitialKeyRepeat = 10;
      KeyRepeat = 3;
      _HIHideMenuBar = true;
    };

    dock = {
      autohide = true;
      mru-spaces = false;
      tilesize = 512;
    };

    finder = {
      AppleShowAllExtensions = true;
      QuitMenuItem = true;
      FXEnableExtensionChangeWarning = false;
    };

    trackpad = {
      Clicking = true;
      TrackpadThreeFingerDrag = true;
      TrackpadRightClick = true;
    };

    # Login and lock screen
    loginwindow = {
      GuestEnabled = false;
    };
  };

  networking = {
    dns = [
      # provided by nextdns
      "45.90.28.43"
      "45.90.30.43"
      # defaults
      "1.1.1.1"
      "8.8.8.8"
    ];
    knownNetworkServices = [
      "Wi-Fi"
      "Bluetooth PAN"
      "Thunderbolt Bridge"
      "NextDNS"
      "Tailscale Tunnel"
    ];
    hostName = "yt";
  };

  nix = {
    useDaemon = true;
    package = pkgs.nixFlakes;
    extraOptions =
      "experimental-features = nix-command flakes"; # not working on macos
    maxJobs = 4;
    buildCores = 4;
    gc = {
      automatic = true;
      options = "--delete-older-than 7d";
      interval = {
        Hour = 24;
        Minute = 0;
      };
    };
  };

  nixpkgs.config = {
    allowUnfree = true;
    packageOverrides = pkgs: {
      nur = import (builtins.fetchTarball {
        url = "https://github.com/nix-community/NUR/archive/master.tar.gz";
        sha256 = "1c3rh7x8bql2m9xcn3kvdqng75lzzf6kpxb3m6knffyir0jcrfrh";
      }) { inherit pkgs; };
    };
    # allow until openssl is updated
    permittedInsecurePackages = [ "openssl-1.0.2u" ];
  };

  users.users.raphael = {
    home = /Users/raphael;
    description = "Raphael megzari";
  };

  services = {
    nix-daemon.enable = true;
    # smartd = { enable = true; }; # unavailable on macos
    # avahi.enable = true; # unavailable on macos

    nextdns = {
      enable = true;
      arguments = [ "-config" "e42bf1" ];
    };
  };
}

Let me know if you want more information. I basically took my old darwin config and just removed the import <nixpkgs-unstable from it. Thanks you for providing nix-darwin!

happysalada commented 3 years ago

It appears to be that the machine is asking me to provide the configuration for another user that I created before. Could it be that upon switching to a flake, a configuration for every user is required?

happysalada commented 3 years ago

I could finally switch to it, but I had to provide an additional user that I'm not really sure where it comes from. I added

    darwinConfigurations.yt = darwin.lib.darwinSystem {
      modules = [./darwin.nix];
    };

And I could actually switch to the flake.

LnL7 commented 3 years ago

This should work the same as NixOS, the current hostname is used to select the default configuration. So if that does not (yet) match the the configuration you want to apply it must be specified, eg. --flake .#yt.

happysalada commented 3 years ago

Thanks a lot for always taking the time to answer even noob questions! ❤️