mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-05-28 18:39:31 +02:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e549fb733 | |||
| c56db98288 | |||
| 720ef0d9ca | |||
| 796cdcd928 | |||
| 126c31d73b |
@@ -1,471 +0,0 @@
|
|||||||
# How to Learn Nix & Flake?
|
|
||||||
|
|
||||||
Nix Flake is a new feature in Nix, it's the unit for packaging Nix code in a reproducible and discoverable way.
|
|
||||||
They can have dependencies on other flakes, making it possible to have multi-repository Nix projects.
|
|
||||||
|
|
||||||
A flake is a filesystem tree (typically fetched from a Git repository or a tarball) that contains a file named flake.nix in the
|
|
||||||
root directory. flake.nix specifies some metadata about the flake such as dependencies (called inputs), as well as its outputs
|
|
||||||
(the Nix values such as packages or NixOS modules provided by the flake).
|
|
||||||
|
|
||||||
Nix Flake is an experimental feature till now (2023-04-23), but it's already very useful and being used by many people.
|
|
||||||
|
|
||||||
>Because `nix-command` & `flake` are still experimental, many document about nix are stll using old commands such as `nix-env`, `nix-channel` & `nix-shell`, but they are not very reproducible compared with `nix-command` & `flake`, So please forget those old commands, and start with the [New Nix Commands][New Nix Commands] for Nix Flake.
|
|
||||||
|
|
||||||
## 一、Nix Flake's Command Line
|
|
||||||
|
|
||||||
after enabled `nix-command` & `flake`, you can use `nix help` to get all the info of [New Nix Commands][New Nix Commands], the main commands include:
|
|
||||||
|
|
||||||
- `nix build` - build a derivation or fetch a store path, generate a result symlink in the current directory
|
|
||||||
- `nix develop` - run a bash shell that provides the build environment of a derivation
|
|
||||||
- `nix flake` - provides subcommands for creating, modifying and querying Nix flakes.
|
|
||||||
- `nix flake archive` - copy a flake and all its inputs to a store
|
|
||||||
- `nix flake check` - check whether the flake evaluates and run its tests
|
|
||||||
- `nix flake clone` - clone flake repository
|
|
||||||
- `nix flake info` - show flake metadata
|
|
||||||
- `nix flake init` - create a flake in the current directory from a template
|
|
||||||
- `nix flake lock` - create missing lock file entries
|
|
||||||
- `nix flake metadata` - show flake metadata
|
|
||||||
- `nix flake new` - create a flake in the specified directory from a template
|
|
||||||
- `nix flake prefetch` - download the source tree denoted by a flake reference into the Nix store
|
|
||||||
- `nix flake show` - show the outputs provided by a flake
|
|
||||||
- `nix flake update` - update flake lock file
|
|
||||||
- `nix profile` - manage Nix profiles. nix profile allows you to create and manage Nix profiles. A Nix profile is a set of packages that can be installed and upgraded independently from each other. Nix profiles are versioned, allowing them to be rolled back easily. its a replacement of `nix-env`.
|
|
||||||
- `nix profile diff-closures` - show the closure difference between each version of a profile
|
|
||||||
- `nix profile history` - show all versions of a profile
|
|
||||||
- `nix profile install` - install a package into a profile
|
|
||||||
- `nix profile list` - list installed packages
|
|
||||||
- `nix profile remove` - remove packages from a profile
|
|
||||||
- `nix profile rollback` - roll back to the previous version or a specified version of a profile
|
|
||||||
- `nix profile upgrade` - upgrade packages using their most recent flake
|
|
||||||
- `nix profile wipe-history` - delete non-current versions of a profile
|
|
||||||
- `nix repl` - start an interactive environment for evaluating Nix expressions
|
|
||||||
- `nix run` - run a Nix application. (use `nix run --help` for detail explanation)
|
|
||||||
- `nix search` - search for packages, maybe your woulde prefer the website <https://search.nixos.org> instead of this command.
|
|
||||||
- `nix shell` - run a shell in which the specified packages are available
|
|
||||||
|
|
||||||
[Zero to Nix - Determinate Systems][Zero to Nix - Determinate Systems] is a brand new guide to get started with Nix & Flake, recommended to read for beginners.
|
|
||||||
|
|
||||||
### Flake outpus
|
|
||||||
|
|
||||||
Flake outputs are what a flake produces as part of its build. Each flake can have many different outputs simultaneously, including but not limited to:
|
|
||||||
|
|
||||||
- Nix packages: named `apps.<system>.<name>`, `packages.<system>.<name>`, or `legacyPackages.<system>.<name>`
|
|
||||||
- Nix Helper Functions: named `lib`, which means a library for other flakes.
|
|
||||||
- Nix development environments: named `devShell`
|
|
||||||
- NixOS configurations: has many different outputs
|
|
||||||
- Nix templates: named `templates`
|
|
||||||
- templates can be used by command `nix flake init --template <reference>`
|
|
||||||
|
|
||||||
### Flake Command Examples
|
|
||||||
|
|
||||||
examples:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# `nixpkgs#ponysay` means `ponysay` from `nixpkgs` flake.
|
|
||||||
# [nixpkgs](https://github.com/NixOS/nixpkgs) contains `flake.nix` file, so it's a flake.
|
|
||||||
# `nixpkgs` is a falkeregistry id for `github:NixOS/nixpkgs/nixos-unstable`.
|
|
||||||
# you can find all the falkeregistry ids at <https://github.com/NixOS/flake-registry/blob/master/flake-registry.json>
|
|
||||||
# so this command means install and run package `ponysay` in `nixpkgs` flake.
|
|
||||||
echo "Hello Nix" | nix run "nixpkgs#ponysay"
|
|
||||||
|
|
||||||
# this command is the same as above, but use a full flake URI instead of falkeregistry id.
|
|
||||||
echo "Hello Nix" | nix run "github:NixOS/nixpkgs/nixos-unstable#ponysay"
|
|
||||||
|
|
||||||
# instead of treat flake package as an application,
|
|
||||||
# this command use the example package in zero-to-nix flake to setup the development environment,
|
|
||||||
# and then open a bash shell in that environment.
|
|
||||||
nix develop "github:DeterminateSystems/zero-to-nix#example"
|
|
||||||
|
|
||||||
# instead of using a remote flake, you can open a bash shell using the flake located in the current directory.
|
|
||||||
mkdir my-flake && cd my-flake
|
|
||||||
## init a flake with template
|
|
||||||
nix flake init --template "github:DeterminateSystems/zero-to-nix#javascript-dev"
|
|
||||||
# open a bash shell using the flake in current directory
|
|
||||||
nix develop
|
|
||||||
# or if your flake has multiple devShell outputs, you can specify which one to use.
|
|
||||||
nix develop .#example
|
|
||||||
|
|
||||||
# build package `bat` from flake `nixpkgs`, and put a symlink `result` in the current directory.
|
|
||||||
mkdir build-nix-package && cd build-nix-package
|
|
||||||
nix build "nixpkgs#bat"
|
|
||||||
# build a local flake is the same as nix develop, skip it
|
|
||||||
```
|
|
||||||
|
|
||||||
### Nix Flakes Repo
|
|
||||||
|
|
||||||
除了官方的 Nixpkgs 之外,nix flake 还可以从任何第三方仓库中获取 flake,这个前面已经演示过许多了。
|
|
||||||
|
|
||||||
第三方仓库虽然多,不过有几个比较常用的,官方也给它们提供了别名,列表保存在 [NixOS/flake-registry](ttps://github.com/NixOS/flake-registry/blob/master/flake-registry.json),可供参考。
|
|
||||||
|
|
||||||
比较知名的有:
|
|
||||||
|
|
||||||
- [NUR](https://github.com/nix-community/NUR): 它类似 Arch Linux 的 AUR,是一个第三方 packages/flakes 的集合
|
|
||||||
- [home-manager](https://github.com/nix-community/home-manager): home-manager 的 flake 版本
|
|
||||||
|
|
||||||
## Basics of Nix Language
|
|
||||||
|
|
||||||
>https://nix.dev/tutorials/nix-language
|
|
||||||
|
|
||||||
主要包含如下内容:
|
|
||||||
|
|
||||||
1. 数据类型
|
|
||||||
2. 函数的声明与调用语法
|
|
||||||
3. 内置函数与库函数
|
|
||||||
4. inputs 的不纯性
|
|
||||||
5. 用于描述 build task 的 derivation
|
|
||||||
|
|
||||||
### 1. 基础数据类型一览
|
|
||||||
|
|
||||||
```nix
|
|
||||||
{
|
|
||||||
string = "hello";
|
|
||||||
integer = 1;
|
|
||||||
float = 3.141;
|
|
||||||
bool = true;
|
|
||||||
null = null;
|
|
||||||
list = [ 1 "two" false ];
|
|
||||||
attribute-set = {
|
|
||||||
a = "hello";
|
|
||||||
b = 2;
|
|
||||||
c = 2.718;
|
|
||||||
d = false;
|
|
||||||
}; # comments are supported
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
以及一些基础操作符,普通的算术运算、布尔运算就跳过了:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
# List concatenation
|
|
||||||
[ 1 2 3 ] ++ [ 4 5 6 ] # [ 1 2 3 4 5 6 ]
|
|
||||||
|
|
||||||
# Update attribute set attrset1 with names and values from attrset2.
|
|
||||||
{ a = 1; b = 2; } // { b = 3; c = 4; } # { a = 1; b = 3; c = 4; }
|
|
||||||
|
|
||||||
# 逻辑隐含,等同于 !b1 || b2.
|
|
||||||
bool -> bool
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. attribute set 说明
|
|
||||||
|
|
||||||
花括号 `{}` 用于创建 attribute set,也就是 key-value 对的集合,类似于 JSON 中的对象。
|
|
||||||
|
|
||||||
attribute set 默认不支持递归引用,如下内容会报错:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
{
|
|
||||||
a = 1;
|
|
||||||
b = a + 1; # error: undefined variable 'a'
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
不过 nix 提供了 `rec` 关键字(recursive attribute set),可用于创建递归引用的 attribute set:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
rec {
|
|
||||||
a = 1;
|
|
||||||
b = a + 1; # ok
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
在递归引用的情况下,nix 会按照声明的顺序进行求值,所以如果 `a` 在 `b` 之后声明,那么 `b` 会报错。
|
|
||||||
|
|
||||||
可以使用 `.` 操作符来访问 attribute set 的成员:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
let
|
|
||||||
a = {
|
|
||||||
b = {
|
|
||||||
c = 1;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
|
||||||
a.b.c # result is 1
|
|
||||||
```
|
|
||||||
|
|
||||||
`.` 操作符也可直接用于赋值:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
{ a.b.c = 1; }
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. let ... in ...
|
|
||||||
|
|
||||||
nix 的 `let ... in ...` 语法被称作「let 表达式」或者「let 绑定」,它用于创建临时使用的局部变量:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
let
|
|
||||||
a = 1;
|
|
||||||
in
|
|
||||||
a + a # result is 2
|
|
||||||
```
|
|
||||||
|
|
||||||
let 表达式中的变量只能在 `in` 之后的表达式中使用,理解成临时变量就行。
|
|
||||||
|
|
||||||
### 4. with 语句
|
|
||||||
|
|
||||||
|
|
||||||
with 语句的语法如下:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
with <attribute-set> ; <expression>
|
|
||||||
```
|
|
||||||
|
|
||||||
`with` 语句会将 `<attribute-set>` 中的所有成员添加到当前作用域中,这样在 `<expression>` 中就可以直接使用 `<attribute-set>` 中的成员了,简化 attribute set 的访问语法,比如:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
let
|
|
||||||
a = {
|
|
||||||
x = 1;
|
|
||||||
y = 2;
|
|
||||||
z = 3;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
with a; [ x y z ] # result is [ 1 2 3 ], equavlent to [ a.x a.y a.z ]
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. 继承 inherit ...
|
|
||||||
|
|
||||||
`inherit` 语句用于从 attribute set 中继承成员,同样是一个简化代码的语法糖,比如:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
let
|
|
||||||
x = 1;
|
|
||||||
y = 2;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit x y;
|
|
||||||
} # result is { x = 1; y = 2; }
|
|
||||||
```
|
|
||||||
|
|
||||||
inherit 还能直接从某个 attribute set 中继承成员,语法为 `inherit (<attribute-set>) <member-name>;`,比如:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
let
|
|
||||||
a = {
|
|
||||||
x = 1;
|
|
||||||
y = 2;
|
|
||||||
z = 3;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit (a) x y;
|
|
||||||
} # result is { x = 1; y = 2; }
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6. ${ ... } 字符串插值
|
|
||||||
|
|
||||||
`${ ... }` 用于字符串插值,懂点编程的应该都很容易理解这个,比如:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
let
|
|
||||||
a = 1;
|
|
||||||
in
|
|
||||||
"the value of a is ${a}" # result is "the value of a is 1"
|
|
||||||
```
|
|
||||||
|
|
||||||
### 7. 文件系统路径
|
|
||||||
|
|
||||||
Nix 中不带引号的字符串会被解析为文件系统路径,路径的语法与 Unix 系统相同。
|
|
||||||
|
|
||||||
### 8. 搜索路径
|
|
||||||
|
|
||||||
>请不要使用这个功能,搜索路径不是 pure 的,会导致不可预期的行为。
|
|
||||||
|
|
||||||
Nix 会在看到 `<nixpkgs>` 这类三角括号语法时,会在 `NIX_PATH` 环境变量中指定的路径中搜索该路径。
|
|
||||||
|
|
||||||
因为环境变量 `NIX_PATH` 是可变更的值,所以这个功能是不纯的,会导致不可预期的行为。
|
|
||||||
|
|
||||||
### 9. 多行字符串
|
|
||||||
|
|
||||||
多行字符串的语法为 `''`,比如:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
''
|
|
||||||
this is a
|
|
||||||
multi-line
|
|
||||||
string
|
|
||||||
''
|
|
||||||
```
|
|
||||||
|
|
||||||
### 10. 函数
|
|
||||||
|
|
||||||
函数的声明语法为:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
<arg1>:
|
|
||||||
<body>;
|
|
||||||
```
|
|
||||||
|
|
||||||
举几个常见的例子:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
# function with one argument
|
|
||||||
a: a + a
|
|
||||||
|
|
||||||
# 嵌套函数
|
|
||||||
a: b: a + b
|
|
||||||
|
|
||||||
# function with two arguments
|
|
||||||
{ a, b }: a + b
|
|
||||||
|
|
||||||
# function with two arguments and default values
|
|
||||||
{ a ? 1, b ? 2 }: a + b
|
|
||||||
|
|
||||||
# 带有命名 attribute set 作为参数的函数,并且使用 ... 收集其他可选参数
|
|
||||||
# 命名 args 与 ... 可选参数通常被一起作为函数的参数定义使用
|
|
||||||
args@{ a, b, ... }: a + b + args.c
|
|
||||||
# 如下内容等价于上面的内容
|
|
||||||
{ a, b, ... }@args: a + b + args.c
|
|
||||||
|
|
||||||
# 但是要注意命名参数仅绑定了输入的 attribute set,默认参数不在其中,举例
|
|
||||||
let
|
|
||||||
f = { a ? 1, b ? 2, ... }@args: args # this will cause an error
|
|
||||||
in
|
|
||||||
f {} # result is {}
|
|
||||||
|
|
||||||
# 函数的调用方式就是把参数放在后面,比如下面的 2 就是前面这个函数的参数
|
|
||||||
a: a + a 2 # result is 4
|
|
||||||
|
|
||||||
# 还可以给函数命名,不过必须使用 let 表达式
|
|
||||||
let
|
|
||||||
f = a: a + a;
|
|
||||||
in
|
|
||||||
f 2 # result is 4
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 内置函数
|
|
||||||
|
|
||||||
Nix 内置了一些函数,可通过 `builtins.<function-name>` 来调用,比如:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
builtins.add 1 2 # result is 3
|
|
||||||
```
|
|
||||||
|
|
||||||
详细的内置函数列表参见 [Built-in Functions - Nix Reference Mannual](https://nixos.org/manual/nix/stable/language/builtins.html)
|
|
||||||
|
|
||||||
#### import 表达式
|
|
||||||
|
|
||||||
`import` 表达式以其他 nix 文件的路径作为参数,返回该 nix 文件的执行结果。
|
|
||||||
|
|
||||||
`import` 的参数如果为文件夹路径,那么会返回该文件夹下的 `default.nix` 文件的执行结果。
|
|
||||||
|
|
||||||
举个例子,首先创建一个 `file.nix` 文件:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ echo "x: x + 1" > file.nix
|
|
||||||
```
|
|
||||||
|
|
||||||
然后使用 import 执行它:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
import ./file.nix 1 # result is 2
|
|
||||||
```
|
|
||||||
|
|
||||||
#### pkgs.lib 函数包
|
|
||||||
|
|
||||||
除了 builtins 之外,Nix 的 nixpkgs 仓库还提供了一个名为 `lib` 的 attribute set,它包含了一些常用的函数,它通常被以如下的形式被使用:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
let
|
|
||||||
pkgs = import <nixpkgs> {};
|
|
||||||
in
|
|
||||||
pkgs.lib.strings.toUpper "search paths considered harmful" # result is "SEARCH PATHS CONSIDERED HARMFUL"
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
可以通过 [Nixpkgs Library Functions - Nixpkgs Manual](https://nixos.org/manual/nixpkgs/stable/#sec-functions-library) 查看 lib 函数包的详细内容。
|
|
||||||
|
|
||||||
### 不纯
|
|
||||||
|
|
||||||
Nix 语言本身是纯函数式的,是纯的,也就是说它就跟数学中的函数一样,同样的输入永远得到同样的输出。
|
|
||||||
|
|
||||||
**Nix 唯一的不纯之处在这里:从文件系统路径或者其他输入源中读取文件作为构建任务的输入**。
|
|
||||||
|
|
||||||
nix 的构建输入只有两种,一种是从文件系统路径等输入源中读取文件,另一种是将其他函数作为输入。
|
|
||||||
|
|
||||||
>nix 中的搜索路径与 `builtins.currentSystem` 也是不纯的,但是这两个功能都不建议使用,所以这里略过了。
|
|
||||||
|
|
||||||
### Fetchers
|
|
||||||
|
|
||||||
构建输入除了直接来自文件系统路径之外,还可以通过 Fetchers 来获取,Fetcher 是一种特殊的函数,它的输入是一个 attribute set,输出是 nix store 中的一个系统路径。
|
|
||||||
|
|
||||||
Nix 提供了四个内置的 Fetcher,分别是:
|
|
||||||
|
|
||||||
- `builtins.fetchurl`:从 url 中下载文件
|
|
||||||
- `builtins.fetchTarball`:从 url 中下载 tarball 文件
|
|
||||||
- `builtins.fetchGit`:从 git 仓库中下载文件
|
|
||||||
- `builtins.fetchClosure`:从 Nix store 中获取 derivation
|
|
||||||
|
|
||||||
|
|
||||||
举例:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
builtins.fetchurl "https://github.com/NixOS/nix/archive/7c3ab5751568a0bc63430b33a5169c5e4784a0ff.tar.gz"
|
|
||||||
# result example => "/nix/store/7dhgs330clj36384akg86140fqkgh8zf-7c3ab5751568a0bc63430b33a5169c5e4784a0ff.tar.gz"
|
|
||||||
|
|
||||||
builtins.fetchTarball "https://github.com/NixOS/nix/archive/7c3ab5751568a0bc63430b33a5169c5e4784a0ff.tar.gz"
|
|
||||||
# result example(auto unzip the tarball) => "/nix/store/d59llm96vgis5fy231x6m7nrijs0ww36-source"
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### Derivations
|
|
||||||
|
|
||||||
一个构建动作的 nix 语言描述被称做一个 Derivation,它描述了如何构建一个软件包,它的执行结果是一个 store object
|
|
||||||
|
|
||||||
在 Nix 语言的最底层,一个构建任务就是使用 builtins 中的不纯函数 `derivation` 创建的,我们实际使用的 `stdenv.mkDerivation` 就是它的一个 wrapper,屏蔽了底层的细节,简化了用法。
|
|
||||||
|
|
||||||
### stdenv.mkDerivation
|
|
||||||
|
|
||||||
stdenv,顾名思义即标准构建环境,它是一个 attribute set,提供了构建 Unix 程序所需的标准环境,比如 gcc、glibc、binutils 等等。
|
|
||||||
它可以完全取代我们在其他操作系统上常用的构建工具链,比如 `./configure`; `make`; `make install` 等等。
|
|
||||||
|
|
||||||
即使 stdenv 提供的环境不能满足你的要求,你也可以通过 `stdenv.mkDerivation` 来创建一个自定义的构建环境。
|
|
||||||
|
|
||||||
举个例子:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
{ lib, stdenv }:
|
|
||||||
|
|
||||||
stdenv.mkDerivation rec {
|
|
||||||
pname = "libfoo";
|
|
||||||
version = "1.2.3";
|
|
||||||
# 源码
|
|
||||||
src = fetchurl {
|
|
||||||
url = "http://example.org/libfoo-source-${version}.tar.bz2";
|
|
||||||
sha256 = "0x2g1jqygyr5wiwg4ma1nd7w4ydpy82z9gkcv8vh2v8dn3y58v5m";
|
|
||||||
};
|
|
||||||
|
|
||||||
# 构建依赖
|
|
||||||
buildInputs = [libbar perl ncurses];
|
|
||||||
|
|
||||||
# Nix 默认将构建拆分为一系列 phases,这里仅用到其中两个
|
|
||||||
# https://nixos.org/manual/nixpkgs/stable/#ssec-controlling-phases
|
|
||||||
buildPhase = ''
|
|
||||||
gcc foo.c -o foo
|
|
||||||
'';
|
|
||||||
installPhase = ''
|
|
||||||
mkdir -p $out/bin
|
|
||||||
cp foo $out/bin
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Override 与 Overlays
|
|
||||||
|
|
||||||
TODO
|
|
||||||
|
|
||||||
## Usfeful Flakes
|
|
||||||
|
|
||||||
those flakes are useful for flake development, but require more knowledge about nix modules, profiles, overlays, etc.
|
|
||||||
|
|
||||||
- [flake-parts](https://github.com/hercules-ci/flake-parts): Simplify Nix Flakes with the module system, useful to hold multiple system configurations in a single flake.
|
|
||||||
- [flake-utils-plus](https://github.com/gytis-ivaskevicius/flake-utils-plus): an more powerful utils for flake development.
|
|
||||||
- [github](https://github.com/divnix/digga): a powerful nix flake template to hold multiple host's configurations in a single flake.
|
|
||||||
|
|
||||||
|
|
||||||
[digga]: https://github.com/divnix/digga
|
|
||||||
[sway-nvidia]: https://github.com/crispyricepc/sway-nvidia
|
|
||||||
[New Nix Commands]: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html
|
|
||||||
[Zero to Nix - Determinate Systems]: https://github.com/DeterminateSystems/zero-to-nix
|
|
||||||
@@ -5,29 +5,24 @@ This repository is home to the nix code that builds my systems.
|
|||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- vscode extensions
|
- vscode extensions - [nix-vscode-extensions](https://github.com/nix-community/nix-vscode-extensions)
|
||||||
- secret management
|
- secret management - [sops-nix](https://github.com/Mic92/sops-nix)
|
||||||
|
- switch from i3wm to hyprland
|
||||||
|
- i3wm: old and stable, only support X11
|
||||||
|
- sway: compatible with i3wm, support Wayland. do not support Nvidia GPU officially.
|
||||||
|
- [hyprland](https://wiki.hyprland.org/Nix/Hyprland-on-NixOS/): project starts from 2022, support Wayland, envolving fast, good looking, support Nvidia GPU.
|
||||||
|
|
||||||
## How to install Nix and Deploy this Flake?
|
|
||||||
|
|
||||||
Nix can be used on Linux and MacOS, we have to method to install Nix:
|
|
||||||
|
|
||||||
1. [Official Way to Install Nix](https://nixos.org/download.html): writen in bash script, `nix-command` & `flake` are disabled by default till now (2023-04-23).
|
|
||||||
1. you need to follow [Enable flakes - NixOS Wiki](https://nixos.wiki/wiki/Flakes) to enable `flake` feature.
|
|
||||||
2. and it provide no method to uninstall nix automatically, you need to delte all resources & users & group(`nixbld`) manually.
|
|
||||||
2. [The Determinate Nix Installer](https://github.com/DeterminateSystems/nix-installer): writen mainly in Rust, enable `nix-command` & `flake` by default, and offer an easy way to uninstall Nix.
|
|
||||||
|
|
||||||
After installed Nix with `nix-command` & `flake` enabled, you can deploy this flake with the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo nixos-rebuild switch .#nixos
|
|
||||||
```
|
|
||||||
|
|
||||||
## Why Nix?
|
## Why Nix?
|
||||||
|
|
||||||
Nix allows for easy to manage, collaborative, reproducible deployments. This means that once something is setup and configured once, it works forever. If someone else shares their configuration, anyone can make use of it.
|
Nix allows for easy to manage, collaborative, reproducible deployments. This means that once something is setup and configured once, it works forever. If someone else shares their configuration, anyone can make use of it.
|
||||||
|
|
||||||
|
|
||||||
## References
|
## How to install Nix and Deploy this Flake?
|
||||||
|
|
||||||
|
After installed NixOS with `nix-command` & `flake` enabled, you can deploy this flake with the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo nixos-rebuild switch .#nixos-test
|
||||||
|
```
|
||||||
|
|
||||||
- [Nix Flake Basics](./Nix_Flake_Basics.md)
|
|
||||||
|
|||||||
@@ -25,9 +25,10 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
# 这是 flake.nix 的标准格式,inputs 是 flake 的依赖,outputs 是 flake 的输出
|
# 这是 flake.nix 的标准格式,inputs 是 flake 的依赖,outputs 是 flake 的输出
|
||||||
# inputs 中的每一项都被拉取、构建后,被作为参数传递给 outputs 函数
|
# inputs 中的每一项都被拉取、构建后,被作为参数传递给 outputs 函数
|
||||||
inputs = {
|
inputs = {
|
||||||
# 以 url 的形式指定依赖,flake 会自动拉取、构建
|
# flake inputs 有很多种引用方式,应用最广泛的是 github 的引用方式
|
||||||
|
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # 使用 nixos-unstable 分支
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # 使用 nixos-unstable 分支
|
||||||
home-manager.url = "github:nix-community/home-manager";
|
home-manager.url = "github:nix-community/home-manager";
|
||||||
# follows 是 inputs 中的继承语法
|
# follows 是 inputs 中的继承语法
|
||||||
@@ -41,17 +42,17 @@
|
|||||||
# outputs 的参数都是 inputs 中定义的依赖项,可以通过它们的名称来引用。
|
# outputs 的参数都是 inputs 中定义的依赖项,可以通过它们的名称来引用。
|
||||||
# 不过 self 是个例外,这个特殊参数指向 outputs 自身(自引用),以及 flake 根目录
|
# 不过 self 是个例外,这个特殊参数指向 outputs 自身(自引用),以及 flake 根目录
|
||||||
# 这里的 @ 语法将函数的参数 attribute set 取了个别名,方便在内部使用
|
# 这里的 @ 语法将函数的参数 attribute set 取了个别名,方便在内部使用
|
||||||
outputs = inputs@{
|
outputs = inputs@{
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
home-manager,
|
home-manager,
|
||||||
nix-vscode-extensions,
|
nix-vscode-extensions,
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
# 名为 nixosConfigurations 的 outputs 会在执行 `nixos-rebuild switch --flake .` 时被使用
|
# 名为 nixosConfigurations 的 outputs 会在执行 `nixos-rebuild switch --flake .` 时被使用
|
||||||
# 默认情况下会使用与主机 hostname 同名的 nixosConfigurations,但是也可以通过 `--flake .#<name>` 来指定
|
# 默认情况下会使用与主机 hostname 同名的 nixosConfigurations,但是也可以通过 `--flake .#<name>` 来指定
|
||||||
nixosConfigurations = {
|
nixosConfigurations = {
|
||||||
# hostname 为 nixos 的主机会使用这个配置
|
# hostname 为 nixos-test 的主机会使用这个配置
|
||||||
# 这里使用了 nixpkgs.lib.nixosSystem 函数来构建配置,后面的 attributes set 是它的参数
|
# 这里使用了 nixpkgs.lib.nixosSystem 函数来构建配置,后面的 attributes set 是它的参数
|
||||||
# 在 nixos 上使用此命令部署配置:`nixos-rebuild switch --flake .#nixos-test`
|
# 在 nixos 上使用此命令部署配置:`nixos-rebuild switch --flake .#nixos-test`
|
||||||
nixos-test = nixpkgs.lib.nixosSystem {
|
nixos-test = nixpkgs.lib.nixosSystem {
|
||||||
@@ -61,7 +62,7 @@
|
|||||||
# NixOS Module 可以是一个 attribute set,也可以是一个返回 attribute set 的函数
|
# NixOS Module 可以是一个 attribute set,也可以是一个返回 attribute set 的函数
|
||||||
# 如果是函数,那么它的参数就是当前的 NixOS Module 的参数.
|
# 如果是函数,那么它的参数就是当前的 NixOS Module 的参数.
|
||||||
# 根据 Nix Wiki 对 NixOS modules 的描述,NixOS modules 函数的参数可以有这四个(详见本仓库中的 modules 文件):
|
# 根据 Nix Wiki 对 NixOS modules 的描述,NixOS modules 函数的参数可以有这四个(详见本仓库中的 modules 文件):
|
||||||
#
|
#
|
||||||
# config: The configuration of the entire system
|
# config: The configuration of the entire system
|
||||||
# options: All option declarations refined with all definition and declaration references.
|
# options: All option declarations refined with all definition and declaration references.
|
||||||
# pkgs: The attribute set extracted from the Nix package collection and enhanced with the nixpkgs.config option.
|
# pkgs: The attribute set extracted from the Nix package collection and enhanced with the nixpkgs.config option.
|
||||||
@@ -70,7 +71,7 @@
|
|||||||
# nix flake 的 modules 系统可将配置模块化,提升配置的可维护性
|
# nix flake 的 modules 系统可将配置模块化,提升配置的可维护性
|
||||||
# 默认只能传上面这四个参数,如果需要传其他参数,必须使用 specialArgs
|
# 默认只能传上面这四个参数,如果需要传其他参数,必须使用 specialArgs
|
||||||
modules = [
|
modules = [
|
||||||
./hosts
|
./hosts/nixos-test
|
||||||
|
|
||||||
# home-manager 作为 nixos 的一个 module
|
# home-manager 作为 nixos 的一个 module
|
||||||
# 这样在 nixos-rebuild switch 时,home-manager 也会被自动部署,不需要额外执行 home-manager switch 命令
|
# 这样在 nixos-rebuild switch 时,home-manager 也会被自动部署,不需要额外执行 home-manager switch 命令
|
||||||
@@ -86,8 +87,29 @@
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
msi-rtx4090 = nixpkgs.lib.nixosSystem {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
|
||||||
|
modules = [
|
||||||
|
./hosts/msi-rtx4090
|
||||||
|
|
||||||
|
# home-manager 作为 nixos 的一个 module
|
||||||
|
# 这样在 nixos-rebuild switch 时,home-manager 也会被自动部署,不需要额外执行 home-manager switch 命令
|
||||||
|
home-manager.nixosModules.home-manager
|
||||||
|
{
|
||||||
|
home-manager.useGlobalPkgs = true;
|
||||||
|
home-manager.useUserPackages = true;
|
||||||
|
|
||||||
|
# 使用 home-manager.extraSpecialArgs 自定义传递给 ./home 的参数
|
||||||
|
home-manager.extraSpecialArgs = inputs;
|
||||||
|
home-manager.users.ryan = import ./home;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
# 如果你在 x86_64-linux 平台上执行 nix build,那么默认会使用这个配置,或者也能通过 `.#<name>` 参数来指定非 default 的配置
|
# 如果你在 x86_64-linux 平台上执行 nix build,那么默认会使用这个配置,或者也能通过 `.#<name>` 参数来指定非 default 的配置
|
||||||
# packages.x86_64-linux.default =
|
# packages.x86_64-linux.default =
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,13 @@
|
|||||||
executable = true; # make all scripts executable
|
executable = true; # make all scripts executable
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
# set cursor size and dpi for 4k monitor
|
||||||
|
xresources.properties = {
|
||||||
|
"Xcursor.size" = 16;
|
||||||
|
"Xft.dpi" = 192;
|
||||||
|
};
|
||||||
|
|
||||||
# 直接以 text 的方式,在 nix 配置文件中硬编码文件内容
|
# 直接以 text 的方式,在 nix 配置文件中硬编码文件内容
|
||||||
# home.file.".xxx".text = ''
|
# home.file.".xxx".text = ''
|
||||||
# xxx
|
# xxx
|
||||||
|
|||||||
+88
-81
@@ -34,86 +34,93 @@
|
|||||||
"terminal.integrated.fontFamily" = "JetBrainsMono Nerd Font";
|
"terminal.integrated.fontFamily" = "JetBrainsMono Nerd Font";
|
||||||
};
|
};
|
||||||
|
|
||||||
# pkgs.vscode-extensions 里包含的 vscode 太少了
|
package =
|
||||||
# 必须使用社区的 <https://github.com/nix-community/nix-vscode-extensions> 才能安装更多插件
|
let
|
||||||
# TODO 安装有点麻烦,后面再整
|
config.packageOverrides = pkgs: {
|
||||||
extensions = with pkgs.vscode-extensions; [
|
vscode = pkgs.vscode-with-extensions.override {
|
||||||
# aaron-bond.better-comments
|
# pkgs.vscode-extensions 里包含的 vscode 太少了
|
||||||
# anweber.vscode-httpyac
|
# 必须使用社区的 <https://github.com/nix-community/nix-vscode-extensions> 才能安装更多插件
|
||||||
# arrterian.nix-env-selector
|
vscodeExtensions = with nix-vscode-extensions.extensions; [
|
||||||
# bierner.markdown-mermaid
|
aaron-bond.better-comments
|
||||||
# christian-kohler.path-intellisense
|
anweber.vscode-httpyac
|
||||||
# cschlosser.doxdocgen
|
arrterian.nix-env-selector
|
||||||
# DanishSarwar.reverse-search
|
bierner.markdown-mermaid
|
||||||
# eamodio.gitlens
|
christian-kohler.path-intellisense
|
||||||
# esbenp.prettier-vscode
|
cschlosser.doxdocgen
|
||||||
# espressif.esp-idf-extension
|
DanishSarwar.reverse-search
|
||||||
# fabiospampinato.vscode-diff
|
eamodio.gitlens
|
||||||
# GitHub.copilot
|
esbenp.prettier-vscode
|
||||||
# golang.go
|
espressif.esp-idf-extension
|
||||||
# hashicorp.terraform
|
fabiospampinato.vscode-diff
|
||||||
# janisdd.vscode-edit-csv
|
GitHub.copilot
|
||||||
# jebbs.plantuml
|
golang.go
|
||||||
# jeff-hykin.better-cpp-syntax
|
hashicorp.terraform
|
||||||
# jnoortheen.nix-ide
|
janisdd.vscode-edit-csv
|
||||||
# JuanBlanco.solidity
|
jebbs.plantuml
|
||||||
# k--kato.intellij-idea-keybindings
|
jeff-hykin.better-cpp-syntax
|
||||||
# llvm-vs-code-extensions.vscode-clangd
|
jnoortheen.nix-ide
|
||||||
# mcu-debug.debug-tracker-vscode
|
JuanBlanco.solidity
|
||||||
# mcu-debug.memory-view
|
k--kato.intellij-idea-keybindings
|
||||||
# mcu-debug.rtos-views
|
llvm-vs-code-extensions.vscode-clangd
|
||||||
# mikestead.dotenv
|
mcu-debug.debug-tracker-vscode
|
||||||
# mkhl.direnv
|
mcu-debug.memory-view
|
||||||
# ms-azuretools.vscode-docker
|
mcu-debug.rtos-views
|
||||||
# ms-dotnettools.vscode-dotnet-runtime
|
mikestead.dotenv
|
||||||
# ms-kubernetes-tools.vscode-kubernetes-tools
|
mkhl.direnv
|
||||||
# ms-python.isort
|
ms-azuretools.vscode-docker
|
||||||
# ms-python.python
|
ms-dotnettools.vscode-dotnet-runtime
|
||||||
# ms-python.vscode-pylance
|
ms-kubernetes-tools.vscode-kubernetes-tools
|
||||||
# ms-toolsai.jupyter
|
ms-python.isort
|
||||||
# ms-toolsai.jupyter-keymap
|
ms-python.python
|
||||||
# ms-toolsai.jupyter-renderers
|
ms-python.vscode-pylance
|
||||||
# ms-toolsai.vscode-jupyter-cell-tags
|
ms-toolsai.jupyter
|
||||||
# ms-toolsai.vscode-jupyter-slideshow
|
ms-toolsai.jupyter-keymap
|
||||||
# ms-vscode-remote.remote-containers
|
ms-toolsai.jupyter-renderers
|
||||||
# ms-vscode-remote.remote-ssh
|
ms-toolsai.vscode-jupyter-cell-tags
|
||||||
# ms-vscode-remote.remote-ssh-edit
|
ms-toolsai.vscode-jupyter-slideshow
|
||||||
# ms-vscode-remote.vscode-remote-extensionpack
|
ms-vscode-remote.remote-containers
|
||||||
# ms-vscode.cmake-tools
|
ms-vscode-remote.remote-ssh
|
||||||
# ms-vscode.cpptools
|
ms-vscode-remote.remote-ssh-edit
|
||||||
# ms-vscode.cpptools-extension-pack
|
ms-vscode-remote.vscode-remote-extensionpack
|
||||||
# ms-vscode.cpptools-themes
|
ms-vscode.cmake-tools
|
||||||
# ms-vscode.remote-explorer
|
ms-vscode.cpptools
|
||||||
# ms-vscode.remote-server
|
ms-vscode.cpptools-extension-pack
|
||||||
# pinage404.nix-extension-pack
|
ms-vscode.cpptools-themes
|
||||||
# platformio.platformio-ide
|
ms-vscode.remote-explorer
|
||||||
# pomdtr.excalidraw-editor
|
ms-vscode.remote-server
|
||||||
# redhat.java
|
pinage404.nix-extension-pack
|
||||||
# redhat.vscode-commons
|
platformio.platformio-ide
|
||||||
# redhat.vscode-xml
|
pomdtr.excalidraw-editor
|
||||||
# redhat.vscode-yaml
|
redhat.java
|
||||||
# rust-lang.rust-analyzer
|
redhat.vscode-commons
|
||||||
# shd101wyy.markdown-preview-enhanced
|
redhat.vscode-xml
|
||||||
# sumneko.lua
|
redhat.vscode-yaml
|
||||||
# tamasfe.even-better-toml
|
rust-lang.rust-analyzer
|
||||||
# timonwong.shellcheck
|
shd101wyy.markdown-preview-enhanced
|
||||||
# tintinweb.graphviz-interactive-preview
|
sumneko.lua
|
||||||
# tintinweb.solidity-visual-auditor
|
tamasfe.even-better-toml
|
||||||
# tintinweb.vscode-inline-bookmarks
|
timonwong.shellcheck
|
||||||
# tintinweb.vscode-solidity-flattener
|
tintinweb.graphviz-interactive-preview
|
||||||
# tintinweb.vscode-solidity-language
|
tintinweb.solidity-visual-auditor
|
||||||
# twxs.cmake
|
tintinweb.vscode-inline-bookmarks
|
||||||
# vadimcn.vscode-lldb
|
tintinweb.vscode-solidity-flattener
|
||||||
# VisualStudioExptTeam.intellicode-api-usage-examples
|
tintinweb.vscode-solidity-language
|
||||||
# VisualStudioExptTeam.vscodeintellicode
|
twxs.cmake
|
||||||
# vscjava.vscode-java-debug
|
vadimcn.vscode-lldb
|
||||||
# vscjava.vscode-java-pack
|
VisualStudioExptTeam.intellicode-api-usage-examples
|
||||||
# vscjava.vscode-java-test
|
VisualStudioExptTeam.vscodeintellicode
|
||||||
# vscjava.vscode-maven
|
vscjava.vscode-java-debug
|
||||||
# vscode-icons-team.vscode-icons
|
vscjava.vscode-java-pack
|
||||||
# WakaTime.vscode-wakatime
|
vscjava.vscode-java-test
|
||||||
yzhang.markdown-all-in-one
|
vscjava.vscode-maven
|
||||||
zxh404.vscode-proto3
|
vscode-icons-team.vscode-icons
|
||||||
];
|
WakaTime.vscode-wakatime
|
||||||
|
yzhang.markdown-all-in-one
|
||||||
|
zxh404.vscode-proto3
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
pkgs.vscode;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
imports =
|
|
||||||
[
|
|
||||||
./nixos-test
|
|
||||||
../modules/system.nix
|
|
||||||
../modules/i3.nix
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
# Edit this configuration file to define what should be installed on
|
||||||
|
# your system. Help is available in the configuration.nix(5) man page
|
||||||
|
# and in the NixOS manual (accessible by running ‘nixos-help’).
|
||||||
|
|
||||||
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
imports =
|
||||||
|
[
|
||||||
|
../../modules/system.nix
|
||||||
|
../../modules/i3.nix
|
||||||
|
|
||||||
|
# Include the results of the hardware scan.
|
||||||
|
./hardware-configuration.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
# Bootloader.
|
||||||
|
boot.loader = {
|
||||||
|
efi = {
|
||||||
|
canTouchEfiVariables = true;
|
||||||
|
efiSysMountPoint = "/boot/efi"; # ← use the same mount point here.
|
||||||
|
};
|
||||||
|
systemd-boot.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
networking.hostName = "msi-rtx4090"; # Define your hostname.
|
||||||
|
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
|
||||||
|
|
||||||
|
# Configure network proxy if necessary
|
||||||
|
# networking.proxy.default = "http://user:password@proxy:port/";
|
||||||
|
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
|
||||||
|
|
||||||
|
# Enable networking
|
||||||
|
networking.networkmanager.enable = true;
|
||||||
|
networking.defaultGateway = "192.168.5.201";
|
||||||
|
|
||||||
|
# for Nvidia GPU
|
||||||
|
services.xserver.videoDrivers = ["nvidia"];
|
||||||
|
hardware.opengl.enable = true;
|
||||||
|
hardware.nvidia = {
|
||||||
|
package = config.boot.kernelPackages.nvidiaPackages.stable;
|
||||||
|
modesetting.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
# This value determines the NixOS release from which the default
|
||||||
|
# settings for stateful data, like file locations and database versions
|
||||||
|
# on your system were taken. It‘s perfectly fine and recommended to leave
|
||||||
|
# this value at the release version of the first install of this system.
|
||||||
|
# Before changing this value read the documentation for this option
|
||||||
|
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
|
||||||
|
system.stateVersion = "22.11"; # Did you read the comment?
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# 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" "ahci" "nvme" "usbhid" "uas" "usb_storage" "sd_mod" ];
|
||||||
|
boot.initrd.kernelModules = [ ];
|
||||||
|
boot.kernelModules = [ "kvm-intel" ];
|
||||||
|
boot.extraModulePackages = [ ];
|
||||||
|
|
||||||
|
fileSystems."/" =
|
||||||
|
{ device = "/dev/disk/by-uuid/9730ef67-577c-4dc9-8563-f431c1cf25fb";
|
||||||
|
fsType = "ext4";
|
||||||
|
};
|
||||||
|
|
||||||
|
fileSystems."/boot/efi" =
|
||||||
|
{ device = "/dev/disk/by-uuid/8DA9-86FF";
|
||||||
|
fsType = "vfat";
|
||||||
|
};
|
||||||
|
|
||||||
|
swapDevices =
|
||||||
|
[ { device = "/dev/disk/by-uuid/5364261a-3ecc-4754-b114-ff44c529627e"; }
|
||||||
|
];
|
||||||
|
|
||||||
|
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
|
||||||
|
# (the default) this is the recommended approach. When using systemd-networkd it's
|
||||||
|
# still possible to use this option, but it's recommended to use it in conjunction
|
||||||
|
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
|
||||||
|
networking.useDHCP = lib.mkDefault true;
|
||||||
|
# networking.interfaces.enp5s0.useDHCP = lib.mkDefault true;
|
||||||
|
# networking.interfaces.wlo1.useDHCP = lib.mkDefault true;
|
||||||
|
|
||||||
|
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
||||||
|
powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
|
||||||
|
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
||||||
|
}
|
||||||
@@ -6,7 +6,11 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
imports =
|
imports =
|
||||||
[ # Include the results of the hardware scan.
|
[
|
||||||
|
../../modules/system.nix
|
||||||
|
../../modules/i3.nix
|
||||||
|
|
||||||
|
# Include the results of the hardware scan.
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -4,14 +4,14 @@
|
|||||||
{
|
{
|
||||||
|
|
||||||
# i3 related options
|
# i3 related options
|
||||||
environment.pathsToLink = [ "/libexec" ]; # links /libexec from derivations to /run/current-system/sw
|
environment.pathsToLink = [ "/libexec" ]; # links /libexec from derivations to /run/current-system/sw
|
||||||
services.xserver = {
|
services.xserver = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
desktopManager = {
|
desktopManager = {
|
||||||
xterm.enable = false;
|
xterm.enable = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
displayManager = {
|
displayManager = {
|
||||||
defaultSession = "none+i3";
|
defaultSession = "none+i3";
|
||||||
lightdm.enable = false;
|
lightdm.enable = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user