(入门安装 3 使用 Home Manager )nixos 从0实现全集 梦中情os
nixos
#基本安装
在想使用flakes之前你最好对nixos有初步的了解,知道 configuration.nix 的基本配置
基础安装参考。
flake参考。
使用 Home Manager 必须有良好的网络环境,意味着你需要解决科学上网的问题。
#/etc/nixos/home.nix
创建/etc/nixos/home.nix
nix
{ config, pkgs, ... }:
{
# 注意修改这里的用户名与用户目录
home.username = "yh";
home.homeDirectory = "/home/yh";
# 也可以在这里ln文件到用户目录,或者直接text写文件到用户目录
# 通过 home.packages 安装一些常用的软件
# 这些软件将仅在当前用户下可用,不会影响系统级别的配置
# 建议将所有 GUI 软件,以及与 OS 关系不大的 CLI 软件,都通过 home.packages 安装 这里就安装了一个 neofetch
home.packages = with pkgs;[
neofetch
];
home.stateVersion = "23.11";
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
}
#修改/etc/nixos/flake.nix
原始内容
nix
{
outputs = { self, nixpkgs }: {
# replace 'vm-nixo' with your hostname here.
nixosConfigurations.vm-nixos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [ ./configuration.nix ];
};
};
}
修改为
nix
{
description = "NixOS configuration";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
home-manager = {
url = "github:nix-community/home-manager/release-23.11";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ nixpkgs, home-manager, ... }: {
nixosConfigurations = {
# 这里的 vm-nixos 替换成你的主机名称
vm-nixos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
# 将 home-manager 配置为 nixos 的一个 module
# 这样在 nixos-rebuild switch 时,home-manager 配置也会被自动部署
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
# 这里的 ryan 也得替换成你的用户名
# 这里的 import 函数在前面 Nix 语法中介绍过了,不再赘述
home-manager.users.yh = import ./home.nix;
# 取消注释下面这一行,就可以在 home.nix 中使用 flake 的所有 inputs 参数了
# home-manager.extraSpecialArgs = inputs;
}
];
};
};
};
}
#构建
sh
sudo nixos-rebuild switch --flake '/etc/nixos#vm-nixos'
# 如果主机名一样,可以忽略flake参数
sudo nixos-rebuild switch
这样构建完成后 用户yh 就可以使用 neofetch