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;

 # 如果是虚拟机,增加下如下内容
 # Bootloader.
  boot.loader.grub.enable = true;
  boot.loader.grub.device = "/dev/sda";
  boot.loader.grub.useOSProber = 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. 重启

<– 这里我们使用了一个备份,直接用吧

  1. 首先解决网络问题,使用 nano 将 /etc/nixos/configuration.nix 中的 networking.proxy 的两个配置修改正确。
  2. 打开 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
nix-prefetch-url https://raw.githubusercontent.com/cyrus-and/gdb-dashboard/master/.gdbinit
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

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:

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

看看这个 https://github.com/astral-sh/uv

[ ] 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

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

如何升级 (update / upgrade)

小版本更新

更新 nixos 为 24.11

内容参考这里:

修改 scripts/nix/nix-channel.sh

nixos-rebuild switch --upgrade

如果仅仅安装了 home-manager ,那么使用 sudo ,会遇到网络问题的。

垃圾清理

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

tskey-auth-XXX 上网页上 generate 的:

sudo tailscale up --auth-key tskey-auth-XXX

[ ] 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

cargo install 几乎没有成功过

cargo install rusty-krab-manager

NixOS 常见问题解答

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

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

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

输入法

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

[ ] 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 不知道为什么,并没有起效。

  1. 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/

manifest.nix 被损坏

使用

nix-env --rollback

然后,

home-manager switch

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

flakes book

作者的配置:

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

nixos distribution

如何代理

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

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

如何在 cgroup 中编译内核

可以采用这种方法:

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

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

sudo cgexec -g memory:mem3 make -j32

教程

如何在 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

生成密码

mkpasswd -m sha-512 abc

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

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

有办法修改为 xueshi.hu 吗?

常见命令

nix-env -qaPA nixos.nodePackages

学习 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/

太坑了

在 clang 自动携带了 flags :

linux defualt.nix

之前的写法

{ pkgs ? import <nixpkgs> { },
  unstable ? import <nixos-unstable> { }
}:

pkgs.stdenv.mkDerivation {
  name = "yyds";
  buildInputs = with pkgs; [
  # ....
  ];
}

还有一种写法:

with import <nixpkgs> {};
pkgs.llvmPackages.stdenv.mkDerivation {
  hardeningDisable = [ "all" ];
  name = "yyds";
  buildInputs = with pkgs; [

    getopt
    flex
    ];
}

还有一种写法:


with import <nixpkgs> {};

pkgs.llvmPackages_14.stdenv.mkDerivation {
   hardeningDisable = [ "all" ];
  name = "yyds";
  buildInputs = with pkgs; [

  ];
  }

也可以参考: https://nixos.wiki/wiki/Using_Clang_instead_of_GCC

使用 clang 交叉编译内核

https://stackoverflow.com/questions/61771494/how-do-i-cross-compile-llvm-clang-for-aarch64-on-x64-host

🧀  clang -arch arm64 aio.c -o main_arm64
clang-16: warning: argument unused during compilation: '-arch arm64' [-Wunused-command-line-argument]

检查内核 compile_commands.json ,果然是没有输出的。

如何解决掉本身就在代理的问题

社区危机

使用 lcov 需要首先配置如下内容

nix-shell -p libgcc

这个似乎还不错

https://github.com/gvolpe/nix-config

其他的 immutable 系统

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

Aeon 非常奇怪,安装不可以用 cdrom ,而且必须是 UEFI

编译 bpf 的时候有警告

linux/tools/bpf/runqslower 下

如果是: make LLVM=1

clang: warning: -lLLVM-17: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lLLVM-17: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lLLVM-17: 'linker' input unused [-Wunused-command-line-argument]
clangclang: : warning: warning: -lLLVM-17: 'linker' input unused [-Wunused-command-line-argument]-lLLVM-17: 'linker' input unused [-Wunused-command-line-argument]

