nixos使用技巧.md
修改源
sudo su
cat ~/.config/nix/nix.conf
require-sigs = false
experimental-features = nix-command flakes
substituters = http://nix.2011101.xyz https://cache.nixos.org
binary-caches = http://nix.2011101.xyz
使用nixpkgs修改配置nur
vim ~/.config/nixpkgs/config.nix
{
allowUnfree = true;
packageOverrides = pkgs: {
nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
inherit pkgs;
};
};
}
关于镜像安装
# 关于部分pc电脑安装u盘镜像时候在grub闪退,无法进入livecd
# 检查u盘efi分区的grub文件是否存在问题
code /EFI/boot/grub.cfg
# 如果存在问题,修改文件 [Menu configuration] 里面的重复设置,保存即可
# 参考文件
./right_grub.cfg
官方每日构建镜像channels地址
https://channels.nixos.org/
安装全局npm的包
# 设置node_modules目录,否则默认就是store里面的,没有写权限
npm config set prefix ~/.node_modules
# 源
npm config set registry https://registry.npmmirror.com
# 测试安装pnpm
npm i -g pnpm
# 配置可执行文件的位置
ls ~/.node_modules/bin
# 配置到shell配置里面
export PATH=/usr/local/bin:/home/jcleng/.local/bin:/home/jcleng/.node_modules/bin:$PATH
创建electron应用
# 安装nodejs和npm,已以及
nix-env -i electron
# 安装electron-forge
npm i -g electron-forge
# 用electron-forge初始化一个项目
electron-forge init
# 重点是,初始化之后npm安装的electron是不兼容的,需要手动替换,使用nix安装的electron
rm ./node_modules/electron/dist/electron
ln -s /home/jcleng/.nix-profile/bin/electron /home/jcleng/桌面/work/www/electron-quick-start/node_modules/electron/dist/electron
# ./node_modules/electron/dist/electron ⇒ /home/jcleng/.nix-profile/bin/electron
# 运行项目即可
❯ npm run start
# 或
# ❯ electron-forge start
> [email protected] start
> electron-forge start
✔ Checking your system
✔ Locating Application
✔ Preparing native dependencies
✔ Launching Application
[22555:1129/225045.985742:ERROR:CONSOLE(168)] "Electron sandbox_bundle.js script failed to run", source: node:electron/js2c/sandbox_bundle (168)
[22555:1129/225045.986037:ERROR:CONSOLE(168)] "TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))", source: node:electron/js2c/sandbox_bundle (168)
fcitx5配置 参考:https://hub.fastgit.org/hosxy/Fcitx5-Material-Color
# 配置文件
/home/jcleng/.config/fcitx5/config
/home/jcleng/.config/fcitx5/conf/classicui.conf
# 主题下载目录
~/.local/share/fcitx5/themes/Material-Color/
# 输入方案配置目录
~/.local/share/fcitx5/rime
# rime配置文件
~/.config/fcitx5/conf/rime.conf
# rime显示的配置文件,如果没有创建即可
~/.local/share/fcitx5/rime/default.custom.yaml
# 注意,修改rime的配置需要右击右下角图标重新部署生效
关于nixos的gc
# The command nix-collect-garbage is mostly an alias of nix-store --gc
# 在gurb目录的环境,可看到system-[num]-link num就是id
ls /nix/var/nix/profiles
# 清除,用户的环境, 清除之后查看: nix-env --list-generations
nix-collect-garbage --delete-older-than 50
# 或者
nix-env --delete-generations +5
# 清除,系统环境,即grub那些,清除之后查看: ls /nix/var/nix/profiles
sudo nix-collect-garbage --delete-older-than 50
# 更新之后参数是14d
sudo nix-collect-garbage --delete-older-than 14d
# 清除已经删除的grub,nixos-manual文档可知
sudo /run/current-system/bin/switch-to-configuration boot
# --help报错
nix-env -i groff
# 删除系统日志
du -hd 1 /var/log/journal
sudo journalctl --vacuum-size=50M
# 默认qemu的系统地址
/var/lib/libvirt/images
防火墙
# 默认开启,最好关闭
systemctl stop firewall.service
# 且禁用 配置文件/etc/nixos/configuration.nix进行禁用
networking.firewall.enable = false;
图形化的解压压缩软件
nix-env -iA nixpkgs.xarchiver
xarchiver
# ark https://apps.kde.org/zh-cn/ark/
nix-env -iA nixpkgs.ark
pdf浏览
# okular
nix-env -iA nixpkgs.okular
多个版本的共存权重设置
❯ nix-env -q|grep php
php-7.1.33
php-with-extensions-7.4.27
# 越小权重越高
To make files from binutils take precedence over files from gcc:
$ nix-env --set-flag priority 5 binutils
$ nix-env --set-flag priority 10 gcc
镜像烧写
# etcher
nix-env -iA nixpkgs.etcher
KDE桌面相关
# 显示虚拟左面快捷键:
Ctrl+F8 预览所有桌面/新增减少桌面
# 关于桌面的快捷键查看是在: 快捷键设置>KWin 里面
# 在设置>虚拟桌面里面可以设置虚拟桌面的动画等展现方式
# 字体一般8pt,只有窗口标题10pt
gparted磁盘操作支持格式
nixpkgs.dosfstools/nixpkgs.mtools
appimage
nixpkgs.appimage-run
Nix 的 Flake
# 查看是否默认开启, 未配置提示: error: 'flake' is not a recognised command
nix flake
# 没有开启的话,编辑配置文件: sudo -e /etc/nixos/configuration.nix 增加配置
nix = {
package = pkgs.nixUnstable;
extraOptions = ''
experimental-features = nix-command flakes
'';
};
# 然后重新配置
sudo nixos-rebuild switch
# 然后在 /etc/nixos 里创建一个 flake.nix 文件
{
# 文件描述,随便写,或者不写也可以
description = "NixOS Flake";
# 输入配置,即软件源
inputs = {
# Nixpkgs,即 NixOS 官方软件源
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# 未测试
# nixpkgs.url = "git+https://mirrors.ustc.edu.cn/nix-channels/nixos-unstable"
};
# 输出配置,即 NixOS 系统配置
outputs = { self, nixpkgs, ... }@inputs: {
# 定义一个名为 nixos 的系统
nixosConfigurations."nixos" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
];
};
# 你也可以在同一份 Flake 中定义好几个系统,NixOS 会根据主机名 Hostname 决定用哪个
# nixosConfigurations."nixos2" = nixpkgs.lib.nixosSystem {
# system = "x86_64-linux";
# modules = [
# ./configuration2.nix
# ];
# };
};
}
# 配置成功,提示: error: 'nix flake' requires a sub-command.
nix flake
# 生成lock文件, warning: creating lock file '/etc/nixos/flake.lock'
cd /etc/nixos
sudo nix flake update
# flake.lock 指定了 nixpkgs 的 commit 编号和 SHA256 哈希值,这样即使这份配置文件被复制到其它机器上,其它机器的 Nix 包管理器也会下载这个特定版本的 nixpkgs 软件源,并安装对应版本的软件,真正做到了软件版本一模一样。
# 最后运行 nixos-rebuild switch 命令,NixOS 会自动优先读取 flake.nix 而非 configuration.nix,把系统里的所有软件包升级(或降级)到这个特定的版本。但因为我们把 configuration.nix 加入了 flake.nix 的 modules 数组,所以系统配置还是保持不变。
# 可能部分软件flake不存在,重新修改名字一下
sudo nixos-rebuild switch
sudo nixos-rebuild switch --option substituters "https://mirror.nju.edu.cn/nix-channels/store/" --show-trace
# 安装flake之后, 搜索
nix search nixpkgs zsh
手写笔记
nix-env -iA nixpkgs.xournalpp
# 使用不了使用flatpak安装吧
flatpak install xournalpp.xournalpp
# 触屏手写,需要设置[编辑][触摸屏]允许触摸板的绘画输入
关于首次安装非root用户的密码
# 配置文件中指定了users.users.jcleng用户,jcleng用户的密码默认是空的
# 需要重新设置密码,开机进入grub的时候按e,进入编辑模式,在启动项最后增加空格single 然后回车进入单用户模式,输入root的密码再回车进入命令行
# 然后重设密码即可
passwd jcleng
dock栏
# 不推荐了
latte-dock
# 主题和布局
https://store.kde.org/browse?cat=417
# 下载Deepin20-Fashion-Mode.layout.latte到目录
/home/jcleng/.config/latte/
├── 我的布局.layout.latte
├── Deepin20-Fashion-Mode.layout.latte
├── Default.layout.latte
└── templates
tint2
# 主题
mkdir -p ~/.config/tint2
# 手动添加文件
nix-store --add-fixed sha256 <path>
# 国内源获取文件
sudo nixos-rebuild switch --option substituters "https://mirror.sjtu.edu.cn/nix-channels/store"
sudo nixos-rebuild switch --option substituters "https://mirrors.ustc.edu.cn/nix-channels/store/"
# 微信
nix run github:nixos-cn/flakes#wine-wechat
远程桌面客户端
remmina
https://gitlab.com/Remmina/Remmina
开启远程桌面
https://nixos.wiki/wiki/Remote_Desktop
# 不推荐xrdp,登录时候帐户没有区分开来
services.xrdp.enable = true;
# 我是kde,就使用startplasma-x11, 其他:xfce4-session/xterm/icewm 图形界面的启动命令
services.xrdp.defaultWindowManager = "startplasma-x11";
# 用remmina登录即可, 注意同一个用户不能多端同时登录,意想不到的错误
# fcitx5输入法远程无法使用
# 推荐VNC
# 客户端
## remmina
flatpak install flathub org.remmina.Remmina
## guacamole
字体安装使用技巧
# 部分软件如vscode不支持系统自带的字体进行设置,就是说需要的字体用户自行安装
# 编程字体下载:
nerdfonts
https://www.nerdfonts.com/
https://github.com/ryanoasis/nerd-fonts
# 中文字体
# 思源字体
https://github.com/adobe-fonts/source-han-sans/releases
# 文泉驿
http://wenq.org/wqy2/index.cgi
# 手动安装字体,复制ttf/otf到用户fonts目录即可,以思源字体为例子:
cp SourceHanSans.ttc ~/.local/share/fonts/
# 一个下载地址
wget https://download.fastgit.org/adobe-fonts/source-han-sans/releases/download/2.003R/SourceHanSans.ttc
升级系统
# 使用sudo添加最新的源
sudo nix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixos-21.11 nixos
# 更新
sudo nixos-rebuild switch --upgrade --option substituters "https://mirror.sjtu.edu.cn/nix-channels/store"
# 更新老是失败加上-k参数[{--keep-going | -k} [{--max-jobs | -j} number] 一直重复即可
sudo nixos-rebuild switch -k -j 20 --upgrade --option substituters "https://mirror.sjtu.edu.cn/nix-channels/store"
# 回滚
# 使用当前的grub作为默认的引导启动项
/run/current-system/bin/switch-to-configuration boot
# 回滚到指定grub版本,N是对应的版本
/nix/var/nix/profiles/system-N-link/bin/switch-to-configuration switch
# 修复异常
# 65.4. Nix Store Corruption
sudo nixos-rebuild switch --repair
sudo nix-store --verify --check-contents --repair
nixpkgs 单用户安装
# 单用户安装
./install --no-daemon --no-channel-add
# 查看:
/home/leng/.nix-profile/etc/profile.d/nix.sh
# 编辑: /home/leng/.bashrc
export NIX_SSL_CERT_FILE=/etc/ssl/ca-bundle.pem
export NIX_PROFILES="/nix/var/nix/profiles/default $HOME/.nix-profile"
export PATH="$NIX_LINK/bin:$PATH"
NIX_LINK=$HOME/.nix-profile
export MANPATH="$NIX_LINK/share/man:$MANPATH"
nix-channel --list
nix-channel --add https://mirrors.tuna.tsinghua.edu.cn/nix-channels/nixpkgs-unstable nixpkgs
# 明显看到网络在下载
nix-channel --update
# 使用nix命令,提示被禁用
nix search postgresql
error: experimental Nix feature 'nix-command' is disabled; use '--extra-experimental-features nix-command' to override
error: experimental Nix feature 'flakes' is disabled; use '--extra-experimental-features flakes' to override
# 修改文件:/home/leng/.config/nix/nix.conf 增加
# https://nixos.org/manual/nix/unstable/command-ref/conf-file.html
experimental-features = nix-command flakes
# 或者加上参数
nix --extra-experimental-features nix-command show-config
nix --extra-experimental-features nix-command --extra-experimental-features flakes search pgsql
# 使用
nix search pgsql
# 搜索
## 默认是搜索flakes
nix search top
## 指定nixpkgs包搜索
nix search nixpkgs pgsql
# /home/leng/.config/nix/nix.conf 文件原文
binary-caches = https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store/ https://cache.nixos.org/
require-sigs = false
experimental-features = nix-command flakes
flake-registry = https://cdn.jsdelivr.net/gh/NixOS/flake-registry@master/flake-registry.json
查看dns
nix-env -iA nixpkgs.dig
dig alidns.com
外置显示器亮度调节
gammy
磁盘挂载
# 文件 /etc/nixos/hardware-configuration.nix
# Do not modify this file! It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:
{
imports =
[ (modulesPath + "/installer/scan/not-detected.nix")
];
boot.initrd.availableKernelModules = [ "xhci_pci" "nvme" "usb_storage" "sd_mod" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ];
# 指定内核版本
boot.kernelPackages = pkgs.linuxKernel.packages.linux_6_14;
fileSystems."/" =
{ device = "/dev/disk/by-uuid/57314842-45ff-457a-8c7e-f2d6fce57d33";
fsType = "btrfs";
};
# fileSystems."/swp" =
# { device = "/dev/disk/by-uuid/7015db9b-9db2-4b7c-8cdb-12e3c6c876a3";
# fsType = "btrfs";
# };
fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/09C1-B27D";
fsType = "vfat";
};
# swapDevices =
# [ { device = "/dev/disk/by-uuid/c648867b-b85d-445f-9fe3-1007408874a2"; }
# ];
powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
# high-resolution display
hardware.video.hidpi.enable = lib.mkDefault true;
}
virtualbox 虚拟机, 需要重启
virtualisation.virtualbox.host.enable = true;
virtualisation.virtualbox.guest.enable = true;
# 支持usb的扩展包
virtualisation.virtualbox.host.enableExtensionPack = true;
# Define a user account. Don't forget to set a password with ‘passwd’.
users.users.jcleng = {
isNormalUser = true;
extraGroups = [ "wheel" "networkmanager" "vboxusers" ]; # Enable ‘sudo’ for the user.
packages = with pkgs; [
# firefox
# thunderbird
];
};
docker
virtualisation.docker.enable = true;
virtualisation.docker.enableOnBoot = true;
# 更新修改为下面: virtualisation.docker.extraOptions = "-H tcp://0.0.0.0:39012";
virtualisation.docker.daemon.settings = {
hosts = [
"0.0.0.0:39012"
];
};
重新安装efi到boot分区
╭─jcleng@nixos ~
╰─$ sudo nixos-rebuild boot --install-bootloader
building Nix...
building the system configuration...
Copied "/nix/store/sj364k7lsr47i87f7iv835lvvn7g4fqm-systemd-250.4/lib/systemd/boot/efi/systemd-bootx64.efi" to "/boot/EFI/systemd/systemd-bootx64.efi".
Copied "/nix/store/sj364k7lsr47i87f7iv835lvvn7g4fqm-systemd-250.4/lib/systemd/boot/efi/systemd-bootx64.efi" to "/boot/EFI/BOOT/BOOTX64.EFI".
Random seed file /boot/loader/random-seed successfully written (512 bytes).
在华为云上安装镜像
# 镜像服务->创建桶,上传镜像,然后创建虚拟机,安装
# 查看磁盘
sudo su
lsblk
parted /dev/vda -- mklabel msdos
parted /dev/vda -- mkpart primary 1MiB -1MiB
mkfs.ext4 -L nixos /dev/vda1
# 备份虚拟机磁盘生成镜像即可
code-server
services.code-server.enable=true;
services.code-server.host="0.0.0.0";
services.code-server.port=8081;
services.code-server.hashedPassword="$argon2id$v=19$m=102400,t=2,p=8$tSm+JOWigOgPZx/g44K5fQ$WDyus6py50bVFIPkjA28lQ";
services.code-server.user="jcleng";
services.code-server.group="users";
# >>> from argon2 import PasswordHasher
# >>> ph = PasswordHasher()
# >>> hash = ph.hash("s3kr3tp4ssw0rd")
# >>> hash
# '$argon2id$v=19$m=102400,t=2,p=8$tSm+JOWigOgPZx/g44K5fQ$WDyus6py50bVFIPkjA28lQ'
# >>> ph.verify(hash, "s3kr3tp4ssw0rd")
# True
kde plasma 中使用Meta/Super/win 键打开应用程序启动器(直接设置快捷键是不能设置单个按键的)
vi ~/.config/kwinrc
# 加入/修改下面两行
[ModifierOnlyShortuts]
Meta=org.kde.plasmashell,/PlasmaShell,org.kde.PlasmaShell,activateLauncherMenu
# 注销/登录
扩展nixpkgs-unstable
# nixos进行扩展
# 使用sudo安装
sudo nix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixpkgs-unstable/ unstable
sudo nix-channel --list
sudo nix-channel --update unstable
nixpkgs.config.packageOverrides = pkgs: {
unstable = import <unstable> {
config = config.nixpkgs.config;
};
};
environment = {
systemPackages = with pkgs; [
unstable.go
unstable.google-chrome
];
};
# nixpkg扩展: 不要用sudo执行,只扩展给当前用户即可
# https://nixos.wiki/wiki/Nix_channels
nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
# nix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixpkgs-unstable/ nixpkgs
nix-channel --list
nix-channel --update nixpkgs
# 安装软件就会安装unstable最新的软件了
nix-env -iA nixpkgs.go --option substituters "https://mirror.sjtu.edu.cn/nix-channels/store"
系统修复,single模式也进不去
# 烧启动盘到u盘: /dev/sdc
lsblk
sudo dd if=./latest-nixos-minimal-x86_64-linux.iso of=/dev/sdc bs=4M status=progress conv=fdatasync
sudo dd if=./latest-nixos-minimal-x86_64-linux2111.iso of=/dev/sda1 bs=4M status=progress conv=fdatasync
# 进入系统,挂载原来的盘
lsblk
mount /dev/nvme1p03 /mnt
# 编辑配置文件
vi /mnt/etc/nixos/configuration.nix
# 连接wifi: wpa_supplicant -B -i 网卡名 -c <(wpa_passphrase 'wifi名' 'wifi密码')
wpa_supplicant -B -i wlp4s0 -c <(wpa_passphrase 'jcleng' '123456')
# 查看ip地址
ip a
# 最后安装
# 尝试删除所有非/mnt/home/的数据
rm -rf bin boot data dev etc lib nix opt proc result root run srv swp sys tmp usr var
# 最后重新安装
nixos-install --root /mnt
# nixos-install --root /mnt --option substituters "https://mirror.sjtu.edu.cn/nix-channels/store"
# 先修改密码,不重启
nixos-enter --root '/mnt'
passwd
passwd jcleng
baloo_file_ext占用高
# 为了在 Plasma 桌面上使用 Baloo 进行搜索,启动 krunner (默认快捷键 ALT+F2)并键入查询。若要在 Dophin(文件管理器)内搜索,按CTRL+F。
# 在默认情况下,桌面搜索的 KCM 仅显示两个选项:一个将文件夹放入黑名单的面板以及一种一次点击来禁用它的方法。
# 禁用索引器
balooctl suspend
balooctl disable
# 把root的也禁用
sudo balooctl suspend
sudo balooctl disable
nix-serve搭建
nix-shell -p nix-serve
nix-serve -p 9091
# 使用1:
vi ~/.config/nix/nix.conf
binary-caches = http://[ip]:9091/
require-sigs = false
# 使用2
--option substituters "http://[ip]:9091"
shell初始执行的脚本
programs.bash.loginShellInit="source ~/.bashrc";
ttyd在线的web shell
# 软件ttyd
ttyd -c jcleng:ttydjcleng@ai bash
http://www.leng2011.icu:7681/
# ttyd注册服务
systemd.services."ttyd" = {
description = "ttyd";
documentation = [ "https://github.com/tsl0922/ttyd" ];
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
requires = [ "network-online.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "/run/current-system/sw/bin/ttyd -u 1000 -c jcleng:ttydjcleng@qq /run/current-system/sw/bin/bash";
ExecReload = "${pkgs.procps}/bin/kill -s HUP $MAINPID";
};
};
systemd.services.ttyd.enable = true;
nix-env 使用
# 配置文件新增
nix.settings.trusted-users=["root" "jcleng"];
# 才能使用substituters
nix-env -iA nixpkgs.tightvnc --option substituters "https://mirror.nju.edu.cn/nix-channels/store/"
cron定时任务
# Enable cron service
services.cron = {
enable = true;
systemCronJobs = [
# "*/1 * * * * jcleng date >> /tmp/cron.log"
# 每60分钟执行
"*/60 * * * * jcleng /home/jcleng/下载/aliyunpan-v0.2.6-linux-amd64/aliyunpan token update -mode 2"
];
};
修复grub-uefi
# 进入live-cd系统
# 挂载系统盘
mount /dev/sdb3 /mnt
# 挂载esp分区,如果是有问题的,可以全部 删除文件
mount /dev/sda1 /mnt/boot/
# 进入chroot系统
nixos-enter --root '/mnt'
# 重新生成efi引导
NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot
# 退出chroot
exit
# 重启
reboot
推荐虚拟机qemu+libvirtd+kvm
virtualisation.libvirtd.enable = true;
virtualisation.libvirtd.onBoot = "start";
virtualisation.libvirtd.qemu.ovmf.enable=true;
# uefi支持,x86和arm
virtualisation.libvirtd.qemu.ovmf.packages=[ pkgs.OVMFFull.fd pkgs.pkgsCross.aarch64-multiplatform.OVMF.fd ];
sudo find / -name QEMU_EFI.fd
# /nix/store/crd7r0jz1qbglhs03l84pd5f0kwbnxib-OVMF-aarch64-unknown-linux-gnu-202211-fd/FV/QEMU_EFI.fd
# /nix/store/nz40d8nfah5ddpzx03ny47yzxinpxci7-qemu-ovmf/FV/QEMU_EFI.fd
# 就可以使用-bios参数了
# 图形化软件
virt-manager
# enable nested virtualization(虚拟化嵌套)
boot.extraModprobeConfig = "options kvm_intel nested=1";
# Enable UEFI with OVMF, 加入配置到文件
vi $XDG_CONFIG_HOME/libvirt/qemu.conf
nvram = [ "/run/libvirt/nix-ovmf/AAVMF_CODE.fd:/run/libvirt/nix-ovmf/AAVMF_VARS.fd", "/run/libvirt/nix-ovmf/OVMF_CODE.fd:/run/libvirt/nix-ovmf/OVMF_VARS.fd" ]
ls /run/libvirt/nix-ovmf
# AAVMF_CODE.fd AAVMF_VARS.fd OVMF_CODE.fd OVMF_VARS.fd
# 关于XDG_CONFIG_HOME
export XDG_CONFIG_HOME=$HOME/.config
# 配置到nix,需要重启
environment.extraInit="
export XDG_CONFIG_HOME=$HOME/.config
";
vnc服务手动启动
# 安装vnc服务以及openbox窗口管理软件,或者xfce: xfce.xfdesktop
tigervnc xorg.xinit openbox
# 启动文件
vi ~/.vnc/xstartup
#!/run/current-system/sw/bin/bash
exec openbox-session
# kde
# exec startplasma-x11
## 配置openbox默认启动xfdesktop
vi ~/.config/openbox/autostart
# 最后增加
exec xfdesktop&
# 登录vnc的密码
vncpasswd ~/.vnc/passwd
# 手动命令启动
xinit ~/.vnc/xstartup -- $(realpath $(which Xvnc)) :8 PasswordFile=~/.vnc/passwd
# 查看端口, 用:8就是5908
netstat -apn|grep :59
# 连接用软件tigervnc-client
# 本地使用测试
ls /tmp/.X11-unix
# X0 X8
export DISPLAY=:8.0
nix-shell -p xorg.xeyes
xeyes
# 其他,可以启动一个X11-unix服务
X :2
# frp远程
[vnc]
type = tcp
local_ip = 127.0.0.1
local_port = 5908
custom_domains = vnc.leng2011.icu
remote_port = 5908
# 就可以使用vnc.leng2011.icu:5908进行连接了
# 注册一个vnc开机服务
# 生成envfile环境变量文件
env >> envfile
# 放到nix配置
systemd.services."vnc" = {
description = "vnc";
documentation = [ "https://github.com/TigerVNC/tigervnc" ];
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
requires = [ "network-online.target" ];
# partOf = [ "network-online.target" ];
serviceConfig = {
Type = "simple";
User= "jcleng";
Group= "users";
EnvironmentFile="/home/jcleng/.vnc/envfile";
ExecStart = "/run/current-system/sw/bin/xinit /home/jcleng/.vnc/xstartup -- /run/current-system/sw/bin/Xvnc :8 PasswordFile=/home/jcleng/.vnc/passwd";
ExecReload = "${pkgs.procps}/bin/kill -s HUP $MAINPID";
};
};
systemd.services.vnc.enable = true;
# 状态
systemctl status vnc.service
创建systemd服务,frp
systemd.services."frp" = {
description = "frp";
documentation = [ "https://github.com/fatedier/frp" ];
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
requires = [ "network-online.target" ];
# partOf = [ "network-online.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "/home/jcleng/desk/work/frp/frp_0.47.0_linux_amd64/frpc -c /home/jcleng/desk/work/frp/frp_0.47.0_linux_amd64/frp_http2.ini";
ExecReload = "${pkgs.procps}/bin/kill -s HUP $MAINPID";
};
};
systemd.services.frp.enable = true;
# 查看状态
# systemctl status frp.service
# 关于systemd_service
# https://zh.opensuse.org/openSUSE:How_to_write_a_systemd_service
vscode远程ssh到nixos,通过docker中转一遍(底包不要使用Alpine,Alpine兼容性不行)
# 因为是nixos,服务端无法运行vscode-server的二进制包;安装一个docker代理一遍ssh, 运行到本地的2222端口, vscode连接也连接2222端口再进行工作目录的编辑
# https://github.com/takeyamajp/docker-ubuntu-sshd
docker pull takeyamajp/ubuntu-sshd:latest
docker pull dockerproxy.com/takeyamajp/ubuntu-sshd:latest
# 把客户端的id_rsa.pub配置到nixos的${HOME}/.ssh/id_rsa.pub
docker run -itd -p 2222:22 \
--name=sshdserver \
-v ${HOME}/.ssh/id_rsa.pub:/home/jcleng/.ssh/authorized_keys \
-v /home/jcleng/desktop/work/www:/home/jcleng/desktop/work/www \
a31df6066303
# vscode连接,配置目录可写
docker exec -it sshdserver bash
# 创建和宿主机一样的用户
useradd jcleng
passwd jcleng
# 有了权限才能登录
chown -R jcleng:jcleng /home/jcleng/
ssh [email protected] -p 2222
# 就是不能使用宿主机的扩展和配置了,使用docker的配置
# 之后就可以连接了, 设置终端
{
"terminal.integrated.shell.linux": "/usr/bin/bash",
}
# 使用frp代理到外网2222端口: ssh [email protected] -p 2222
[common]
server_addr = www.leng2011.icu
server_port = 7000
privilege_token = leng2011
token = leng2011
[ttyd]
type = tcp
local_ip = 127.0.0.1
local_port = 2222
custom_domains = vnc.leng2011.icu
remote_port = 2222
命令行进入tty
sudo chvt 1
# 回到图形化
sudo chvt 7
配置sddm的dpi
# 配置sddm的dpi和主题
services.xserver.displayManager.sddm.settings={
X11={
ServerArguments="-dpi 192";
EnableHiDPI=true;
};
Theme={
CursorTheme="Bibata-Modern-Classic";
CursorSize=48;
};
};
# 会生成文件
cat /nix/store/2d5ks6g6gph1g2fb57p5fnm0z57bn4rn-sddm.conf
...
[X11]
...
ServerArguments=-dpi 192
...
提示untrusted
warning: ignoring untrusted substituter 'http://cache.leng2011.icu'
# 增加nix配置
nix.settings.substituters = [ "http://cache.leng2011.icu" "https://mirrors.ustc.edu.cn/nix-channels/store" ];
command not found 提示
programs.command-not-found.enable=true;
# 然后更新索引
sudo nix-channel --update
# 直到文件出现
ls /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite
# 效果
podman
# The program 'podman' is not in your PATH. You can make it available in an
# ephemeral shell by typing:
# nix-shell -p podman
nix用户配置 ~/.config/nix/nix.conf
# 普通用户和root用户都可以配置
# substituters = https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store
require-sigs = false
experimental-features = nix-command flakes
substituters = https://cache.nixos.org http://cache.leng2011.icu https://mirrors.ustc.edu.cn/nix-channels/store https://cache.nixos.org/ https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store https://jcleng-dev.cachix.org
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= jcleng-dev.cachix.org-1:z9ANWkDcDZfbUGK12osxOaX4u4A9kmhnRKu3Oh5OQcc=
# nix-channel的缓存时间
tarball-ttl = 1
网卡信息
sudo lshw -C network
# *-network:0
# description: Wireless interface
# configuration: broadcast=yes driver=iwlwifi driverversion=6.5.9 firmware=81.31fc9ae6.0 so-a0-hr-b0-81.uc ip=192.168.1.19 latency=0 link=yes multicast=yes wireless=IEEE 802.11
# *-network:1
# description: Ethernet interface
# configuration: autonegotiation=on broadcast=yes driver=e1000e driverversion=6.5.9 firmware=0.5-4 latency=0 link=no multicast=yes port=twisted pair
# 通过configuration的driver查看硬件
lspci -nnk|grep e1000e
lspci -nnk|grep iwlwifi
# 查看驱动详细信息
modinfo e1000e
modinfo iwlwifi
# 下载驱动并安装
insmod
# 或者
modprobe
steam手柄支持
# 大屏模式能手柄支持, 但是游戏内不支持, 需要开启这个选项
hardware.steam-hardware.enable=true;
开启zram(设置优先级在swap之上)
# 手动设置
# 开机启动需要设置
modprobe zram
echo 16G | sudo tee /sys/block/zram0/disksize
sudo mkswap /dev/zram0
# 开启并设置优先级
sudo swapon -p 100 /dev/zram0
cat /proc/swaps
zswap(配合swap进行使用的, 感觉效果不如直接使用zram, 可以在zarm之上进行叠加使用)
grep -R . /sys/module/zswap/parameters
boot.kernelParams = [
"zswap.enabled=1" "zswap.compressor=lz4" "zswap.max_pool_percent=80" "zswap.zpool=z3fold"
];
# 其他配置
zswap.enabled=1 zswap.compressor=lz4 zswap.max_pool_percent=20 zswap.zpool=z3fold
# accept_threshold_percent – zswap 在页面满后再次开始接受页面的百分比阈值。 Ubuntu 中默认为 90%。
# compressor – 设置压缩算法。可能的值包括 zstd、deflate、lzo、842、lz4 和 >lz4hc。看比较。
# enabled – 通过设置值 0 或 1 来启用/禁用该功能。
# exclusive_loads – 加载页面时使 zswap 条目无效。值包括 0 或 1。
# max_pool_percent – zswap 可以占用的最大物理内存百分比。
# zpool – 控制压缩内存池的管理。值包括zbud(2:1或更低的压缩比)、z3fold(3:1或更低)、zsmalloc(自内核以来更复杂的方法) 6.3)。
# 手动修改
echo 1 | sudo tee /sys/module/zswap/parameters/enabled
echo zsmalloc | sudo tee /sys/module/zswap/parameters/zpool
# 查看使用情况, 只有内存高的时候才会有
cat /proc/meminfo | grep -i zswap
# Zswap: 925808 kB
# Zswapped: 3986076 kB