Skip to the content.

NixOS 初步尝试

声明:

我在使用 NixOS 的时候,一度想要放弃,最终勉强坚持下来了。

之所以坚持使用 NixOS ,是因为我感觉 NixOS 非常符合计算机的思维, 那就是相同的问题仅仅解决一次,而这个问题是 环境配置。

安装

手动安装

手动分区

参考官方教程 以及

创建分区,安装操作系统,并且初始化 nixos

因为是在 QEMU 中,所以暂时使用的 MBR 的分区,而不是 GPT

sudo -i
parted /dev/vda -- mklabel msdos
parted /dev/vda -- mkpart primary 1MiB -20GB
parted /dev/vda -- mkpart primary linux-swap -20GB 100%
mkfs.ext4 -L nixos /dev/vda1
mount /dev/disk/by-label/nixos /mnt
mkswap -L swap /dev/vda2
swapon /dev/vda2
nixos-generate-config --root /mnt

打开配置 /mnt/etc/nixos/configuration.nix 中实现 uefi 启动,并且含有 grub

 # 将这行注释掉
 # boot.loader.systemd-boot.enable = true;
 # 增加下如下内容
  boot = {
    loader = {
      efi = {
        canTouchEfiVariables = true;
        efiSysMountPoint = "/boot";
      };
      grub = {
        devices = [ "nodev" ];
        efiSupport = true;
      };
    };
  };
  1. 添加基本的工具方便之后使用
environment.systemPackages = with pkgs; [
  vim
  git
  wget
  zsh
];

最后,执行 nixos-install,然后就是等待,最后你需要输入密码,这是 root 的密码,然后重启,进入下一个阶段。

我在这里踩的坑

安装系统

使用 root 用户登录进去:

  1. 创建 martins 用户,主要是为了创建 /home/martins3 目录出来
useradd -c 'martins three' -m martins3
su -l martins3
  1. 导入本配置的操作:
git clone https://github.com/Martins3/My-Linux-Config
git checkout feat

执行 ./scripts/install.sh 将本配置的文件软链接的位置。

  1. su
  2. 执行 ./scripts/nixos-install.sh

  3. 切换为 martins3,开始部署 home-manager 配置
# 安装home-manager
nix-shell '<home-manager>' -A install
home-manager switch

在图形界面的安装

  1. 2.2. Graphical Installation : 建议图形化安装 遇到网络问题,执行如下内容
sudo chmod +w /etc/nixos/configuration.nix
sudo vim /etc/nixos/configuration.nix
# 在配置中增加上
# networking.proxy.default = "http://192.168.64.62:8889"; # 需要提前搭梯子
sudo nixos rebuild
  1. 重启
  2. 首先解决网络问题,使用 sed 将 /etc/nixos/configuration.nix 中的 networking.proxy 的两个配置修改正确。
  3. 打开 shell,执行 nix-shell -p vim git ,然后
git clone https://github.com/Martins3/My-Linux-Config .dotfiles
# nixos 的安装
sudo /home/martins3/.dotfiles/scripts/nixos-install.sh
# 其他的工具的安装
/home/martins3/.dotfiles/scripts/install.sh

最开始的时候无法 ssh ,所以以上操作都需要在图形界面中操作。

高级

关于 reproducible build

常见操作

nix-prefetch-url https://github.com/Aloxaf/fzf-tab

自动环境加载

echo "use nix" >> .envrc
direnv allow

npm 包管理

之后,安装无需使用 sudo 了

npm install -g @lint-md/cli@beta
# npm i -g bash-language-server
# npm install -g vim-language-server
npm install -g prettier
# npm install -g @microsoft/inshellisense

共享

使用 samba 实现目录共享

参考配置: https://gist.github.com/vy-let/a030c1079f09ecae4135aebf1e121ea6

此外,在 Linux 中设置

sudo smbpasswd -a martins3

在 windows 虚拟机中,打开文件浏览器, 右键 网络,选择 映射网络驱动器,在文件夹中填写路径 \\10.0.2.2\public 即可。

如果遇到需要密码的时候,但是密码不对

sudo smbpasswd -a martins3

在 windows 那一侧使用 martins3 和新设置的密码来登录。

syncthing

强烈推荐,相当于一个自动触发的 rsync ,配置也很容易:

使用注意项,可以在两个机器中编辑同一个文件夹中的文件,但是注意不要同时多个机器上编辑同一个文件,否则存在冲突。

python

pip3 install http # 会提示你,说无法可以安装 python39Packages.pip
nix-shell -p python39Packages.pip # 好的,安装了
pip install http # 会提升你,需要安装 setuptools
pip install setuptools # 结果 readonly 文件系统

参考这里 在 home/cli.nix 中添加上内容,但是会遇到这个问题,

  home.packages = with pkgs; [

正确的解决办法是,之后,就按照正常的系统中使用 python:

python -m venv .venv
source .venv/bin/activate

[ ] cpp

别人也遇到了类似的问题:

所以这才是正确的操作吗? https://www.reddit.com/r/NixOS/comments/fdi3jb/gcc1_doesnt_work_gives_weird_internalish_errors/

似乎这个东西叫做 user environment: https://nixos.wiki/wiki/User_Environment

https://xieby1.github.io/scripts/index.html

nix-shell '<nixpkgs>' -A lua --command zsh

kernel

总体来说,构建

pkgs.stdenv.mkDerivation 和 pkgs.mkShell 的区别是什么

For ephemeral environments mkShell is probably easier to use, as it is meant to be used just for this.

If you though have something you want to build and want to derive an exact build environment without any extras from it, then use mkDerivation to build the final package and get the Dev env for free from it.

pkgs.mkShell is a specialized stdenv.mkDerivation that removes some repetition when using it with nix-shell (or nix develop).

代理

https://yacd.metacubex.one/#/proxies

交叉编译

参考:

tmux

为了让 tmux 配置的兼容其他的 distribution ,所以 tpm 让 nixos 安装,而剩下的 tmux 插件由 tmp 安装。

gui

虽然暂时没有 gui 的需求,但是还是收集一下,以后在搞:

安装 unstable 的包

一种方法是:

  /* google-chrome-stable = pkgs.callPackage ./programs/google-chrome-stable.nix {}; */
  nixpkgs_unstable = import
    (builtins.fetchTarball {
      url = "https://github.com/NixOS/nixpkgs/archive/ac608199012d63453ed251b1e09784cd841774e5.tar.gz";
      sha256 = "0bcy5aw85f9kbyx6gv6ck23kccs92z46mjgid3gky8ixjhj6a8vr";
    })
    { config.allowUnfree = true; };

但是更加简单的是直接 install :

[ ] 如何安装 tarball 的包

按照 https://unix.stackexchange.com/questions/646319/how-do-i-install-a-tarball-with-home-manager 的提示, rnix-lsp 可以,但是 x86-manpages 不可以

gcc 和 clang 是冲突的

blog

Are We Getting Too Many Immutable Distributions?

打个包吧

tutorial

nix pill

how to learn nix

nix.dev

可以关注一下: https://nix.dev/anti-patterns/language

安装特定版本的程序

let
  old = import
    (builtins.fetchTarball {
      url = "https://github.com/NixOS/nixpkgs/archive/7d7622909a38a46415dd146ec046fdc0f3309f44.tar.gz";
    })
    { };

  clangd13 = old.clang-tools;
in {
  home.packages = with pkgs; [
  clangd13

使用特定版本的 gcc 或者 llvm

shell.nix 和 default.nix 的区别

虚拟化

其他有趣的 Linux Distribution

值得一看的资料

[ ] flake.nix

实验特性

switch caps 和 escape

https://unix.stackexchange.com/questions/377600/in-nixos-how-to-remap-caps-lock-to-control

似乎需要:

gsettings reset org.gnome.desktop.input-sources xkb-options
gsettings reset org.gnome.desktop.input-sources sources

也许也需要执行下: setxkbmap -option caps:swapescape

问题

需要验证的问题

Nix/NixOs 踩坑记录

最近时不时的在 hacknews 上看到 nix 相关的讨论:

Ian Henry 的How to Learn Nix 写的好长啊,

问题

这三个命令的区别是什么:

文档

manual : https://nixos.org/manual/nix/stable/introduction.html

This means that it treats packages like values in purely functional programming languages such as Haskell — they are built by functions that don’t have side-effects, and they never change after they have been built. 充满了哲学的感觉啊。

For example, the following command gets all dependencies of the Pan newsreader, as described by its Nix expression:

nix-shell '<nixpkgs>' -A pan

The main command for package management is nix-env.

Components are installed from a set of Nix expressions that tell Nix how to build those packages, including, if necessary, their dependencies. There is a collection of Nix expressions called the Nixpkgs package collection that contains packages ranging from basic development stuff such as GCC and Glibc, to end-user applications like Mozilla Firefox. (Nix is however not tied to the Nixpkgs package collection; you could write your own Nix expressions based on Nixpkgs, or completely new ones.)

  1. Nix Expressions 实际上是在描述一个包是如何构建的
  2. Nixpkgs 是一堆社区构建好的
  3. 完全可以自己来构建这些内容

You can view the set of available packages in Nixpkgs:

nix-env -qaP

The flag -q specifies a query operation, -a means that you want to show the “available” (i.e., installable) packages, as opposed to the installed packages, and -P prints the attribute paths that can be used to unambiguously select a package for installation (listed in the first column).

You can install a package using nix-env -iA. For instance,

nix-env -iA nixpkgs.subversion

Profiles and user environments are Nix’s mechanism for implementing the ability to allow different users to have different configurations, and to do atomic upgrades and rollbacks.

直接跳转到 Chapter 5

使用 https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/hello/default.nix 作为例子。

manual : https://nixos.org/manual/nixpkgs/stable/

manual : https://nixos.org/manual/nixpkgs/unstable/

你需要认真学习一波

https://www.reddit.com/r/NixOS/comments/119sfg8/how_long_did_it_take_you_to_really_grok_nixos/

文摘

资源

目前最好的教程,应该上手完成之后,就使用这个

关键参考

https://github.com/xieby1/nix_config

similar project

一个快速的教程

https://nixery.dev/nix-1p.html

问题

warning: not including '/nix/store/ins8q19xkjh21fhlzrxv0dwhd4wq936s-nix-shell' in the user environment because it's not a directory
nix-env -f ./linux.nix -i
shell-nix --cmd zsh
nix-env -i -f https://github.com/nix-community/rnix-lsp/archive/master.tar.gz

之后重新安装之后,就可以出现:

Oops, Nix failed to install your new Home Manager profile!

Perhaps there is a conflict with a package that was installed using
"nix-env -i"? Try running

    nix-env -q

and if there is a conflicting package you can remove it with

    nix-env -e {package name}

Then try activating your Home Manager configuration again.
$ nix-shell -E 'with import <nixpkgs> {}; linux.overrideAttrs (o: {nativeBuildInputs=o.nativeBuildInputs ++ [ pkg-config ncurses ];})'
[nix-shell] $ unpackPhase && cd linux-*
[nix-shell] $ make menuconfig

nur

https://nur.nix-community.org/

到底如何编译 Linux 内核

https://ryantm.github.io/nixpkgs/builders/packages/linux/

有趣

桌面环境

曾经简单的尝试过如下:

但是发现其中存在很多小问题,很多配置也是没怎么维护,所以还是使用默认的 gnome 了。

4k 屏幕

虽然,我没有做过图形开发,但是我估计适配 4k 屏幕是个非常复杂的问题,Linux 目前对于这个问题处理的也不是很好:

例如

组件

nixos 的

https://www.youtube.com/@NixCon

更新 nixos 为 22.11

内容参考这里:

垃圾清理

sudo nix-collect-garbage -d

nix-store –gc sudo nixos-rebuild boot

遇到了相同的问题(boot 分区满了),头疼: https://discourse.nixos.org/t/what-to-do-with-a-full-boot-partition/2049/13

搞了半天,这应该是是一个 bug ,这个时候需要手动删除 /boot 下的一些内容才可以。

包搜索

静态编译

应该使用这种方法: nix-shell -p gcc glibc.static

devenv

如何使用

如何安装 steam

但是社区感觉实在是太复杂了,所以存在一个专门的 hacking:

nixpkgs.config.allowUnfree = true;
programs.steam.enable = true;

装好之后,发现也没啥用。

nix-index 是做什么的

自定义字体

但是不知道如何指定安装这个!

和各种 dotfile manager 的关系是什么

nix M1

vpn

tailscale

[ ] wireguard

wasm

似乎 wasm 的配置很复杂,连最基本的配置都搞不定:

这个人解决了问题,最后的评论中看到了 flake.nix,还有 flake.lock,我的鬼鬼!

如果彻底搞定后,可以尝试下这个: https://github.com/casonadams/z-tab-bar

nixops

记录一次断电的处理

因为小米智障插座,直接断电,导致磁盘信息不对。

export PATH=/nix/var/nix/profiles/system/sw/bin:/nix/var/nix/profiles/system/sw/sbin
fsck -a /dev/nvme0n1p1
fsck -a /dev/nvme0n1p2
fsck -a /dev/nvme0n1p3

参考: https://www.reddit.com/r/NixOS/comments/4fnsxb/how_do_i_run_fsck_manually_on_root_in_nixos/

xfs_repair -L /dev/dm-1

-L : 最后的武器,会切掉部分日志

[ ] 如何编译一个静态的 QEMU,测试启动速度

参考 scripts/nix/pkg/static-qemu.nix

[ ] nixos 没有 centos 中对应的 kernel-tools 包

类似 kvm_stat 是没有现成的包,非常难受。nixmd

nixos 上无法安装 pytype

使用 pyright 安装的时候,出现如下错误。 libstdc++.so.6

构建 qemu guest 镜像

虽然执行有点问题,但是值得借鉴:

#! /nix/store/96ky1zdkpq871h2dlk198fz0zvklr1dr-bash-5.1-p16/bin/bash

export PATH=/nix/store/wxb674h6dp7h63na8z6jwpagps811jl7-coreutils-9.1/bin${PATH:+:}$PATH

set -e

NIX_DISK_IMAGE=$(readlink -f "${NIX_DISK_IMAGE:-./nixos.qcow2}")

if ! test -e "$NIX_DISK_IMAGE"; then
    /nix/store/zsf59dn5sak8pbq4l3g5kqp7adyv3fph-qemu-host-cpu-only-7.1.0/bin/qemu-img create -f qcow2 "$NIX_DISK_IMAGE" \
      1024M
fi

# Create a directory for storing temporary data of the running VM.
if [ -z "$TMPDIR" ] || [ -z "$USE_TMPDIR" ]; then
    TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir)
fi



# Create a directory for exchanging data with the VM.
mkdir -p "$TMPDIR/xchg"



cd "$TMPDIR"




# Start QEMU.
exec /nix/store/zsf59dn5sak8pbq4l3g5kqp7adyv3fph-qemu-host-cpu-only-7.1.0/bin/qemu-kvm -cpu max \
    -name nixos \
    -m 1024 \
    -smp 1 \
    -device virtio-rng-pci \
    -net nic,netdev=user.0,model=virtio -netdev user,id=user.0,"$QEMU_NET_OPTS" \
    -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store \
    -virtfs local,path="${SHARED_DIR:-$TMPDIR/xchg}",security_model=none,mount_tag=shared \
    -virtfs local,path="$TMPDIR"/xchg,security_model=none,mount_tag=xchg \
    -drive cache=writeback,file="$NIX_DISK_IMAGE",id=drive1,if=none,index=1,werror=report -device virtio-blk-pci,drive=drive1 \
    -device virtio-keyboard \
    -usb \
    -device usb-tablet,bus=usb-bus.0 \
    -kernel ${NIXPKGS_QEMU_KERNEL_nixos:-/nix/store/k9xnkgjs5dwjzww8n9c3dsx3hl7axl5k-nixos-system-nixos-22.11.2999.a7cc81913bb/kernel} \
    -initrd /nix/store/k9xnkgjs5dwjzww8n9c3dsx3hl7axl5k-nixos-system-nixos-22.11.2999.a7cc81913bb/initrd \
    -append "$(cat /nix/store/k9xnkgjs5dwjzww8n9c3dsx3hl7axl5k-nixos-system-nixos-22.11.2999.a7cc81913bb/kernel-params) init=/nix/store/k9xnkgjs5dwjzw
w8n9c3dsx3hl7axl5k-nixos-system-nixos-22.11.2999.a7cc81913bb/init regInfo=/nix/store/byyk6x729q54ys1dv8m852v5f7g39ssn-closure-info/registration consol
e=ttyS0,115200n8 console=tty0 $QEMU_KERNEL_PARAMS" \
    $QEMU_OPTS \
    "$@"

感觉目前的时机不成熟,或者我对于这个的理解有问题。

总之,等我对于 nixos 理解在深入一点再来搞这个问题吧。

而且,无论如何,都是需要在 guest 中使用 crash 的。

在 guest 中使用 docker 环境?

不要把简单问题复杂化了!

使用 shell 初始化即可,遇到问题,以后再说。

而且导致无法 dracut

虽然尝试将其作为完全的测试的 Guest 是失败了,但是 使用 nixos 搭建一个和 host 机器完全相同的虚拟机,然后可以实现 host guest 环境对比

桌面环境

启用 hyprland 的方法:

commit 6746b06b79275b160a433567b47d5e6c49445e77
Author: Martins3 <hubachelar@gmail.com>
Date:   Sun Jun 25 22:23:53 2023 +0800

    cool

diff --git a/nixpkgs/home/gui.nix b/nixpkgs/home/gui.nix
index 8f0d909..fac00dc 100644
--- a/nixpkgs/home/gui.nix
+++ b/nixpkgs/home/gui.nix
@@ -19,7 +19,7 @@ in
 {

   imports = [
-    ./app/gnome.nix
+    # ./app/gnome.nix
   ];

   home.packages = with pkgs; [
diff --git a/nixpkgs/sys/gui.nix b/nixpkgs/sys/gui.nix
index 61f4f3e..a525fb5 100644
--- a/nixpkgs/sys/gui.nix
+++ b/nixpkgs/sys/gui.nix
@@ -1,17 +1,17 @@
 { config, pkgs, ... }:

 {
-  services.xserver = {
-    enable = true;
-    xkbOptions = "caps:swapescape";
-    # 暂时可以使用这个维持生活吧
-    # gsettings set org.gnome.desktop.input-sources xkb-options "['caps:swapescape']"
-    # https://nixos.org/manual/nixos/stable/index.html#sec-gnome-gsettings-overrides
-  };
+  # services.xserver = {
+  #   enable = true;
+  #   xkbOptions = "caps:swapescape";
+  #   # 暂时可以使用这个维持生活吧
+  #   # gsettings set org.gnome.desktop.input-sources xkb-options "['caps:swapescape']"
+  #   # https://nixos.org/manual/nixos/stable/index.html#sec-gnome-gsettings-overrides
+  # };

-  services.xserver.displayManager.gdm.enable = true;
-  services.xserver.displayManager.gdm.wayland = false;
-  services.xserver.desktopManager.gnome.enable = true;
+  # services.xserver.displayManager.gdm.enable = true;
+  # services.xserver.displayManager.gdm.wayland = false;
+  # services.xserver.desktopManager.gnome.enable = true;

   # see xieby1
   fonts.fonts = (
diff --git a/nixpkgs/system.nix b/nixpkgs/system.nix
index 8490c95..c1c018b 100644
--- a/nixpkgs/system.nix
+++ b/nixpkgs/system.nix
@@ -20,6 +20,12 @@ in
     "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
     "https://cache.nixos.org/"
   ];
+  programs.hyprland.enable = true;
+ services.xserver.desktopManager = {
+    gnome.enable = false;
+    plasma5.enable = false;
+    xterm.enable = false;
+  };

   time.timeZone = "Asia/Shanghai";
   time.hardwareClockInLocalTime = true;

还是感觉收益不大,而且启动之后 edge 无法使用。再度放弃。

如何调试 host 内核

参考 nixpkgs/pkgs/os-specific/linux/kernel/linux-6.2.nix ,我发现其

cargo install 几乎没有成功过

cargo install rusty-krab-manager

virt-manager 可以尝试一下

https://nixos.wiki/wiki/Virt-manager

virtualisation.libvirtd.enable = true;
programs.dconf.enable = true;
environment.systemPackages = with pkgs; [ virt-manager ];

NixOS 常见问题解答

nixos 中文社区下的项目 https://github.com/nixos-cn/flakes :

如何编译一个静态的 bear 出来

尝试到此结束,不如去分析一下 signal_pending 的问题

输入法

https://github.com/NixOS/nixpkgs/issues/53085

coredump

nixos 的处理方式:

🧀  cat /proc/sys/kernel/core_pattern
|/nix/store/34am2kh69ll6q03731imxf21jdbizda2-systemd-251.15/lib/systemd/systemd-coredump %P %u %g %s %t %c %h

ubuntu 的处理方式:

smtxauto@node1:/var/lib/systemd/coredump$  cat /proc/sys/kernel/core_pattern
|/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E

通过检查 /var/log/apport.log 可以知道

ERROR: apport (pid 17768) Thu Apr 27 03:08:58 2023: called for pid 17767, signal 11, core limit 0, dump mode 1
ERROR: apport (pid 17768) Thu Apr 27 03:08:58 2023: executable: /home/smtxauto/a.out (command line "./a.out")
ERROR: apport (pid 17768) Thu Apr 27 03:08:58 2023: executable does not belong to a package, ignoring

所以需要调整一下:

ulimit -c unlimited

其路径也是在 /var/lib/apport/coredump 中。

[ ] infer 处理下

https://fbinfer.com/docs/getting-started/

虚拟机中安装

有些需要手动设置的内容

gnome 有些内容需要手动设置

  1. 将 edge 设置为默认的浏览器, gnome setting
  2. ctrl 1 进入到第一个 workspace
  3. Vn 和 My-Linux-Config 两个仓库中
npm install -g @lint-md/cli@beta
pre-commit install

但是 pre-commit 不知道为什么,并没有起效。 4. escape and capslock 的切换

gsettings set org.gnome.desktop.input-sources xkb-options "['caps:swapescape']"

参考: https://nixos.org/manual/nixos/stable/index.html#sec-gnome-gsettings-overrides

不知道为什么 efm 在新装的环境中无法使用了。

[ ] 到底如何切换 escape 和 caps

这种方法是通过 gnome 实现的:

  services.xserver = {
    enable = true;
    xkbOptions = "caps:swapescape"; # 之前还可以靠这个维持生活的
  };

可以参考这个 https://www.reddit.com/r/vim/comments/1442ads/mapping_capslock_to_esc_is_life_changing/

dual boot 双系统

https://nixos.wiki/wiki/Bootloader

在 13900K 上可以采用这个系统,但是笔记本上似乎有问题,而且 grub 本身有时候会出现问题。

  /* /dev/nvme1n2p3: BLOCK_SIZE="512" UUID="0470864A70864302" TYPE="ntfs" PARTUUID="8402854e-03" */
  /* /dev/nvme1n2p1: LABEL="M-gM-3M-;M-gM-;M-^_M-dM-?M-^]M-gM-^UM-^Y" BLOCK_SIZE="512" UUID="409E41739E416310" TYPE="ntfs" PARTUUID="8402854e-01" */
  /* /dev/nvme1n2p2: BLOCK_SIZE="512" UUID="02084242084234C7" TYPE="ntfs" PARTUUID="8402854e-02" */
  boot.loader = {
    efi = {
      canTouchEfiVariables = true;
      # assuming /boot is the mount point of the  EFI partition in NixOS (as the installation section recommends).
      efiSysMountPoint = "/boot";
    };
    grub = {
      # https://www.reddit.com/r/NixOS/comments/wjskae/how_can_i_change_grub_theme_from_the/
      # theme = pkgs.nixos-grub2-theme;
      theme =
        pkgs.fetchFromGitHub {
          owner = "shvchk";
          repo = "fallout-grub-theme";
          rev = "80734103d0b48d724f0928e8082b6755bd3b2078";
          sha256 = "sha256-7kvLfD6Nz4cEMrmCA9yq4enyqVyqiTkVZV5y4RyUatU=";
        };
      # despite what the configuration.nix manpage seems to indicate,
      # as of release 17.09, setting device to "nodev" will still call
      # `grub-install` if efiSupport is true
      # (the devices list is not used by the EFI grub install,
      # but must be set to some value in order to pass an assert in grub.nix)
      devices = [ "nodev" ];
      efiSupport = true;

      # useOSProber = true; # 没有说的那么不堪,还是很好用的

      enable = true;
      # set $FS_UUID to the UUID of the EFI partition
      # /dev/nvme1n1p1: BLOCK_SIZE="512" UUID="3A22AF3A22AEF9D1" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="1b23d1fb-c1ad-4b8b-83e1-79005771a027"
      extraEntries = ''
        menuentry "Windows" {
          insmod part_gpt
          insmod fat
          search --fs-uuid --set=root 4957-45A0
          chainloader /EFI/Microsoft/Boot/bootmgfw.efi
        }
      '';
      version = 2;
    };
  };

manifest.nix 被损坏

使用

nix-env --rollback

然后,

home-manager switch

lsof 存在警告

[sudo] password for martins3:
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
lsof: WARNING: can't stat() fuse.portal file system /run/user/1000/doc
      Output information may be incomplete.
COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
zsh     34262 martins3  cwd    DIR  259,2     4096 39060352 bus
sleep   34801 martins3  cwd    DIR  259,2     4096 39060352 bus

sway : i3-compatible Wayland compositor

如何在 nixos 中启用 wayland https://drakerossman.com/blog/wayland-on-nixos-confusion-conquest-triumph

notification

不知道为什么大家会专门的 notification 工具来 https://github.com/emersion/mako

如果想要简单的 hacking 一下: https://wiki.archlinux.org/title/Desktop_notifications

如果更多的定制化: dunst man home-configuration.nix 中搜索 dunst

clash 配置

在 profiles 中右键,参考 https://docs.cfw.lbyczf.com/contents/ui/profiles/rules.html

目前使用: clash-verge

canTouchEfiVariables 到底是什么来头

https://nixos.wiki/wiki/Bootloader 中最后提到如何增加 efi

efibootmgr -c -d /dev/nvme0n1 -p 1 -L NixOS-boot -l '\EFI\NixOS-boot\grubx64.efi'
  1. 注意,-p 1 来设置那个 partition 的。
  2. 后面的那个路径需要将 boot 分区 mount 然后具体产看,还有一次是设置的 “\EFI\nixo\BOOTX64.efi”

这个说的是什么意思来着:

efiSysMountPoint = "/boot/efi"; # ← use the same mount point here.

我设置的是 /boot 似乎影响也不大啊!

不知道为什么 efibootmgr 在 home.cli 中无法安装。

删除一个:

sudo efibootmgr  -B -b 3 # 3 是参数

设置优先级 sudo efibootmgr -o 0,1,2

flakes book

作者的配置:

感觉写的相当不错。但是,问题是,我老版本的 nix channel 之类的还没掌握,怎么现在又切换了啊!

nixos distribution

如何代理

sudo proxychains4 -f /home/martins3/.dotfiles/config/proxychain.conf  nixos-rebuild switch

不知道如何调试代码,debug symbol 如何加载

[x] sar 无法正常使用

🧀  sar
Cannot open /var/log/sa/sa21: No such file or directory
Please check if data collecting is enabled

兄弟,是这个:

sar -n DEV 1

如何在 cgroup 中编译内核

可以采用这种方法:

sudo cgexec -g memory:mem3 nix-shell --command "make -j32"

但是这种方法就不太妙了:

sudo cgexec -g memory:mem3 make -j32

文摘

搞搞 cuda 吧

https://nixos.org/community/teams/cuda

# Run with `nix-shell cuda-shell.nix`
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
   name = "cuda-env-shell";
   buildInputs = with pkgs; [
     git gitRepo gnupg autoconf curl
     procps gnumake util-linux m4 gperf unzip
     cudatoolkit linuxPackages.nvidia_x11
     libGLU libGL
     xorg.libXi xorg.libXmu freeglut
     xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr zlib
     ncurses5 stdenv.cc binutils
   ];
   shellHook = ''
      export CUDA_PATH=${pkgs.cudatoolkit}
      export LD_LIBRARY_PATH=${pkgs.linuxPackages.nvidia_x11}/lib:${pkgs.ncurses5}/lib
      export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"
      export EXTRA_CCFLAGS="-I/usr/include"
   '';
}

然后配合这个 : https://github.com/Tony-Tan/CUDA_Freshman

https://news.ycombinator.com/item?id=37818570

微信

  wrapWine_nix = pkgs.fetchurl {
    url = "https://raw.githubusercontent.com/xieby1/nix_config/d57b5c4b1532eb5599b23c13ed063b2fa81edfa7/usr/gui/wrapWine.nix";
    hash = "sha256-4vdks0N46J/n8r3wdChXcJbBHPrbTexEN+yMi7zAbKs=";
  };
  weixin_nix = pkgs.fetchurl {
    url = "https://raw.githubusercontent.com/xieby1/nix_config/d57b5c4b1532eb5599b23c13ed063b2fa81edfa7/usr/gui/weixin.nix";
    hash = "sha256-ql6BE/IZBM31W/yqCayAdktcV2QZ/maVzwskybFZwz0=";
  };
  weixin = import weixin_nix {
    wrapWine = import wrapWine_nix { inherit pkgs; };
  };

又一个教程

构建内核的确方便,但是构建过程不能利用 cacahe ,现在修改一个 patch 就要重新构建整个内核,很烦

此外,现在 systemd 中构建一次之后,在 zsh 中还是需要重新 make 一次

如何在 nixpkgs 的基础上稍作修改制作自己的包

git clone nixpkgs

跑到对应的路径下去:

nix-build -E ‘with import {}; callPackage ./default.nix {}'

https://elatov.github.io/2022/01/building-a-nix-package/

这个库

https://github.com/svanderburg/node2nix

https://github.com/nix-community/NixOS-WSL

配置文件

 fileSystems."/home/martins3/hack" = {
    device = "/dev/disk/by-uuid/8eba61f5-5ed3-4221-ba7a-40b6ef3cbd62";
    fsType = "auto";
    options = [ "user"];
  };

生成密码

mkpasswd -m sha-512 abc

构建 github action

  services.github-runners = {
    testrunner = {
      enable = true;
      user = "martins3";
      name = "test-runner";
      # token file is somewhere on local machine - in my case, it's not currently managed by nix
      tokenFile = "/home/martins3/.github-runners";
      url = "https://github.com/Martins3/R9000P";
    };
  };

tokenFile 只是需要包含 github 指导步骤中的 token 即可

./config.sh --url https://github.com/Martins3/R9000P --token xxx

需要将 username 变为可以定制化才可以,或者说

可以存在多个 username ,将 martins3 只是作为临时安装的一个名称,之后可以重新指向一个名称

有办法修改为 xueshi.hu 吗?

常见命令

nix-env -qaPA nixos.nodePackages

TODO : 真正的代办

参考这个文档,重新理解下到底如何优雅的构建内核驱动来着: https://nixos.org/manual/nixos/stable/#sec-kernel-config

如何编译 kernel module

没必要那么复杂,参考这个,中的 : Developing out-of-tree kernel modules

nix-shell '<nixpkgs>' -A linuxPackages_latest.kernel.dev
make -C $(nix-build -E '(import <nixpkgs> {}).linuxPackages_latest.kernel.dev' --no-out-link)/lib/modules/*/build M=$(pwd) modules

make SYSSRC=$(nix-build -E '(import <nixpkgs> {}).linuxPackages_latest.kernel.dev' --no-out-link)/lib/modules/$(uname -r)/source

学习 nix 语言

nix eval -f begin.nix

主要参考语言:

从 nixos virtualisation 中的实现直接 中开始入手吧

感受

学习资料

工具

缺陷

材料

nixos 在 sudo su 的情况下,基本没有什么命令可以执行,但是 nixos 之类的程序并不会如此

其他人的配置

bpftool 和 bpftools 居然完全是同一个程序

nixpkgs/home/cli.nix

切换之后,居然是相同的,但是在 nixpkgs 无法搜索到 bpftool

lrwxrwxrwx     - root  1 1月   1970  /home/martins3/.nix-profile/bin/bpftool -> /nix/store/md6qg2q7309xggbrjywcm5mjsiwiliv3-bpftools-6.5/bin/bpftool

lrwxrwxrwx     - root  1 1月   1970  /home/martins3/.nix-profile/bin/bpftool -> /nix/store/md6qg2q7309xggbrjywcm5mjsiwiliv3-bpftools-6.5/bin/bpftool

ps 都是从那里来的

🧀  l /home/martins3/.nix-profile/bin/ps

Permissions Size User Date Modified Name
lrwxrwxrwx     - root  1 1月   1970  /home/martins3/.nix-profile/bin/ps -> /nix/store/gb18gj7zpbhdavmsdr5090rx7lsvxvyk-procps-3.3.17/bin/ps
🧀  l /run/current-system/sw/bin/ps

Permissions Size User Date Modified Name
lrwxrwxrwx     - root  1 1月   1970  /run/current-system/sw/bin/ps -> /nix/store/gb18gj7zpbhdavmsdr5090rx7lsvxvyk-procps-3.3.17/bin/ps

结论: 系统中本来就是自带了一份

wps 的版本还是停留在 2019

https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/office/wpsoffice/default.nix

但是不知道怎么给他们更新。

基于 nix ?

https://github.com/flox/flox

参考这个资源

https://dotfiles.github.io/