feat: update links & refactor ./docs/.vitepress/config.ts

This commit is contained in:
Ryan Yin 2023-07-08 02:28:06 +08:00
parent ae087d3c57
commit 966ff53c95
5 changed files with 388 additions and 378 deletions

View file

@ -1,45 +1,6 @@
import { generateSitemap as sitemap } from "sitemap-ts";
import { PageData, defineConfig } from "vitepress";
function getJSONLD(pageData: PageData) {
if (pageData.relativePath === "index.md") {
return `{
"@context":"http://schema.org",
"@type":"WebSite",
"url":"https:\/\/nixos-and-flakes.thiscute.world\/",
"inLanguage":"en",
"description":"An unofficial and opinionated book for beginners",
"name":"${pageData.title}"
}`;
} else if (pageData.relativePath === "zh/index.md") {
return `{
"@context":"http://schema.org",
"@type":"WebSite",
"url":"https:\/\/nixos-and-flakes.thiscute.world\/zh\/",
"inLanguage":"zh-CN",
"description":"一份非官方的新手指南",
"name":"${pageData.title}"
}`;
} else {
let lang = pageData.relativePath.startsWith("zh/") ? "zh-CN" : "en";
let url = `https:\/\/nixos-and-flakes.thiscute.world\/${pageData.relativePath
.replace(/\.md$/, "")
.replace(/\/index\$/, "/")}`;
return `{
"@context":"http://schema.org",
"@type":"TechArticle",
"headline":"${pageData.title} | NixOS & Flakes Book",
"inLanguage":"${lang}",
"mainEntityOfPage":{
"@type":"WebPage",
"@id":"${url}"
},
"keywords":"NixOS, Nix, Flakes, Linux, Tutorial",
"url":"${url}"
}`;
}
}
// https://vitepress.dev/reference/site-config
export default defineConfig({
// remove trailing `.html`
@ -88,339 +49,388 @@ export default defineConfig({
},
locales: {
root: {
label: "English",
lang: "en",
link: "/",
title: "NixOS & Flakes Book",
description: "An unofficial and opinionated book for beginners",
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: "Home", link: "/" },
{ text: "Get Started", link: "/introduction/index.md" },
{ text: "Best Practices", link: "/best-practices/intro.md" },
],
sidebar: [
{
text: "Get Started",
items: [
{ text: "Introduction", link: "/introduction/index.md" },
{
text: "Advantages and Disadvantages",
link: "/introduction/advantages-and-disadvantages.md",
},
{
text: "Installation",
link: "/introduction/installation.md",
},
],
},
{
text: "The Nix Language",
items: [{ text: "Basics", link: "/the-nix-language/index.md" }],
},
{
text: "NixOS with Flakes",
items: [
{
text: "Get Started with NixOS",
link: "/nixos-with-flakes/get-started-with-nixos.md",
},
{
text: "Introduction to Flakes",
link: "/nixos-with-flakes/introduction-to-flakes.md",
},
{
text: "NixOS with Flakes Enabled",
link: "/nixos-with-flakes/nixos-with-flakes-enabled.md",
},
{
text: "Getting Started with Home Manager",
link: "/nixos-with-flakes/start-using-home-manager.md",
},
{
text: "Modularize the Configuration",
link: "/nixos-with-flakes/modularize-the-configuration.md",
},
{
text: "Updating the System",
link: "/nixos-with-flakes/update-the-system.md",
},
{
text: "Downgrading or Upgrading Packages",
link: "/nixos-with-flakes/downgrade-or-upgrade-packages.md",
},
{
text: "Other useful Tips",
link: "/nixos-with-flakes/other-useful-tips.md",
},
],
},
{
text: "Nixpkgs's Advanced Usage",
items: [
{ text: "Introduction", link: "/nixpkgs/intro.md" },
{ text: "callPackage", link: "/nixpkgs/callpackage.md" },
{ text: "Overridding", link: "/nixpkgs/overriding.md" },
{ text: "Overlays", link: "/nixpkgs/overlays.md" },
],
},
{
text: "Best Practices",
items: [
{ text: "Introduction", link: "/best-practices/intro.md" },
{
text: "Run downloaded binaries on NixOS",
link: "/best-practices/run-downloaded-binaries-on-nixos.md",
},
{
text: "Simplify NixOS-related Commands",
link: "/best-practices/simplify-nixos-related-commands.md",
},
{
text: "Debug with nix repl",
link: "/best-practices/debug-with-nix-repl.md",
},
],
},
{
text: "Other Usage of Flakes",
items: [
{ text: "Introduction", link: "/other-usage-of-flakes/intro.md" },
{
text: "Flake Inputs",
link: "/other-usage-of-flakes/inputs.md",
},
{
text: "Flake Outputs",
link: "/other-usage-of-flakes/outputs.md",
},
{
text: "The New CLI",
link: "/other-usage-of-flakes/the-new-cli.md",
},
{
text: "Nix option difinitions",
link: "/zh/other-usage-of-flakes/options.md",
},
],
},
{
text: "Dev Environments on NixOS",
items: [
{ text: "Introduction", link: "/development/intro.md" },
{
text: "Dev Environments",
link: "/development/dev-environments.md",
},
{
text: "Packaging 101",
link: "/development/packaging-101.md",
},
{
text: "Cross-platform Compilation",
link: "/development/cross-platform-compilation.md",
},
{
text: "Distribution Building",
link: "/development/distributed-building.md",
},
{
text: "Kernel Development",
link: "/development/kernel-development.md",
},
],
},
{
text: "Advanced Topics",
items: [{ text: "Links", link: "/advanced-topics/index.md" }],
},
{
text: "FAQ",
items: [{ text: "FAQ", link: "/faq/index.md" }],
},
],
socialLinks: [
{
icon: "github",
link: "https://github.com/ryan4yin/nixos-and-flakes-book",
},
],
},
},
zh: {
label: "简体中文",
lang: "zh-CN",
link: "/zh/",
title: "NixOS 与 Flakes",
description: "一份非官方的新手指南",
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: "首页", link: "/zh/" },
{ text: "开始使用", link: "/zh/introduction/index.md" },
{ text: "最佳实践", link: "/zh/best-practices/intro.md" },
],
sidebar: [
{
text: "开始使用",
items: [
{ text: "简介", link: "/zh/introduction/index.md" },
{
text: "优缺点",
link: "/zh/introduction/advantages-and-disadvantages.md",
},
{
text: "安装",
link: "/zh/introduction/installation.md",
},
],
},
{
text: "Nix 语言",
items: [
{ text: "快速入门", link: "/zh/the-nix-language/index.md" },
],
},
{
text: "NixOS 与 Flakes",
items: [
{
text: "开始使用 NixOS",
link: "/zh/nixos-with-flakes/get-started-with-nixos.md",
},
{
text: "Flakes 简介",
link: "/zh/nixos-with-flakes/introduction-to-flakes.md",
},
{
text: "使用 Flakes 管理 NixOS",
link: "/zh/nixos-with-flakes/nixos-with-flakes-enabled.md",
},
{
text: "安装使用 Home Manager",
link: "/zh/nixos-with-flakes/start-using-home-manager.md",
},
{
text: "模块化系统配置",
link: "/zh/nixos-with-flakes/modularize-the-configuration.md",
},
{
text: "更新系统",
link: "/zh/nixos-with-flakes/update-the-system.md",
},
{
text: "降级或升级软件包",
link: "/zh/nixos-with-flakes/downgrade-or-upgrade-packages.md",
},
{
text: "其他杂七杂八的内容",
link: "/zh/nixos-with-flakes/other-useful-tips.md",
},
],
},
{
text: "Nixpkgs 高级用法",
items: [
{ text: "简介", link: "/zh/nixpkgs/intro.md" },
{ text: "callPackage", link: "/zh/nixpkgs/callpackage.md" },
{ text: "Overridding", link: "/zh/nixpkgs/overriding.md" },
{ text: "Overlays", link: "/zh/nixpkgs/overlays.md" },
],
},
{
text: "NixOS 最佳实践",
items: [
{ text: "简介", link: "/zh/best-practices/intro.md" },
{
text: "运行非 NixOS 的二进制文件",
link: "/zh/best-practices/run-downloaded-binaries-on-nixos.md",
},
{
text: "使用 Makefile 简化常用命令",
link: "/zh/best-practices/simplify-nixos-related-commands.md",
},
{
text: "使用 nix repl 查看源码、调试配置",
link: "/zh/best-practices/debug-with-nix-repl.md",
},
],
},
{
text: "Flakes 的其他玩法",
items: [
{ text: "简介", link: "/zh/other-usage-of-flakes/intro.md" },
{
text: "Flake Inputs",
link: "/zh/other-usage-of-flakes/inputs.md",
},
{
text: "Flake Outputs",
link: "/zh/other-usage-of-flakes/outputs.md",
},
{
text: "The New CLI",
link: "/zh/other-usage-of-flakes/the-new-cli.md",
},
{
text: "Nix option difinitions",
link: "/zh/other-usage-of-flakes/options.md",
},
],
},
{
text: "在 NixOS 上进行开发工作",
items: [
{ text: "简介", link: "/zh/development/intro.md" },
{
text: "各语言的开发环境",
link: "/zh/development/dev-environments.md",
},
{
text: "软件打包",
link: "/zh/development/packaging-101.md",
},
{
text: "跨平台编译",
link: "/zh/development/cross-platform-compilation.md",
},
{
text: "分布式构建",
link: "/zh/development/distributed-building.md",
},
{
text: "内核开发",
link: "/zh/development/kernel-development.md",
},
],
},
{
text: "其他进阶话题",
items: [
{ text: "其他进阶话题", link: "/zh/advanced-topics/index.md" },
],
},
{
text: "常见问题 FAQ",
items: [{ text: "常见问题 FAQ", link: "/zh/faq/index.md" }],
},
],
socialLinks: [
{
icon: "github",
link: "https://github.com/ryan4yin/nixos-and-flakes-book",
},
],
},
},
root: themeConfigEnglish(),
zh: themeConfigChinese(),
},
});
function themeConfigEnglish() {
return {
label: "English",
lang: "en",
link: "/",
title: "NixOS & Flakes Book",
description: "An unofficial and opinionated book for beginners",
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: "Home", link: "/" },
{ text: "Get Started", link: "/introduction/index.md" },
{ text: "Best Practices", link: "/best-practices/intro.md" },
],
sidebar: [
{
text: "Get Started",
items: [
{ text: "Introduction", link: "/introduction/index.md" },
{
text: "Advantages and Disadvantages",
link: "/introduction/advantages-and-disadvantages.md",
},
{
text: "Installation",
link: "/introduction/installation.md",
},
],
},
{
text: "The Nix Language",
items: [{ text: "Basics", link: "/the-nix-language/index.md" }],
},
{
text: "NixOS with Flakes",
items: [
{
text: "Get Started with NixOS",
link: "/nixos-with-flakes/get-started-with-nixos.md",
},
{
text: "Introduction to Flakes",
link: "/nixos-with-flakes/introduction-to-flakes.md",
},
{
text: "NixOS with Flakes Enabled",
link: "/nixos-with-flakes/nixos-with-flakes-enabled.md",
},
{
text: "Getting Started with Home Manager",
link: "/nixos-with-flakes/start-using-home-manager.md",
},
{
text: "Modularize the Configuration",
link: "/nixos-with-flakes/modularize-the-configuration.md",
},
{
text: "Updating the System",
link: "/nixos-with-flakes/update-the-system.md",
},
{
text: "Downgrading or Upgrading Packages",
link: "/nixos-with-flakes/downgrade-or-upgrade-packages.md",
},
{
text: "Other useful Tips",
link: "/nixos-with-flakes/other-useful-tips.md",
},
],
},
{
text: "Nixpkgs's Advanced Usage",
items: [
{ text: "Introduction", link: "/nixpkgs/intro.md" },
{ text: "callPackage", link: "/nixpkgs/callpackage.md" },
{ text: "Overridding", link: "/nixpkgs/overriding.md" },
{ text: "Overlays", link: "/nixpkgs/overlays.md" },
],
},
{
text: "Best Practices",
items: [
{ text: "Introduction", link: "/best-practices/intro.md" },
{
text: "Run downloaded binaries on NixOS",
link: "/best-practices/run-downloaded-binaries-on-nixos.md",
},
{
text: "Simplify NixOS-related Commands",
link: "/best-practices/simplify-nixos-related-commands.md",
},
{
text: "Debug with nix repl",
link: "/best-practices/debug-with-nix-repl.md",
},
],
},
{
text: "Other Usage of Flakes",
items: [
{ text: "Introduction", link: "/other-usage-of-flakes/intro.md" },
{
text: "Flake Inputs",
link: "/other-usage-of-flakes/inputs.md",
},
{
text: "Flake Outputs",
link: "/other-usage-of-flakes/outputs.md",
},
{
text: "The New CLI",
link: "/other-usage-of-flakes/the-new-cli.md",
},
{
text: "Nix Options",
link: "/zh/other-usage-of-flakes/options.md",
},
],
},
{
text: "Dev Environments on NixOS",
items: [
{ text: "Introduction", link: "/development/intro.md" },
{
text: "Dev Environments",
link: "/development/dev-environments.md",
},
{
text: "Packaging 101",
link: "/development/packaging-101.md",
},
{
text: "Cross-platform Compilation",
link: "/development/cross-platform-compilation.md",
},
{
text: "Distribution Building",
link: "/development/distributed-building.md",
},
{
text: "Kernel Development",
link: "/development/kernel-development.md",
},
],
},
{
text: "Advanced Topics",
items: [
{ text: "Advanced Topics", link: "/advanced-topics/index.md" },
],
},
{
text: "Frequently Asked Questions",
items: [
{ text: "Frequently Asked Questions", link: "/faq/index.md" },
],
},
],
socialLinks: [
{
icon: "github",
link: "https://github.com/ryan4yin/nixos-and-flakes-book",
},
],
},
};
}
function themeConfigChinese() {
return {
label: "简体中文",
lang: "zh-CN",
link: "/zh/",
title: "NixOS 与 Flakes",
description: "一份非官方的新手指南",
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: "首页", link: "/zh/" },
{ text: "开始使用", link: "/zh/introduction/index.md" },
{ text: "最佳实践", link: "/zh/best-practices/intro.md" },
],
sidebar: [
{
text: "开始使用",
items: [
{ text: "简介", link: "/zh/introduction/index.md" },
{
text: "优缺点",
link: "/zh/introduction/advantages-and-disadvantages.md",
},
{
text: "安装",
link: "/zh/introduction/installation.md",
},
],
},
{
text: "Nix 语言",
items: [{ text: "快速入门", link: "/zh/the-nix-language/index.md" }],
},
{
text: "NixOS 与 Flakes",
items: [
{
text: "开始使用 NixOS",
link: "/zh/nixos-with-flakes/get-started-with-nixos.md",
},
{
text: "Flakes 简介",
link: "/zh/nixos-with-flakes/introduction-to-flakes.md",
},
{
text: "使用 Flakes 管理 NixOS",
link: "/zh/nixos-with-flakes/nixos-with-flakes-enabled.md",
},
{
text: "安装使用 Home Manager",
link: "/zh/nixos-with-flakes/start-using-home-manager.md",
},
{
text: "模块化系统配置",
link: "/zh/nixos-with-flakes/modularize-the-configuration.md",
},
{
text: "更新系统",
link: "/zh/nixos-with-flakes/update-the-system.md",
},
{
text: "降级或升级软件包",
link: "/zh/nixos-with-flakes/downgrade-or-upgrade-packages.md",
},
{
text: "其他杂七杂八的内容",
link: "/zh/nixos-with-flakes/other-useful-tips.md",
},
],
},
{
text: "Nixpkgs 高级用法",
items: [
{ text: "简介", link: "/zh/nixpkgs/intro.md" },
{ text: "callPackage", link: "/zh/nixpkgs/callpackage.md" },
{ text: "Overridding", link: "/zh/nixpkgs/overriding.md" },
{ text: "Overlays", link: "/zh/nixpkgs/overlays.md" },
],
},
{
text: "NixOS 最佳实践",
items: [
{ text: "简介", link: "/zh/best-practices/intro.md" },
{
text: "运行非 NixOS 的二进制文件",
link: "/zh/best-practices/run-downloaded-binaries-on-nixos.md",
},
{
text: "使用 Makefile 简化常用命令",
link: "/zh/best-practices/simplify-nixos-related-commands.md",
},
{
text: "使用 nix repl 查看源码、调试配置",
link: "/zh/best-practices/debug-with-nix-repl.md",
},
],
},
{
text: "Flakes 的其他玩法",
items: [
{ text: "简介", link: "/zh/other-usage-of-flakes/intro.md" },
{
text: "Flake Inputs",
link: "/zh/other-usage-of-flakes/inputs.md",
},
{
text: "Flake Outputs",
link: "/zh/other-usage-of-flakes/outputs.md",
},
{
text: "新一代 Nix 命令行工具的使用",
link: "/zh/other-usage-of-flakes/the-new-cli.md",
},
{
text: "Nix Options",
link: "/zh/other-usage-of-flakes/options.md",
},
],
},
{
text: "在 NixOS 上进行开发工作",
items: [
{ text: "简介", link: "/zh/development/intro.md" },
{
text: "各语言的开发环境",
link: "/zh/development/dev-environments.md",
},
{
text: "软件打包",
link: "/zh/development/packaging-101.md",
},
{
text: "跨平台编译",
link: "/zh/development/cross-platform-compilation.md",
},
{
text: "分布式构建",
link: "/zh/development/distributed-building.md",
},
{
text: "内核开发",
link: "/zh/development/kernel-development.md",
},
],
},
{
text: "其他进阶话题",
items: [
{ text: "其他进阶话题", link: "/zh/advanced-topics/index.md" },
],
},
{
text: "常见问题 FAQ",
items: [{ text: "常见问题 FAQ", link: "/zh/faq/index.md" }],
},
],
socialLinks: [
{
icon: "github",
link: "https://github.com/ryan4yin/nixos-and-flakes-book",
},
],
},
};
}
function getJSONLD(pageData: PageData) {
if (pageData.relativePath === "index.md") {
return `{
"@context":"http://schema.org",
"@type":"WebSite",
"url":"https:\/\/nixos-and-flakes.thiscute.world\/",
"inLanguage":"en",
"description":"An unofficial and opinionated book for beginners",
"name":"${pageData.title}"
}`;
} else if (pageData.relativePath === "zh/index.md") {
return `{
"@context":"http://schema.org",
"@type":"WebSite",
"url":"https:\/\/nixos-and-flakes.thiscute.world\/zh\/",
"inLanguage":"zh-CN",
"description":"一份非官方的新手指南",
"name":"${pageData.title}"
}`;
} else {
let lang = pageData.relativePath.startsWith("zh/") ? "zh-CN" : "en";
let url = `https:\/\/nixos-and-flakes.thiscute.world\/${pageData.relativePath
.replace(/\.md$/, "")
.replace(/\/index\$/, "/")}`;
return `{
"@context":"http://schema.org",
"@type":"TechArticle",
"headline":"${pageData.title} | NixOS & Flakes Book",
"inLanguage":"${lang}",
"mainEntityOfPage":{
"@type":"WebPage",
"@id":"${url}"
},
"keywords":"NixOS, Nix, Flakes, Linux, Tutorial",
"url":"${url}"
}`;
}
}