clang: warning: -lLLVM-17: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lLLVM-17: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lLLVM-17: 'linker' input unused [-Wunused-command-line-argument]
  LINK    /home/martins3/data/linux/tools/bpf/runqslower/.output/bpftool/bootstrap/bpftool
  GEN     /home/martins3/data/linux/tools/bpf/runqslower/.output//vmlinux.h
  GEN     /home/martins3/data/linux/tools/bpf/runqslower/.output//runqslower.bpf.o
clang: warning: argument unused during compilation: '--gcc-toolchain=/nix/store/llmjvk4i2yncv8xqdvs4382wr3kgdmvp-gcc-13.2.0' [-Wunused-command-line-argument]
  GEN     /home/martins3/data/linux/tools/bpf/runqslower/.output//runqslower.skel.h
  CC      /home/martins3/data/linux/tools/bpf/runqslower/.output//runqslower.o
  LINK    /home/martins3/data/linux/tools/bpf/runqslower/.output//runqslower

如果是: make

clang: warning: argument unused during compilation: '--gcc-toolchain=/nix/store/llmjvk4i2yncv8xqdvs4382wr3kgdmvp-gcc-13.2.0' [-Wunused-command-line-argument]
  GEN     /home/martins3/data/linux/tools/bpf/runqslower/.output//runqslower.skel.h
  CC      /home/martins3/data/linux/tools/bpf/runqslower/.output//runqslower.o
  LINK    /home/martins3/data/linux/tools/bpf/runqslower/.output//runqslower

看看这个吧

https://rasmuskirk.com/articles/2024-07-24_dont-use-nixos/

nixos 的动态库

构建项目如果发现没有动态库,基本的解决思路是:

参考 https://discourse.nixos.org/t/where-can-i-get-libgthread-2-0-so-0/16937/6

使用 nix-index 也许可以定位是那个包提供的,在 nix 中添加:

例如,这个提供了 stdc++ ,libGL 和 glib2 的动态库的位置:

    LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.libGL}/lib:${pkgs.glib.out}/lib";

ocaml

🧀  opam install herdtools7
[NOTE] External dependency handling not supported for OS family 'nixos'.
       You can disable this check using 'opam option --global depext=false'
The following actions will be performed:
  ∗ install conf-which      1        [required by herdtools7]
  ∗ install conf-gmp        4        [required by zarith]
  ∗ install conf-pkg-config 3        [required by zarith]
  ∗ install dune            3.16.0   [required by herdtools7]
  ∗ install ocamlfind       1.9.6    [required by zarith]
  ∗ install menhirSdk       20240715 [required by menhir]
  ∗ install menhirLib       20240715 [required by menhir]
  ∗ install menhirCST       20240715 [required by menhir]
  ∗ install zarith          1.14     [required by herdtools7]
  ∗ install menhir          20240715 [required by herdtools7]
  ∗ install herdtools7      7.57
