Homemanager 选项不是套餐类型

问题描述 投票:0回答:1

我想以模块化的方式使用 nix-darwin (这意味着每个包都是它自己的 .nix 文件,其中包含所有必要的选项)。

但是,当我执行时出现错误

nix build .#darwinConfigurations.atlas.system

错误:选项

home-manager.users.tk.home.packages."[definition 4-entry 1]"' is not of type 
package'的定义。

这是我的

flake.nix
文件

{
  inputs = {
    nixpkgs.url = "nixpkgs/nixos-unstable";
    darwin.url = "github:LnL7/nix-darwin";
    home-manager.url = "github:nix-community/home-manager";
  };

  outputs = { self, nixpkgs, darwin, home-manager }:
    let
      system = "aarch64-darwin";
    in {
      darwinConfigurations.atlas = darwin.lib.darwinSystem {
        modules = [
          ./hosts/atlas.nix
        ];
        specialArgs = {
          inherit nixpkgs home-manager;
        };
      };
    };
}

这是

atlas.nix

{ config, pkgs, home-manager, ... }:

let
  user = "tk";
  packageList = [
    (import ../packages/alacritty.nix { inherit pkgs; })
  ];
in
{
  imports = [
    home-manager.darwinModules.home-manager
  ];

  nixpkgs.hostPlatform = "aarch64-darwin";

  users.users.${user} = {
    name = "${user}";
    home = "/Users/${user}";
    isHidden = false;
    shell = pkgs.zsh;
  };

  home-manager = {
    useGlobalPkgs = true;
    users.${user} = {
      pkgs,
      config,
      lib,
      ...
    }: {
      home = {
        enableNixpkgsReleaseCheck = false;
        stateVersion = "23.11";
        packages = packageList;
      };
    };
  };
}

最后

alacritty.nix

{ pkgs, ... }: {
  pkgs.alacritty = {
    enable = true;
  };
}

我对 Nix 语言还很陌生,并且对语法很困惑。有人能找出问题所在吗?

macos nix nixos nix-darwin
1个回答
0
投票

好的,我现在明白了。

这是我的

flake.nix

{
  description = "Darwin configuration";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    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";
  };

  outputs = inputs@{ nixpkgs, home-manager, darwin, ... }: {
    darwinConfigurations = {
      atlas = darwin.lib.darwinSystem {
        system = "aarch64-darwin";
        modules = [
          ./hosts/atlas.nix
          home-manager.darwinModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.tk = import ./home.nix;
          }
        ];
        specialArgs = {inherit inputs;};
      };
    };
  };
}

还有

atlas.nix

{ config, pkgs, home-manager, ... }:
{
  nixpkgs.hostPlatform = "aarch64-darwin";
  services.nix-daemon.enable = true;
  users.users.tk = {
    name = "tk";
    home = "/Users/tk";
  };
}

home.nix

{
  inputs,
  outputs,
  lib,
  config,
  pkgs,
  home-manager,
  ...
}: {
  imports = [
    ./packages/alacritty.nix
  ];

  programs.home-manager.enable = true;
  home.stateVersion = "24.05";
}

alacritty.nix

{
  programs.alacritty = {
    enable = true;
  };
}
© www.soinside.com 2019 - 2024. All rights reserved.