View file

@ -37,4 +37,4 @@ Overall, I believe that NixOS is suitable for developers with a certain level of
I do not recommend newcomers without any Linux usage experience to dive directly into NixOS, as it may lead to a frustrating journey.
> If you have more questions about NixOS, you can refer to the last chapter of this book, "FAQ".
> If you have more questions about NixOS, you can refer to the last chapter of this book, [FAQ](../faq/).

View file

@ -24,7 +24,7 @@ The following are classic Nix commands and associated concepts that are no longe
1. It installs packages from the data sources added by `nix-channel`, causing the installed package's version to be influenced by the channel. Packages installed with `nix-env` are not automatically recorded in Nix's declarative configuration and are completely independent of its control, making them challenging to reproduce on other machines. Therefore, it is not recommended to use this tool.
2. The corresponding command in Flakes is `nix profile`, which is also not recommended for use.
3. `nix-shell`: `nix-shell` creates a temporary shell environment, which is useful for development and testing.
1. In Flakes, this tool is divided into three sub-commands: `nix develop`, `nix shell`, and `nix run`. We will discuss these three commands in detail in the "Development" chapter.
1. In Flakes, this tool is divided into three sub-commands: `nix develop`, `nix shell`, and `nix run`. We will discuss these three commands in detail in the "[Development](../development/intro.md)" chapter.
4. `nix-build`: `nix-build` builds Nix packages and places the build results in `/nix/store`, but it does not record them in Nix's declarative configuration.
1. In Flakes, `nix-build` is replaced by `nix build`.
5. ...
@ -40,4 +40,4 @@ I delved into some details regarding Flakes:
- [Flakes Are Such an Obviously Good Thing - Graham Christensen](https://grahamc.com/blog/flakes-are-an-obviously-good-thing/): An article emphasizing the advantages of Flakes while suggesting areas for improvement in its design and development process.
- [Draft: 1-year Roadmap - NixOS Foundation](https://nixos-foundation.notion.site/1-year-roadmap-0dc5c2ec265a477ea65c549cd5e568a9): A roadmap provided by the NixOS Foundation, which includes plans regarding the stabilization of Flakes.
After reviewing these resources, it seems likely that Flakes will be stabilized within one or two years, possibly accompanied by some breaking changes[^1][^2][^3].
After reviewing these resources, it seems likely that Flakes will be stabilized within one or two years, possibly accompanied by some breaking changes[^1][^2][^3].

View file

@ -36,4 +36,4 @@
我不推荐没有任何 Linux 使用经验的新人直接上手 NixOS那可能会是一段糟糕的旅程。
> 如果你对 NixOS 还有疑问,可以看看本书的最后一章「常见问题」。
> 如果你对 NixOS 还有疑问,可以看看本书的最后一章「[常见问题](../faq/)」。

View file

@ -28,7 +28,7 @@ Nix 于 2020 年推出了 `nix-command` & `flakes` 两个新特性,它们提
1. 通过 `nix-env` 安装的包不会被自动记录到 Nix 的声明式配置中,是完全脱离掌控的,无法在其他主机上复现,因此不推荐使用。
2. 在 Nix Flakes 中对应的命令为 `nix profile`,此命令也同样不推荐使用。
3. `nix-shell`: nix-shell 用于创建一个临时的 shell 环境
1. 这玩意儿可能有点复杂了,因此在 Nix Flakes 中它被拆分成了三个子命令 `nix develop`, `nix shell` 以及 `nix run`,我们会在「构建开发环境」一章详细介绍这三个命令。
1. 这玩意儿可能有点复杂了,因此在 Nix Flakes 中它被拆分成了三个子命令 `nix develop`, `nix shell` 以及 `nix run`,我们会在「[构建开发环境](../development/intro.md)」一章详细介绍这三个命令。
4. `nix-build`: 用于构建 Nix 包,它会将构建结果放到 `/nix/store` 路径下,但是不会记录到 Nix 的声明式配置中。
1. 在 Nix Flakes 中对应的命令为 `nix build`
5. ...