===== ∗ 11 =====
Do you want to continue? [Y/n] Y

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Processing  5/33: [conf-gmp.4/test.c: dl] [dune.3.16.0: dl] [herdtools7.7.57: dl]
[ERROR] The compilation of conf-pkg-config.3 failed at "pkg-config --help".
∗ installed conf-which.1
⬇ retrieved conf-gmp.4  (https://opam.ocaml.org/cache)
[ERROR] The compilation of conf-gmp.4 failed at "sh -exc cc -c $CFLAGS -I/usr/local/include test.c".
⬇ retrieved herdtools7.7.57  (https://opam.ocaml.org/cache)
⬇ retrieved dune.3.16.0  (https://opam.ocaml.org/cache)
⬇ retrieved menhir.20240715  (https://opam.ocaml.org/cache)
⬇ retrieved menhirSdk.20240715  (cached)
⬇ retrieved menhirCST.20240715  (https://opam.ocaml.org/cache)
⬇ retrieved ocamlfind.1.9.6  (https://opam.ocaml.org/cache)
⬇ retrieved zarith.1.14  (https://opam.ocaml.org/cache)
∗ installed ocamlfind.1.9.6
⬇ retrieved menhirLib.20240715  (https://opam.ocaml.org/cache)
∗ installed dune.3.16.0
∗ installed menhirCST.20240715
∗ installed menhirSdk.20240715
∗ installed menhirLib.20240715
∗ installed menhir.20240715

#=== ERROR while compiling conf-pkg-config.3 ==================================#
# context     2.1.5 | linux/x86_64 | ocaml.5.2.0 | https://opam.ocaml.org#f302b6aaf01995b706f9b5a0a8fc2e6bb299
eae8
# path        ~/.opam/default/.opam-switch/build/conf-pkg-config.3
# command     ~/.opam/opam-init/hooks/sandbox.sh build pkg-config --help
# exit-code   10
# env-file    ~/.opam/log/conf-pkg-config-1134447-8c5011.env
# output-file ~/.opam/log/conf-pkg-config-1134447-8c5011.out
### output ###
# [ERROR] Command not found: pkg-config


#=== ERROR while compiling conf-gmp.4 =========================================#
# context     2.1.5 | linux/x86_64 | ocaml.5.2.0 | https://opam.ocaml.org#f302b6aaf01995b706f9b5a0a8fc2e6bb299
eae8
# path        ~/.opam/default/.opam-switch/build/conf-gmp.4
# command     ~/.opam/opam-init/hooks/sandbox.sh build sh -exc cc -c $CFLAGS -I/usr/local/include test.c
# exit-code   1
# env-file    ~/.opam/log/conf-gmp-1134447-2aea49.env
# output-file ~/.opam/log/conf-gmp-1134447-2aea49.out
### output ###
# + cc -c -I/usr/local/include test.c
# test.c:1:10: fatal error: gmp.h: No such file or directory
#     1 | #include <gmp.h>
#       |          ^~~~~~~
# compilation terminated.



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build conf-gmp        4
│ λ build conf-pkg-config 3
└─
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install conf-which 1
│ ∗ install dune       3.16.0
│ ∗ install menhir     20240715
│ ∗ install menhirCST  20240715
│ ∗ install menhirLib  20240715
│ ∗ install menhirSdk  20240715
│ ∗ install ocamlfind  1.9.6
└─

The former state can be restored with:
    /nix/store/sgxvws7lxhhz60j0l3grnkv6wa7fyx8v-opam-2.1.5/bin/.opam-wrapped switch import
"/home/martins3/.opam/default/.opam-switch/backup/state-20241004072102.export"

但是,如果这个时候 nix-shell -p gmp pkg-config ,那么还是可以正确的使用的。

看来的确是可以的

指定动态库

参考 scripts/nix/env/uboot.nix

[ ] 有没有办法,只有 cache 我需要的内容

https://discourse.nixos.org/t/introducing-attic-a-self-hostable-nix-binary-cache-server/24343

似乎只有自己去 push 就可以了

如何快速拷贝,也许可以尝试一下,但是不容易

nix-store export 和 import

nix-copy-closure

如果可以构建一个 local cache ,那么就完美了

事到如今,批评还是很多的

https://www.reddit.com/r/NixOS/comments/1gfx95g/leaving_nix_dont_expect_anyone_to_care_but_you/

[ ] home-manager 按照到 fedora 中,为什么最后还是有 vmlinux ,而且是 300 多 M

哪里配置的有问题吗?

🧀  l
Permissions Size User     Date Modified Name
dr-xr-xr-x     - martins3  1 Jan  1970   bin
dr-xr-xr-x     - martins3  1 Jan  1970   etc
lrwxrwxrwx     - martins3  1 Jan  1970   include -> /nix/store/di2a4smdj8li54di42chyfr261chw4rz-home-manager-path/include
dr-xr-xr-x     - martins3  1 Jan  1970   lib
dr-xr-xr-x     - martins3  1 Jan  1970   libexec
lrwxrwxrwx     - martins3  1 Jan  1970   manifest.nix -> /nix/store/3i0bzw19pdx2nyrccbfqy2fz5c0sq1wa-env-manifest.nix
lrwxrwxrwx     - martins3  1 Jan  1970   rplugin.vim -> /nix/store/di2a4smdj8li54di42chyfr261chw4rz-home-manager-path/rplugin.vim
lrwxrwxrwx     - martins3  1 Jan  1970   run -> /nix/store/di2a4smdj8li54di42chyfr261chw4rz-home-manager-path/run
lrwxrwxrwx     - martins3  1 Jan  1970   sbin -> /nix/store/di2a4smdj8li54di42chyfr261chw4rz-home-manager-path/sbin
dr-xr-xr-x     - martins3  1 Jan  1970   share
lrwxrwxrwx     - martins3  1 Jan  1970   usr -> /nix/store/di2a4smdj8li54di42chyfr261chw4rz-home-manager-path/usr
lrwxrwxrwx     - martins3  1 Jan  1970   var -> /nix/store/di2a4smdj8li54di42chyfr261chw4rz-home-manager-path/var
lrwxrwxrwx     - martins3  1 Jan  1970   vmlinux -> /nix/store/di2a4smdj8li54di42chyfr261chw4rz-home-manager-path/vmlinux
lrwxrwxrwx     - martins3  1 Jan  1970   x86_64-unknown-linux-gnu -> /nix/store/di2a4smdj8li54di42chyfr261chw4rz-home-manager-path/x86_64-unknown-linux-gnu
nix/profiles/profile🔒 🌳
🧀  pwd
/home/martins3/.local/state/nix/profiles/profile

应该是和这个有关系: linuxPackages_6_10.kernel.dev

cache

https://github.com/nix-community/harmonia

仔细看看这个

https://github.com/NixOS-CN

home manager 可以管理 systemd 吗?

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

kernel 配置在这里的

kernel-modules/lib/modules/6.12.7/modules.devname

原来 rust-analyzer 是一个软连接啊

🧀  l /nix/store/dyn2kdxcnhcjz13nqpdrpcgd3qj7996b-rustup-1.27.1/bin/rust-analyzer
Permissions Size User Date Modified Name
lrwxrwxrwx     - root  1 Jan  1970   /nix/store/dyn2kdxcnhcjz13nqpdrpcgd3qj7996b-rustup-1.27.1/bin/rust-analyzer -> rustup

这样可以解决:

rustup component add rust-analyzer

这个功能对于我来说,很重要

安装的时候可以不用联网。 https://github.com/tfc/nixos-auto-installer

coreutils 中的 .envrc 可以关注下

https://github.com/uutils/coreutils/blob/main/.envrc

研究下动态库吧,每次都要卡好久的时间

https://github.com/nix-community/nix-ld

似乎 pkg-config 就可以帮我们把动态库都找到,也就不需要额外的 config 了。

路径中不能有空格,不然 ld 会有报错

/nix/store/bwkb907myixfzzykp21m9iczkhrq5pfy-binutils-2.43.1/bin/ld: cannot find b/outputs/out/lib: No such file or directory

未解之谜

这个东西好啊

https://github.com/nix-community/nh

看看这个

https://saylesss88.github.io/Getting_Started_with_Nix_1.html

才意识到

如果有了 glibc.static 之后,之后普通的 gcc hello.c 都是自动和 static 链接的

可怕;

nix-shell -p gcc glibc.static --command zsh

只能说,有一点赞同

https://aruarian.dance/blog/you-do-not-need-nixos/

图形界面用起来痛苦,但是 cli 很好

和 rpm ostree 对比一下?

https://github.com/zdyxry/isengard

不理解为什么构建了,但是启动之后,动态库就找不到了

/home/martins3/data/qemu-f9a3def17b2a////install/bin/qemu-system-x86_64: error while loading shared libraries: libpixman-1.so.0: cannot open shared object file: No such file or directory
🤒  ldd /home/martins3/data/qemu-f9a3def17b2a/install/bin/qemu-system-x86_64
        linux-vdso.so.1 (0x00007ffc98df6000)
        libepoxy.so.0 => /usr/lib64/libepoxy.so.0 (0x00007f3ef3e13000)
        libudev.so.1 => /usr/lib64/libudev.so.1 (0x00007f3ef3de9000)
        libusb-1.0.so.0 => /usr/lib64/libusb-1.0.so.0 (0x00007f3ef3dcb000)
        libseccomp.so.2 => /usr/lib64/libseccomp.so.2 (0x00007f3ef3daa000)
        libgio-2.0.so.0 => /usr/lib64/libgio-2.0.so.0 (0x00007f3ef3bc7000)
        libgobject-2.0.so.0 => /usr/lib64/libgobject-2.0.so.0 (0x00007f3ef3b6d000)
        libglib-2.0.so.0 => /usr/lib64/libglib-2.0.so.0 (0x00007f3ef3a36000)
        libz.so.1 => /usr/lib64/libz.so.1 (0x00007f3ef3a1c000)
        librdmacm.so.1 => /nix/store/0g8xcpg1c1i5ywqaxmqg2im4xx2q5f6f-rdma-core-54.2/lib/librdmacm.so.1 (0x00007f3ef39fc000)
        libibverbs.so.1 => /nix/store/0g8xcpg1c1i5ywqaxmqg2im4xx2q5f6f-rdma-core-54.2/lib/libibverbs.so.1 (0x00007f3ef39da000)
        libzstd.so.1 => /usr/lib64/libzstd.so.1 (0x00007f3ef38cb000)
        libslirp.so.0 => not found
        libvirglrenderer.so.1 => /usr/lib64/libvirglrenderer.so.1 (0x00007f3ef3855000)
        libiscsi.so.10 => not found
        libaio.so.1 => /nix/store/h32pz141kxm622pqdlik469jpf80pvbr-libaio-0.3.113/lib/libaio.so.1 (0x00007f3ef3850000)
        liburing.so.2 => not found
        libnfs.so.14 => not found
        libssh.so.4 => /usr/lib64/libssh.so.4 (0x00007f3ef37df000)
        libgmodule-2.0.so.0 => /usr/lib64/libgmodule-2.0.so.0 (0x00007f3ef37d9000)
        libbz2.so.1 => /nix/store/vrqss3954zk1c52mda3xf1rv7wc5ygba-bzip2-1.0.8/lib/libbz2.so.1 (0x00007f3ef37c6000)
        libm.so.6 => /nix/store/5m9amsvvh2z8sl7jrnc87hzy21glw6k1-glibc-2.40-66/lib/libm.so.6 (0x00007f3ef36df000)
        libc.so.6 => /nix/store/5m9amsvvh2z8sl7jrnc87hzy21glw6k1-glibc-2.40-66/lib/libc.so.6 (0x00007f3ef34e7000)
        /nix/store/5m9amsvvh2z8sl7jrnc87hzy21glw6k1-glibc-2.40-66/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f3ef59a9000)
        libmount.so.1 => /usr/lib64/libmount.so.1 (0x00007f3ef3485000)
        libselinux.so.1 => /usr/lib64/libselinux.so.1 (0x00007f3ef3459000)
        libffi.so.8 => /usr/lib64/libffi.so.8 (0x00007f3ef344d000)
        libpcre.so.1 => /usr/lib64/libpcre.so.1 (0x00007f3ef33d4000)
        libnl-3.so.200 => /nix/store/8bv2z2ygrfz54dgyj8dvz5c8k891wkw4-libnl-3.10.0/lib/libnl-3.so.200 (0x00007f3ef33af000)
        libnl-route-3.so.200 => /nix/store/8bv2z2ygrfz54dgyj8dvz5c8k891wkw4-libnl-3.10.0/lib/libnl-route-3.so.200 (0x00007f3ef3310000)
        libdrm.so.2 => /usr/lib64/libdrm.so.2 (0x00007f3ef32fb000)
        libgbm.so.1 => /usr/lib64/libgbm.so.1 (0x00007f3ef32eb000)
        libX11.so.6 => /usr/lib64/libX11.so.6 (0x00007f3ef31a8000)
        libcrypto.so.1.1 => /usr/lib64/libcrypto.so.1.1 (0x00007f3ef2ebe000)
        libgssapi_krb5.so.2 => /usr/lib64/libgssapi_krb5.so.2 (0x00007f3ef2e69000)
        libkrb5.so.3 => /usr/lib64/libkrb5.so.3 (0x00007f3ef2d80000)
        libk5crypto.so.3 => /usr/lib64/libk5crypto.so.3 (0x00007f3ef2d68000)
        libcom_err.so.2 => /usr/lib64/libcom_err.so.2 (0x00007f3ef2d62000)
        libblkid.so.1 => /usr/lib64/libblkid.so.1 (0x00007f3ef2d0d000)
        libpcre2-8.so.0 => /usr/lib64/libpcre2-8.so.0 (0x00007f3ef2c73000)
        libpthread.so.0 => /nix/store/5m9amsvvh2z8sl7jrnc87hzy21glw6k1-glibc-2.40-66/lib/libpthread.so.0 (0x00007f3ef2c6c000)
        libwayland-server.so.0 => /usr/lib64/libwayland-server.so.0 (0x00007f3ef2c55000)
        libexpat.so.1 => /usr/lib64/libexpat.so.1 (0x00007f3ef2c24000)
        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f3ef2a43000)
        libxcb.so.1 => /usr/lib64/libxcb.so.1 (0x00007f3ef2a18000)
        libkrb5support.so.0 => /usr/lib64/libkrb5support.so.0 (0x00007f3ef2a06000)
        libkeyutils.so.1 => /usr/lib64/libkeyutils.so.1 (0x00007f3ef29fd000)
        libresolv.so.2 => /usr/lib64/libresolv.so.2 (0x00007f3ef29e9000)
        libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1 (0x00007f3ef29cf000)
        libXau.so.6 => /usr/lib64/libXau.so.6 (0x00007f3ef29ca000)

在 qemu 中执行 make install 导致的,有点坑了 但是在两个机器上测试,不是稳定复现的。

very nice 的 python 环境搭建

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

uv 来解决 python3 的环境问题可以吗?

https://github.com/astral-sh/uv

真的有点累了

https://www.reddit.com/r/NixOS/comments/1fv4hyg/anyone_using_python_uv_on_nixos/

  × Querying Python at `/home/martins3/.local/share/uv/python/cpython-3.13.0-linux-x86_64-gnu/bin/python3.13` failed with exit status exit
  │ status: 127
  │ --- stdout:

  │ --- stderr:
  │ Could not start dynamically linked executable: /home/martins3/.local/share/uv/python/cpython-3.13.0-linux-x86_64-gnu/bin/python3.13
  │ NixOS cannot run dynamically linked executables intended for generic
  │ linux environments out of the box. For more information, see:
  │ https://nix.dev/permalink/stub-ld
  │ ---

在 fedora + home-manager 中可以,为什么在 nixos 中就不可以。

为什么 home-manager 中,命令行中编译和 bu 有不同的效果

[ 8666.886755] ftrace_direct_modify: loading out-of-tree module taints kernel.
[ 8666.888054] BPF: [142902] TYPEDEF
[ 8666.888378] BPF: type_id=142909
[ 8666.888675] BPF:
[ 8666.888870] BPF: Invalid name
[ 8666.889206] BPF:
[ 8666.889399] failed to validate module [ftrace_direct_modify] BTF: -22

不知道为什么,现在 compile_commands.json 中需要把 rebuild 字段删掉才可以