安装 nix

sh <(curl -L https://nixos.org/nix/install) --no-daemon

配置

创建文件 ~/.config/nix/nix.conf,写入以下内容:

experimental-features = nix-command flakes

创建目录 ~/.config/home-manager/,需要两个文件,我的配置里使用 flake 作为辅助,所以先创建 flake.nix 文件,写入以下内容:

{
description = "Home Manager configuration for Me QwQ";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
neovim-nightly-overlay = {
url = "github:nix-community/neovim-nightly-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, flake-utils, nixpkgs, home-manager, neovim-nightly-overlay, ... }@inputs:
flake-utils.lib.eachDefaultSystemPassThrough (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in {
homeConfigurations.lxz = home-manager.lib.homeManagerConfiguration {
inherit pkgs;

# Specify your home configuration modules here, for example,
# the path to your home.nix.
modules = [
./home.nix
];

# Optionally use extraSpecialArgs
# to pass through arguments to home.nix
extraSpecialArgs = { inherit inputs; };
};
}
);
}

nix 的语法就不在这里介绍了,还需要创建一个 home.nix,写入以下内容:

{ inputs, config, pkgs, ... }:

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

home.packages = with pkgs; [
git-lfs
neofetch
htop
ripgrep
lazygit
gh
go
cargo
lemonade
nix-index
nix-update

# font
noto-fonts
noto-fonts-cjk
noto-fonts-emoji
liberation_ttf
fira-code
fira-code-symbols
fira-code-nerdfont
sarasa-gothic
(nerdfonts.override { fonts = [ "FiraCode" "DroidSansMono" ]; })

nodejs

# neovim nightly
neovim
# neovim-nightly
];

nixpkgs.overlays = [
inputs.neovim-nightly-overlay.overlays.default
];

fonts.fontconfig.enable = true; # Allow fontconfig to discover fonts in home.packages

programs.fzf = {
enable = true;
enableBashIntegration = true;
enableZshIntegration = true;
};

services.gpg-agent = {
enable = false;
defaultCacheTtl = 1800;
enableSshSupport = true;
};

home.shellAliases = {
"..." = "cd ../..";
};

home.stateVersion = "24.05";

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

这个文件的配置就是安装和配置软件了,可以看到我定义了一些路径和软件包,以及字体的 override 等,可以按需修改。

安装和更新

nix flake update 更新下仓库

nix-shell -p home-manager 安装一个 home-manager。

home-manager switch --flake . 使用当前配置安装 nix 软件包,其中包括了 home-manager。