Document not found (404)
+This URL is invalid, sorry. Please use the navigation bar or search to continue.
+ +diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..1d953f4b --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.genSUMMARY.sh b/.genSUMMARY.sh new file mode 100755 index 00000000..91afa974 --- /dev/null +++ b/.genSUMMARY.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env bash + +getTitle() { + PATHMD=$1 + head -n 3 "${PATHMD}" | awk '/^# / {$1=""; print substr($0,2); exit;}' +} +genDir() { + Dir=$1 + for PATHMD in $(find $Dir -name "*.md" -exec ./.parent_dirs.sh {} \; | sort -n | uniq); do + + # remove tailing slash for dir + PATHMD=${PATHMD%/} + + # README.md & index.md belongs to current folder + NAMEMD=${PATHMD##*/} + if [[ ${NAMEMD} =~ README.*md || ${NAMEMD} == "index.md" || ${NAMEMD} == "SUMMARY.md" ]]; then + continue + fi + + # ignore . + if [[ ${PATHMD} == "." ]]; then + continue + fi + + # count indentation # $PATHMD = ./miao/wang/x.md + TMP1=${PATHMD#./} # TMP1 = miao/wang/x.md + TMP2=${TMP1//[^\/]} # TMP2 = // + INDENT=${#TMP2} # INDENT = 2 + + for (( i=0; i<${INDENT}; i++ )); do + echo -n " " + done + + if [[ -f ${PATHMD} ]]; then + TITLE=$(getTitle "${PATHMD}") + if [[ -n ${TITLE} ]]; then + echo "* [${TITLE}](${PATHMD})" + else + echo "* [${NAMEMD}](${PATHMD})" + fi + elif [[ -f ${PATHMD}/index.md ]]; then + TITLE=$(getTitle "${PATHMD}/index.md") + if [[ -n ${TITLE} ]]; then + echo "* [${TITLE}](${PATHMD}/index.md)" + else + echo "* [${NAMEMD}/](${PATHMD}/index.md)" + fi + elif [[ -f ${PATHMD}/README.md ]]; then + TITLE=$(getTitle "${PATHMD}/README.md") + if [[ -n ${TITLE} ]]; then + echo "* [${TITLE}](${PATHMD}/README.md)" + else + echo "* [${NAMEMD}/](${PATHMD}/README.md)" + fi + elif [[ -d ${PATHMD} ]]; then + echo "* [${NAMEMD}/]()" + else + echo "* [${NAMEMD}]()" + fi + done +} + +echo "# Summary" +echo +echo "# 🏠主页" +echo +echo "* [📔README.md](./README.md)" +echo +echo "# 🌏全局配置" +echo +echo "* [config.nix](./config.nix.md)" +echo "* [TODO: nix/nix.conf](./nix/nix.conf.md)" +echo "* [opt.nix](./opt.nix.md)" +echo +echo "# 🖥️系统配置(需sudo,用于NixOS)" +echo +echo "* [system.nix](./system.nix.md)" +genDir ./sys/ +echo +echo "# 😺用户配置(无需sudo,用于Nix/NixOS)" +echo +echo "* [home.nix](./home.nix.md)" +genDir ./usr/ +echo +echo "# 🤖安卓配置(无需sudo,复用\"用户配置\")" +echo +echo "* [nix-on-droid.nix](./nix-on-droid.nix.md)" +echo +echo "# 🔩通用模块" +echo +genDir ./modules/ +echo +echo "# 📝文档和心得体会" +echo +genDir ./docs/ +echo +echo "# 📃Nix脚本(nix-shell和打包)" +echo +genDir ./scripts/ +echo +echo "# 📌其他" +echo +echo "* [shell.nix](./shell.nix.md)" diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..99ad31a8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +theme/* linguist-vendored diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..7521f0ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +result* +.direnv +book/ +SUMMARY.md +*.nix.md +nix/nix.conf.md +opt-local.nix +.ccache/ diff --git a/.markcode_progress.sh b/.markcode_progress.sh new file mode 100755 index 00000000..6c5e7abc --- /dev/null +++ b/.markcode_progress.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +n=$(grep "#MC" -rl --include="*.nix" | grep -v "book/" | wc -l) +d=$(find -name "*.nix" | grep -v "book/" | wc -l) + +sed -i '1 s,[0-9]\+/[0-9]\+,'$n'/'$d',' ./README.md diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..f1731109 --- /dev/null +++ b/.nojekyll @@ -0,0 +1 @@ +This file makes sure that Github Pages doesn't process mdBook's output. diff --git a/.parent_dirs.sh b/.parent_dirs.sh new file mode 100755 index 00000000..367ada54 --- /dev/null +++ b/.parent_dirs.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +path="$1" +echo $path +dir=$(dirname "$path") +while true; do + echo $dir/ + + dirdir=$(dirname "$dir") + if [[ "$dir" != "$dirdir" ]]; then + dir="$dirdir" + else + break + fi +done diff --git a/404.html b/404.html new file mode 100644 index 00000000..ab2dde87 --- /dev/null +++ b/404.html @@ -0,0 +1,226 @@ + + +
+ + +This URL is invalid, sorry. Please use the navigation bar or search to continue.
+ +当初始化nixpkgs
时,例如pkgs = import <nixpkgs> {}
,
+nixpkgs
的初始化代码会读取~/.config/nixpkgs/config.nix
作为nixpkgs.config
参数。
+如果你对nixpkgs
的初始化感兴趣,可以去看看这部分的源代码<nixpkgs>/pkgs/top-level/impure.nix
。
config.nix
文件(即nixpkgs.config
)接受的参数可以参考nixpkgs的官方文档的
+config Options Reference章节,
+或是去看nixpkgs这部分的源码<nixpkgs>/pkgs/top-level/config.nix
。
下面是添加了注解的我的config.nix
:
{
+
+禁用安装非本地的包,比如禁止x86_64-linux的包被安装到aarch64-linux上。
+ allowUnsupportedSystem = false;
+ allowUnfree = true;
+ packageOverrides = pkgs: rec {
+
+添加nix user repository (NUR)到nixpkgs里。
+ nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
+ pkgs = pkgsu;
+ };
+
+添加非稳定版的nixpkgs到nixpkgs里,
+比如非稳定版的hello可以通过pkgs.pkgsu.hello
来访问。
pkgsu = import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/master.tar.gz") {};
+
+添加flake-compat,用于在nix expression中使用flake的包
+ flake-compat = import (builtins.fetchTarball {
+ url = "https://github.com/edolstra/flake-compat/archive/0f9255e01c2351cc7d116c072cb317785dd33b33.tar.gz";
+ sha256 = "0m9grvfsbwmvgwaxvdzv6cmyvjnlww004gfxjvcl806ndqaxzy4j";
+ });
+ };
+}
+
+
+ nixpkgs/lib/modules.nix:
+从loadModule
可以看出,imports可以接受Function、Attr、路径,不能够嵌套List。
注意mkSkeletonFromList通过
+${toString (length l)}
+实现了一个根据l长度的switch case。
crossSystem的4个域分别为cpu-vendor-kernel-abi
+import <nixpgks> {}
+的加载流程
vim_configurable.override {python = python3} +vimUtils.makeCustomizable (vim.override {python = python3}) +vimUtils.makeCustomizable (vim.override {python = python3})
+似乎是一个浮现override变量的最小集 +f = a:{res = a+1;} +fo = pkgsMiao.makeOverride f +f 2
+ +参考Packaging/32bit Applications。
+打包使用pkgs.pkgsi686Linux.stdenv.mkDerivation
+编译使用pkgs.pkgsi686Linux.gcc
+打包使用pkgs.multiStdenv.mkDerivation。
+编译使用pkgs.gcc_multi。
+ +This file try to implement a package wrapper, which will automatically push pkg
to cachix upon building.
+However, this method seems not work, due to limited resources in nix-build environment.
+For more details, see here.
{ cachix
+, stdenv
+, writeShellScript
+}:
+
+{ pkg
+, sha256
+, cachix_dhall
+, cachix_name
+, name ? "cachixed"
+}:
+
+builtins.derivation {
+ inherit name;
+ system = builtins.currentSystem;
+ builder = writeShellScript "cachix-package-builder" ''
+ source ${stdenv}/setup
+ echo ${pkg} > $out
+ if [[ -f "${cachix_dhall}" ]]; then
+ ${cachix}/bin/cachix -c ${cachix_dhall} push ${cachix_name} ${pkg}
+ result=$?
+ echo result $result
+ exit $result
+ fi
+ '';
+
+ outputHashMode = "flat";
+ outputHashAlgo = "sha256";
+ outputHash = sha256;
+}
+
+
+ Objective:
+Automatically push specific built packages to cachix during home-manager switch
/nixos-rebuild switch
/nix-shell
.
Although there are several existing ways to achieve this:
+However, the granularity of these methods is coarse; they push all packages to cachix. +Is there a way to allow users to control which packages are pushed?
+Use hooks to push the selected packages to cachix:
+Scenario | Hook | Example |
---|---|---|
home-manager | home.activation | modules/cachix.nix, usr/modules/cachix.nix |
nixos-rebuild | system.activationScripts | modules/cachix.nix, sys/modules/cachix.nix |
nix-shell | shellHook | openc910/shell.nix |
Possible solutions:
+Add a wrapper called cachixPackages
, which recives the packages to be pushed and cachix information.
+This cachixPackages
is a dummy package whose build stages will push the packages to cachix.
+However, normal nix packages are not allowed network access during building.
+To tackle this, like how fetch* series functions are implemented, the fixed-output derivation can be utilized to allow network access.
However, the above method seems not work as below, +because cachix needs accesses to some resources beyond nix-build process (such as nix-build's sandbox).
+nix-build test.nix
+...
+cachix: CppStdException e "\ESC[31;1merror:\ESC[0m creating directory '\ESC[35;1m/nix/var\ESC[0m': \ESC[35;1mPermission denied\ESC[0m"(Just "nix::SysError")
+result 1
+...
+
+Even though I disable the nix-build sandbox by using --no-sandbox
,
+the cachix still does not satisfy as below.
$ nix-build test.nix --no-sandbox
+...
+cachix: CppStdException e "\ESC[31;1merror:\ESC[0m cannot open connection to remote store '\ESC[35;1mdaemon\ESC[0m': \ESC[35;1m\ESC[31;1merror:\ESC[0m reading from file: \ESC[35;1mConnection reset by peer\ESC[0m\ESC[0m"(Just "nix::Error")
+...
+
+If you curious about my demo of cachixPackages
and its test,
+see cachix-package.nix and test.nix.
To run the test:
+# run with nix-build sandbox
+nix-build test.nix
+# run without nix-build sandbox
+nix-build test.nix --no-sandbox
+
+let
+ pkgs = import <nixpkgs> {};
+ cachixPackage = import ./cachix-package.nix {inherit (pkgs) cachix stdenv writeShellScript;};
+in cachixPackage {
+ pkg = pkgs.hello;
+ sha256 = "01vm275n169r0ly8ywgq0shgk8lrzg79d1aarshwybwxwffj4q0q";
+ cachix_dhall = /home/xieby1/Gist/Config/cachix.dhall;
+ cachix_name = "xieby1";
+}
+
+
+ 官方binary cache没有的包, 自己花了很长时间编译出来。 +值得把编译出来的的包及其依赖全部保存下来。
+nix copy --to
nixpkgs原生支持x86和arm指令集。 +通过对nixpkgs配置可以轻松实现交叉编译, +跨平台程序的安装等功能。
+x86_64上的aarch64交叉编译器
+(with import <nixpkgs> {crossSystem="aarch64-linux";}; stdenv.cc)
aarch64的hello应用程序
+(with import <nixpkgs> {localSystem.system="aarch64-linux";crossSystem="aarch64-linux";}; hello)
应用于nix-shell的例子
+ +localSystem
和crossSystem
的语法
+
+localSystem
和crossSystem
的应用
+
+nixpkgs1众多输入参数中,包含localSystem
和crossSystem
2。
localSystem
++The system packages will be built on.
+
本地系统,即工具链运行的平台。
+crossSystem
++The system packages will ultimately be run on.
+
程序运行的平台。
+通过localSystem
和crossSystem
不同值的组合,
+可以实现交叉编译、安装其他架构的原生应用。
+下面从localSystem
和crossSystem
的语法和应用两方面进行介绍。
+语法章节从nixpkgs源码的角度出发,介绍其语法的组成。
+应用章节围绕一个nix-shell脚本的实际例子,
+介绍x86_64平台的交叉编译和安装aarch64架构的原生应用的方法。
localSystem
和crossSystem
的语法localSystem
和crossSystem
由4个维度去刻画一个系统:cpu, vendor, kernel, abi。
+localSystem
和crossSystem
的值为字符串或者{system=字符串;}
3。
+system字符串为可以包含前述4个维度的1~4个维度。
+nix在解析时会将省略的维度按以某些默认值补充完整。
+维度之间之间用-
分割。
+因此system字符串形式上为"cpu-vendor-kernel-abi"
。
+字符串不同数量的维度及其可用的值,
+按匹配优先级由高到低列举如下4,
system字符串 | cpu | vendor | kernel | abi |
---|---|---|---|---|
"avr" | avr | none | unknown | |
"{cpu}-cygwin" | {cpu} | windows | cygnus | |
"{cpu}-windows" | {cpu} | windows | msvc | |
"{cpu}-elf" | {cpu} | unknown | none | elf |
"{cpu}-{kernel}" | {cpu} | {kernel} | ||
"{cpu}-apple-{kernel}" | {cpu} | apple | {kernel} | |
"{cpu}-linux-gnu" | {cpu} | linux | gnu | |
"{cpu}-{vendor}-mingw32" | {cpu} | {vendor} | windows | |
"{cpu}-{vendor}-wasi" | {cpu} | {vendor} | wasi | |
"{cpu}-{vendor}-redox" | {cpu} | {vendor} | redox | |
"{cpu}-{vendor}-mmixware" | {cpu} | {vendor} | mmixware | |
"{cpu}-{vendor}-netbsd*" | {cpu} | {vendor} | netbsd* | |
"{cpu}-{vendor}-eabi" | {cpu} | unknown | {kernel} | eabi |
"{cpu}-{vendor}-eabihf" | {cpu} | unknown | {kernel} | eabihf |
"{cpu}-{kernel}-elf" | {cpu} | unknown | {kernel} | elf |
"{cpu}-*-{ghcjs}" | {cpu} | unknown | ghcjs | |
"{cpu}-{vendor}-genode" | {cpu} | {vendor} | genode | |
"{cpu}-{vendor}-{kernel}-{abi} " | {cpu} | {vendor} | {kernel} | {abi} |
cpu字符串可取的值列举如下5,
+cpu字符串 | bits | significantByte | family | version | arch |
---|---|---|---|---|---|
"arm" | 32 | littleEndian | "arm" | ||
"armv5tel" | 32 | littleEndian | "arm" | "5" | "armv5t" |
"armv6m" | 32 | littleEndian | "arm" | "6" | "armv6-m" |
"armv6l" | 32 | littleEndian | "arm" | "6" | "armv6" |
"armv7a" | 32 | littleEndian | "arm" | "7" | "armv7-a" |
"armv7r" | 32 | littleEndian | "arm" | "7" | "armv7-r" |
"armv7m" | 32 | littleEndian | "arm" | "7" | "armv7-m" |
"armv7l" | 32 | littleEndian | "arm" | "7" | "armv7" |
"armv8a" | 32 | littleEndian | "arm" | "8" | "armv8-a" |
"armv8r" | 32 | littleEndian | "arm" | "8" | "armv8-a" |
"armv8m" | 32 | littleEndian | "arm" | "8" | "armv8-m" |
"aarch64" | 64 | littleEndian | "arm" | "8" | "armv8-a" |
"aarch64_be" | 64 | bigEndian | "arm" | "8" | "armv8-a" |
"i386" | 32 | littleEndian | "x86" | "i386" | |
"i486" | 32 | littleEndian | "x86" | "i486" | |
"i586" | 32 | littleEndian | "x86" | "i586" | |
"i686" | 32 | littleEndian | "x86" | "i686" | |
"x86_64" | 64 | littleEndian | "x86" | "x86-64" | |
"mips" | 32 | bigEndian | "mips" | ||
"mipsel" | 32 | littleEndian | "mips" | ||
"mips64" | 64 | bigEndian | "mips" | ||
"mips64el" | 64 | littleEndian | "mips" | ||
"mmix" | 64 | bigEndian | "mmix" | ||
"m68k" | 32 | bigEndian | "m68k" | ||
"powerpc" | 32 | bigEndian | "power" | ||
"powerpc64" | 64 | bigEndian | "power" | ||
"powerpc64le" | 64 | littleEndian | "power" | ||
"powerpcle" | 32 | littleEndian | "power" | ||
"riscv32" | 32 | littleEndian | "riscv" | ||
"riscv64" | 64 | littleEndian | "riscv" | ||
"s390" | 32 | bigEndian | "s390" | ||
"s390x" | 64 | bigEndian | "s390" | ||
"sparc" | 32 | bigEndian | "sparc" | ||
"sparc64" | 64 | bigEndian | "sparc" | ||
"wasm32" | 32 | littleEndian | "wasm" | ||
"wasm64" | 64 | littleEndian | "wasm" | ||
"alpha" | 64 | littleEndian | "alpha" | ||
"msp430" | 16 | littleEndian | "msp430" | ||
"avr" | 8 | "avr" | |||
"vc4" | 32 | littleEndian | "vc4" | ||
"or1k" | 32 | bigEndian | "or1k" | ||
"js" | 32 | littleEndian | "js" |
cpu之间的兼容性(具有传递性和自反性)如下6,
+ +vendor字符串可取值"apple"
, "pc"
(windows), "w64"
(MinGW-w64), "none"
, "unknown"
(default)。
kernel字符串可取值如下表7,
+kernel字符串 | execFormat | families |
---|---|---|
"macos" | macho | darwin |
"darwin" | ↑ | ↑ |
"ios" | macho | darwin |
"watchos" | ↑ | ↑ |
"tvos" | ↑ | ↑ |
"freebsd" | elf | bsd |
"linux" | elf | |
"netbsd" | elf | bsd |
"none" | unknown | |
"openbsd" | elf | bsd |
"solaris" | elf | |
"wasi" | wasm | |
"redox" | elf | |
"windows" | pe | |
"win32" | ↑ | ↑ |
"ghcjs" | unknown | |
"genode" | elf | |
"mmixware" | unknown |
abi字符串可取的值列举如下8,
+abi字符串 | float | abi | Note |
---|---|---|---|
"cygnus" | |||
"msvc" | |||
"eabi" | soft | for ARM, PowerPC | |
"eabihf" | hard | for ARM, PowerPC | |
"elf" | |||
"androideabi" | |||
"android" | not 32-bit | ||
"gnueabi" | soft | ||
"gnueabihf" | hard | ||
"gnu" | not 32-bit | ||
"gnuabi64" | 64 | ||
"musleabi" | soft | ||
"musleabihf" | hard | ||
"musl" | |||
"uclibceabihf" | soft | ||
"uclibceabi" | hard | ||
"uclibc" | |||
"unknown" |
localSystem
和crossSystem
的应用以x86为本地指令集,localSystem
和crossSystem
的组合有以下效果
↓crossSystem ↓ →localSystem → | "x86_64-linux" | "aarch64-linux" |
---|---|---|
"x86_64-linux" | 通常情况 | |
"aarch64-linux" | 交叉编译aarch64 | 原生aarch64应用 |
因此基于这3种组合,可以在同一个shell环境中配置出3种软件, +代码见[cross_platform.nix]({{ site.repo_url }}/scripts/shell/cross_platform.nix)。
+pkgs_arm_cross
软件包的stdenv.cc
为x86平台的arm交叉编译器。
+nixpkgs channel只包含了原生x86应用和原生arm应用。
+交叉编译的arm应用和原生arm应用的derivation不一样。
+因此使用pkgs_arm_cross
中的应用,
+则会使用交叉编译器从源码开始编译arm应用,
+而不是直接拉取nixpkgs channel的原生arm应用。
pkgs_arm_native
软件包包含原生arm软件包。
+从这个软件包拉取的应用和在arm平台的拉取到的应用一致。
+例如figlet
将直接从nix channel中拉取。
pkgs
即x86原生的软件包。
shell_cross_platform.nix使用例子,
+# 创建一个新的shell环境,包含stdenv.cc, figlet, qemu
+$ nix-shell shell_cross_platform.nix
+
+# 使用交叉编译工具链的c编译器
+$ aarch64-unknown-linux-gnu-gcc helloworld.c -o helloworld
+$ file helloworld
+helloworld: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /nix/store/01kw0gb38phviarfv3fca49dpqh0qwlx-glibc-aarch64-unknown-linux-gnu-2.33-123/lib/ld-linux-aarch64.so.1, for GNU/Linux 2.6.32, with debug_info, not stripped
+
+# arm原生应用
+$ file `command -v figlet`
+/nix/store/4f70f04bvd664n00jlnzccyzxd35lykw-figlet-2.2.5/bin/figlet: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /nix/store/rjc27shzir243n1w3127w713fijamf6v-glibc-2.33-123/lib/ld-linux-aarch64.so.1, for GNU/Linux 2.6.32, not stripped
+
+# 直接执行figlet会出错
+$ figlet
+bash: /nix/store/4f70f04bvd664n00jlnzccyzxd35lykw-figlet-2.2.5/bin/figlet: cannot execute binary file: Exec format error
+
+# 使用QEMU执行figlet即可
+$ qemu-aarch64 `command -v figlet` miao!
+ _ _
+ _ __ ___ (_) __ _ ___ | |
+| '_ ` _ \| |/ _` |/ _ \| |
+| | | | | | | (_| | (_) |_|
+|_| |_| |_|_|\__,_|\___/(_)
+
+[cross_mips.nix]({{ site.repo_url }}/scripts/shell/cross_mips.nix)
+nixpkgs版本2022.01.20, commit hash: 7e149abe9db1509fa974bb2286f862a761ca0a07
+nixpkgs/pkgs/top-level/default.nix
+nixpkgs/lib/systems/default.nix: elaborate
nixpkgs/lib/systems/parse.nix: mkSkeletonFromList
nixpkgs/lib/systems/parse.nix: cpuTypes
nixpkgs/lib/systems/parse.nix: isCompatible
nixpkgs/lib/systems/parse.nix: kernels
nixpkgs/lib/systems/parse.nix: abis
安装过程采用官方安装文档。 +若已安装NixOS,则可跳过该步骤,直接看安装我的配置。
+QEMU:
+# 下载minimal ISO镜像:https://nixos.org/download.html
+# 创建qemu硬盘(大小32GB)
+qemu-img create -f qcow2 <output/path/to/nix.qcow2> 32G
+# 将ISO安装到qemu硬盘
+qemu-system-x86_64 -display gtk,window-close=off -vga virtio -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5556-:22,smb=/home/xieby1/ -m 4G -smp 3 -enable-kvm -hda </path/to/nix.qcow2> -cdrom </path/to/nixos-minial.iso> -boot d &
+
+物理机:
+# 暂时未探究命令行连接wifi的方法
+# 所以目前使用gnome版ISO,而非minimal ISO。
+# 下载gnome ISO镜像:https://nixos.org/download.html
+# 启动U盘制作
+sudo dd if=<path/to/nixos.iso> of=</dev/your_usb>
+sync
+# 重启进入U盘系统
+# 注:需要在BIOS中取消secure boot,否则U盘无法启动。
+
+进入ISO系统后,创建分区。 +一共需要3个分区:启动分区,操作系统分区,swap分区。 +QEMU和物理机单系统需要创建这3个分区。 +物理机双系统中启动分区已有,只需创建剩下2个分区。
+QEMU:
+sudo bash
+parted /dev/sda -- mklabel msdos
+parted /dev/sda -- mkpart primary 1MiB -8GiB
+parted /dev/sda -- mkpart primary linux-swap -8GiB 100%
+
+物理机单系统:
+parted /dev/sda -- mklabel gpt
+parted /dev/sda -- mkpart primary 512MiB -8GiB
+parted /dev/sda -- mkpart primary linux-swap -8GiB 100%
+parted /dev/sda -- mkpart ESP fat32 1MiB 512MiB
+parted /dev/sda -- set 3 esp on
+
+物理机双系统:
+还未探索parted详细用法,目前使用disk软件可视化分区。
+mkfs.ext4 -L nixos /dev/<系统分区>
+mkswap -L swap /dev/<swap分区>
+swapon /dev/<swap分区>
+mkfs.fat -F 32 -n boot /dev/<启动分区> # 物理机单系统
+mount /dev/disk/by-label/nixos /mnt
+mkdir -p /mnt/boot # 物理机单系统&双系统
+mount /dev/disk/by-label/boot /mnt/boot # 物理机单系统&双系统
+
+nixos-generate-config --root /mnt
+
+networking.hostName
networking.proxy.default = "http://user:password@proxy:port/";
networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
boot.loader.grub.device = "/dev/sda";
networking.firewall.enable = false;
boot.loader.grub.useOSProber = true;
users.users.xieby1
environment.systemPackages = with pkgs; [vim git];
最后
+nixos-install
+reboot
+
+重启之后,进入NixOS。
+ +注:左下角菜单里可切换全屏
+ + +