Next: , Previous: , Up: 贡献   [Contents][Index]


22.7 源码树结构

If you’re willing to contribute to Guix beyond packages, or if you’d like to learn how it all fits together, this section provides a guided tour in the code base that you may find useful.

Overall, the Guix source tree contains almost exclusively Guile modules, each of which can be seen as an independent library (see Modules in GNU Guile Reference Manual).

The following table gives an overview of the main directories and what they contain. Remember that in Guile, each module name is derived from its file name—e.g., the module in file guix/packages.scm is called (guix packages).

guix

This is the location of core Guix mechanisms. To illustrate what is meant by “core”, here are a few examples, starting from low-level tools and going towards higher-level tools:

(guix store)

Connecting to and interacting with the build daemon (see 仓库).

(guix derivations)

Creating derivations (see Derivations).

(guix gexps)

Writing G-expressions (see G-表达式).

(guix packages)

Defining packages and origins (see package Reference).

(guix download)
(guix git-download)

The url-fetch and git-fetch origin download methods (see origin Reference).

(guix swh)

Fetching source code from the Software Heritage archive.

(guix search-paths)

Implementing search paths (see Search Paths).

(guix build-system)

The build system interface (see 构建系统).

(guix profiles)

Implementing profiles.

guix/build-system

This directory contains specific build system implementations (see 构建系统), such as:

(guix build-system gnu)

the GNU build system;

(guix build-system cmake)

the CMake build system;

(guix build-system pyproject)

The Python “pyproject” build system.

guix/build

This contains code generally used on the “build side” (see strata of code). This includes code used to build packages or other operating system components, as well as utilities:

(guix build utils)

Utilities for package definitions and more (see Build Utilities).

(guix build gnu-build-system)
(guix build cmake-build-system)
(guix build pyproject-build-system)

Implementation of build systems, and in particular definition of their build phases (see Build Phases).

(guix build syscalls)

Interface to the C library and to Linux system calls.

guix/scripts

这包括了相应于 guix 子命令的模块。例如,(guix scripts shell) 模块导出了 guix-shell 过程,这直接对应于 guix shell 命令(see 调用guix shell)。

guix/import

这包含了对于导入器和升级器的支持代码(see Invoking guix import,以及 see Invoking guix refresh)。例如,(guix import pypi) 定义了 PyPI 的接口,这由 guix import pypi 命令使用。

The directories we have seen so far all live under guix/. The other important place is the gnu/ directory, which contains primarily package definitions as well as libraries and tools for Guix System (see 系统配置) and Guix Home (see Home Configuration), all of which build upon functionality provided by (guix …) modules46.

gnu/packages

This is by far the most crowded directory of the source tree: it contains package modules that export package definitions (see 软件包模块). A few examples:

(gnu packages base)

Module providing “base” packages: glibc, coreutils, grep, etc.

(gnu packages guile)

Guile and core Guile packages.

(gnu packages linux)

The Linux-libre kernel and related packages.

(gnu packages python)

Python and core Python packages.

(gnu packages python-xyz)

Miscellaneous Python packages (we were not very creative).

In any case, you can jump to a package definition using guix edit (see Invoking guix edit) and view its location with guix show (see Invoking guix package).

gnu/packages/patches

This directory contains patches applied against packages and obtained using the search-patches procedure.

gnu/services

This contains service definitions, primarily for Guix System (see 服务) but some of them are adapted and reused for Guix Home as we will see below. Examples:

(gnu services)

The service framework itself, which defines the service and service type data types (see 合成服务).

(gnu services base)

“Base” services (see 基础服务).

(gnu services desktop)

“Desktop” services (see 桌面服务).

(gnu services shepherd)

Support for Shepherd services (see Shepherd服务).

You can jump to a service definition using guix system edit and view its location with guix system search (see 调用guix system).

gnu/system

These are core Guix System modules, such as:

(gnu system)

Defines operating-system (see operating-system Reference).

(gnu system file-systems)

Defines file-system (see 文件系统).

(gnu system mapped-devices)

Defines mapped-device (see 映射的设备).

gnu/build

These are modules that are either used on the “build side” when building operating systems or packages, or at run time by operating systems.

(gnu build accounts)

Creating /etc/passwd, /etc/shadow, etc. (see 用户帐号).

(gnu build activation)

Activating an operating system at boot time or reconfiguration time.

(gnu build file-systems)

Searching, checking, and mounting file systems.

(gnu build linux-boot)
(gnu build hurd-boot)

Booting GNU/Linux and GNU/Hurd operating systems.

(gnu build linux-initrd)

Creating a Linux initial RAM disk (see 初始的内存虚拟硬盘).

gnu/home

This contains all things Guix Home (see Home Configuration); examples:

(gnu home services)

Core services such as home-files-service-type.

(gnu home services ssh)

SSH-related services (see Secure Shell).

gnu/installer

This contains the text-mode graphical system installer (see 指导的图形安装).

gnu/machine

These are the machine abstractions used by guix deploy (see 调用guix deploy).

gnu/tests

This contains system tests—tests that spawn virtual machines to check that system services work as expected (see 运行测试套件).

Last, there’s also a few directories that contain files that are not Guile modules:

nix

This is the C++ implementation of guix-daemon, inherited from Nix (see 调用guix-daemon).

tests

These are unit tests, each file corresponding more or less to one module, in particular (guix …) modules (see 运行测试套件).

doc

This is the documentation in the form of Texinfo files: this manual and the Cookbook. See Writing a Texinfo File in GNU Texinfo, for information on Texinfo markup language.

po

This is the location of translations of Guix itself, of package synopses and descriptions, of the manual, and of the cookbook. Note that .po files that live here are pulled directly from Weblate (see 翻译 Guix).

etc

Miscellaneous files: shell completions, support for systemd and other init systems, Git hooks, etc.

With all this, a fair chunk of your operating system is at your fingertips! Beyond grep and git grep, see 完美的配置 on how to navigate code from your editor, and see 交互式使用 Guix for information on how to use Scheme modules interactively. Enjoy!


Footnotes

(46)

For this reason, (guix …) modules must generally not depend on (gnu …) modules, with notable exceptions: (guix build-system …) modules may look up packages at run time—e.g., (guix build-system cmake) needs to access the cmake variable at run time—, (guix scripts …) often rely on (gnu …) modules, and the same goes for some of the (guix import …) modules.


Next: 打包指导, Previous: 替代配置, Up: 贡献   [Contents][Index]