安装 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;
modules = [ ./home.nix ];
extraSpecialArgs = { inherit inputs; }; }; } ); }
|
nix 的语法就不在这里介绍了,还需要创建一个 home.nix
,写入以下内容:
{ inputs, config, pkgs, ... }:
{ 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
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 ];
nixpkgs.overlays = [ inputs.neovim-nightly-overlay.overlays.default ];
fonts.fontconfig.enable = true;
programs.fzf = { enable = true; enableBashIntegration = true; enableZshIntegration = true; };
services.gpg-agent = { enable = false; defaultCacheTtl = 1800; enableSshSupport = true; };
home.shellAliases = { "..." = "cd ../.."; };
home.stateVersion = "24.05";
programs.home-manager.enable = true; }
|
这个文件的配置就是安装和配置软件了,可以看到我定义了一些路径和软件包,以及字体的 override 等,可以按需修改。
安装和更新
nix flake update
更新下仓库
nix-shell -p home-manager
安装一个 home-manager。
home-manager switch --flake .
使用当前配置安装 nix 软件包,其中包括了 home-manager。