Compare commits

...

17 Commits

Author SHA1 Message Date
Ryan Yin b9c1b10135 fix: issue #202 2025-07-12 15:55:13 +08:00
Ryan Yin d4847c44ce Merge pull request #191 from ryan4yin/i3-kickstarter-nixos-25.05
feat: upgrade to nixos-25.05
2025-05-29 12:25:29 +08:00
Ryan Yin 1f0a26524b fix: issues after upgrade nixos 2025-05-29 12:23:29 +08:00
Ryan Yin 7dc769aad2 fix: command in README 2025-05-29 12:14:13 +08:00
Ryan Yin 938cf720fd feat: upgrade to nixos-25.05 2025-05-29 12:04:56 +08:00
Ryan Yin 7a5587d14d fix: typo #190 2025-05-29 12:03:21 +08:00
Ryan Yin d384607345 feat: bump nixos to 24.05 2024-08-16 11:18:35 +08:00
Ryan Yin adc91138c5 feat: multi user 2024-08-16 10:55:54 +08:00
Ryan Yin 42bcfeb47c feat: add gitignore 2024-08-16 10:15:54 +08:00
Ryan Yin 82b65f7753 feat: upgrade to nixos-23.11 2023-12-09 22:58:13 +08:00
Ryan Yin 5237bf31c5 nix.settings.substituters(system-level) & nixConfig.extra-substituers(flake-only) 2023-12-09 16:16:22 +08:00
Ryan Yin abdf6d181b fix: set this variable make i3 failed to start XAUTHORITY 2023-09-11 00:25:03 +08:00
Ryan Yin 9e549fb733 feat: add new host - msi-rtx4090 2023-05-04 23:48:49 +08:00
ryan4yin c56db98288 feat: update vscode extensions 2023-05-04 17:53:26 +08:00
ryan4yin 720ef0d9ca feat: update vscode extensions 2023-05-04 17:41:38 +08:00
ryan4yin 796cdcd928 feat: migrate docs to thiscute.world 2023-05-04 16:53:10 +08:00
ryan4yin 126c31d73b feat: update docs 2023-05-04 14:50:40 +08:00
28 changed files with 1383 additions and 918 deletions
+6
View File
@@ -0,0 +1,6 @@
result
result/
.direnv/
.DS_Store
.pre-commit-config.yaml
logs/
-471
View File
@@ -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
+7 -22
View File
@@ -3,31 +3,16 @@
This repository is home to the nix code that builds my systems.
## TODO
- vscode extensions
- secret management
## 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?
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 --flake .#nixos-test
```
- [Nix Flake Basics](./Nix_Flake_Basics.md)
Generated
+19 -72
View File
@@ -1,117 +1,64 @@
{
"nodes": {
"flake-compat": {
"catppuccin-bat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"lastModified": 1734996624,
"narHash": "sha256-6fWoCH90IGumAMc4buLRWL0N61op+AuMNN9CAR9/OdI=",
"owner": "catppuccin",
"repo": "bat",
"rev": "699f60fc8ec434574ca7451b444b880430319941",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"owner": "catppuccin",
"repo": "bat",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
"nixpkgs": ["nixpkgs"]
},
"locked": {
"lastModified": 1682176386,
"narHash": "sha256-xwYjQ8PjfdHlggi8Dq0PXWby/1oXegSUuNuBvoTcnpA=",
"lastModified": 1748487945,
"narHash": "sha256-e9zc/rHdoH9i+sFFhhQiKoF6IuD+T2rB/nUyPaO7CCg=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "6169690ae38175295605d521bd778d999fbd85cd",
"rev": "0d13ea58d565d3c1c1468ddae1f623316dc395d9",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "release-25.05",
"repo": "home-manager",
"type": "github"
}
},
"nix-vscode-extensions": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1683076311,
"narHash": "sha256-xGvR07+fR5g/89oVEQieKG/ZveGHZZyhxXcRouW0WCk=",
"owner": "nix-community",
"repo": "nix-vscode-extensions",
"rev": "70d48e0c7eafdbcdaa9dac6c17f46a88872f7285",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nix-vscode-extensions",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1675763311,
"narHash": "sha256-bz0Q2H3mxsF1CUfk26Sl9Uzi8/HFjGFD/moZHz1HebU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "fab09085df1b60d6a0870c8a89ce26d5a4a708c2",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1681920287,
"narHash": "sha256-+/d6XQQfhhXVfqfLROJoqj3TuG38CAeoT6jO1g9r1k0=",
"lastModified": 1748302896,
"narHash": "sha256-ixMT0a8mM091vSswlTORZj93WQAJsRNmEvqLL+qwTFM=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "645bc49f34fa8eff95479f0345ff57e55b53437e",
"rev": "7848cd8c982f7740edf76ddb3b43d234cb80fc4d",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"ref": "nixos-25.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"catppuccin-bat": "catppuccin-bat",
"home-manager": "home-manager",
"nix-vscode-extensions": "nix-vscode-extensions",
"nixpkgs": "nixpkgs_2"
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}
+62 -67
View File
@@ -1,21 +1,17 @@
{
description = "NixOS configuration of Ryan Yin";
# flake 为了确保够纯,它不依赖系统自身的 /etc/nix/nix.conf,而是在 flake.nix 中通过 nixConfig 设置
# 但是为了确保安全性,flake 默认仅允许直接设置少数 nixConfig 参数,其他参数都需要在执行 nix 命令时指定 `--accept-flake-config`,否则会被忽略
# <https://nixos.org/manual/nix/stable/command-ref/conf-file.html>
# 如果有些包国内镜像下载不到,它仍然会走国外,这时候就得靠旁路由来解决了。
# 临时修改默认网关为旁路由: sudo ip route add default via 192.168.5.201
# sudo ip route del default via 192.168.5.201
nixConfig = {
experimental-features = [ "nix-command" "flakes" ];
substituters = [
# replace official cache with a mirror located in China
"https://mirrors.bfsu.edu.cn/nix-channels/store"
"https://cache.nixos.org/"
];
##################################################################################################################
#
# Want to know Nix in details? Looking for a beginner-friendly tutorial?
# Check out https://github.com/ryan4yin/nixos-and-flakes-book !
#
##################################################################################################################
# nix community's cache server
# the nixConfig here only affects the flake itself, not the system configuration!
nixConfig = {
# substituers will be appended to the default substituters when fetching packages
# nix com extra-substituters = [munity's cache server
extra-substituters = [
"https://nix-community.cachix.org"
];
@@ -24,70 +20,69 @@
];
};
# 这是 flake.nix 的标准格式,inputs 是 flake 的依赖,outputs 是 flake 的输出
# inputs 中的每一项都被拉取、构建后,被作为参数传递给 outputs 函数
inputs = {
# 以 url 的形式指定依赖,flake 会自动拉取、构建
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # 使用 nixos-unstable 分支
home-manager.url = "github:nix-community/home-manager";
# follows 是 inputs 中的继承语法
# 这里使 home-manager 的 nixpkgs 这个 inputs 与当前 flake 的 inputs.nixpkgs 保持一致,避免依赖的 nixpkgs 版本不一致导致问题
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
home-manager.url = "github:nix-community/home-manager/release-25.05";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
# vscode 插件库
nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions";
catppuccin-bat = {
url = "github:catppuccin/bat";
flake = false;
};
};
# outputs 的参数都是 inputs 中定义的依赖项,可以通过它们的名称来引用。
# 不过 self 是个例外,这个特殊参数指向 outputs 自身(自引用),以及 flake 根目录
# 这里的 @ 语法将函数的参数 attribute set 取了个别名,方便在内部使用
outputs = inputs@{
self,
nixpkgs,
home-manager,
nix-vscode-extensions,
...
outputs = inputs @ {
self,
nixpkgs,
home-manager,
...
}: {
# 名为 nixosConfigurations 的 outputs 会在执行 `nixos-rebuild switch --flake .` 时被使用
# 默认情况下会使用与主机 hostname 同名的 nixosConfigurations,但是也可以通过 `--flake .#<name>` 来指定
nixosConfigurations = {
# hostname 为 nixos 的主机会使用这个配置
# 这里使用了 nixpkgs.lib.nixosSystem 函数来构建配置,后面的 attributes set 是它的参数
# 在 nixos 上使用此命令部署配置:`nixos-rebuild switch --flake .#nixos-test`
nixos-test = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
nixos-test = let
username = "ryan";
specialArgs = {inherit username;};
in
nixpkgs.lib.nixosSystem {
inherit specialArgs;
system = "x86_64-linux";
# modules 中每个参数,都是一个 NixOS Module <https://nixos.org/manual/nixos/stable/index.html#sec-modularity>
# NixOS Module 可以是一个 attribute set,也可以是一个返回 attribute set 的函数
# 如果是函数,那么它的参数就是当前的 NixOS Module 的参数.
# 根据 Nix Wiki 对 NixOS modules 的描述,NixOS modules 函数的参数可以有这四个(详见本仓库中的 modules 文件):
#
# config: The configuration of the entire system
# 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.
# modulesPath: The location of the module directory of NixOS.
#
# nix flake 的 modules 系统可将配置模块化,提升配置的可维护性
# 默认只能传上面这四个参数,如果需要传其他参数,必须使用 specialArgs
modules = [
./hosts
modules = [
./hosts/nixos-test
./users/${username}/nixos.nix
# 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.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;
}
];
};
home-manager.extraSpecialArgs = inputs // specialArgs;
home-manager.users.${username} = import ./users/${username}/home.nix;
}
];
};
# 如果你在 x86_64-linux 平台上执行 nix build,那么默认会使用这个配置,或者也能通过 `.#<name>` 参数来指定非 default 的配置
# packages.x86_64-linux.default =
msi-rtx4090 = let
username = "suzi"; # another username for this machine
specialArgs = {inherit username;};
in
nixpkgs.lib.nixosSystem {
inherit specialArgs;
system = "x86_64-linux";
modules = [
./hosts/msi-rtx4090
./users/${username}/nixos.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = inputs // specialArgs;
home-manager.users.${username} = import ./users/${username}/home.nix;
}
];
};
};
};
}
+4 -15
View File
@@ -1,20 +1,9 @@
{ config, pkgs, ... }:
{
imports = [
./fcitx5
./i3
./programs
./rofi
./shell
];
{username, ...}: {
# Home Manager needs a bit of information about you and the
# paths it should manage.
home = {
username = "ryan";
homeDirectory = "/home/ryan";
inherit username;
homeDirectory = "/home/${username}";
# This value determines the Home Manager release that your
# configuration is compatible with. This helps avoid breakage
@@ -24,7 +13,7 @@
# You can update Home Manager without changing this value. See
# the Home Manager release notes for a list of state version
# changes in each release.
stateVersion = "22.11";
stateVersion = "25.05";
};
# Let Home Manager install and manage itself.
+7
View File
@@ -18,6 +18,13 @@
executable = true; # make all scripts executable
};
# set cursor size and dpi for 4k monitor
xresources.properties = {
"Xcursor.size" = 16;
"Xft.dpi" = 192;
};
# 直接以 text 的方式,在 nix 配置文件中硬编码文件内容
# home.file.".xxx".text = ''
# xxx
+2 -1
View File
@@ -1,6 +1,7 @@
{
pkgs,
config,
username,
...
}: {
programs = {
@@ -14,7 +15,7 @@
firefox = {
enable = true;
profiles.ryan = {};
profiles.${username} = {};
};
};
}
+17 -12
View File
@@ -1,4 +1,9 @@
{pkgs, ...}: {
{
lib,
pkgs,
catppuccin-bat,
...
}: {
home.packages = with pkgs; [
# archives
zip
@@ -7,7 +12,7 @@
# utils
ripgrep
yq-go # https://github.com/mikefarah/yq
yq-go # https://github.com/mikefarah/yq
htop
# misc
@@ -26,14 +31,13 @@
docker-compose
kubectl
nodejs
nodePackages.npm
nodePackages.pnpm
yarn
# db related
dbeaver
dbeaver-bin
mycli
pgcli
];
@@ -50,19 +54,20 @@
enable = true;
config = {
pager = "less -FR";
theme = "Catppuccin-mocha";
theme = "catppuccin-mocha";
};
themes = {
Catppuccin-mocha = builtins.readFile (pkgs.fetchurl {
url = "https://raw.githubusercontent.com/catppuccin/bat/main/Catppuccin-mocha.tmTheme";
hash = "sha256-qMQNJGZImmjrqzy7IiEkY5IhvPAMZpq0W6skLLsng/w=";
});
# https://raw.githubusercontent.com/catppuccin/bat/main/Catppuccin-mocha.tmTheme
catppuccin-mocha = {
src = catppuccin-bat;
file = "Catppuccin-mocha.tmTheme";
};
};
};
btop.enable = true; # replacement of htop/nmon
exa.enable = true; # A modern replacement for ls
jq.enable = true; # A lightweight and flexible command-line JSON processor
btop.enable = true; # replacement of htop/nmon
eza.enable = true; # A modern replacement for ls
jq.enable = true; # A lightweight and flexible command-line JSON processor
ssh.enable = true;
aria2.enable = true;
-5
View File
@@ -1,14 +1,9 @@
{
config,
pkgs,
...
}: {
imports = [
./browsers.nix
./common.nix
./git.nix
./media.nix
./vscode.nix
./xdg.nix
];
}
+1 -2
View File
@@ -7,7 +7,6 @@
programs.git = {
enable = true;
userName = "Ryan Yin";
userEmail = "xiaoyin_c@qq.com";
# ... Other options ...
};
}
-119
View File
@@ -1,119 +0,0 @@
{
config,
pkgs,
home-manager,
nix-vscode-extensions,
...
}:
{
# if use vscode in wayland, uncomment this line
# environment.sessionVariables.NIXOS_OZONE_WL = "1";
programs.vscode = {
enable = true;
userSettings = {
"editor.renderWhitespace" = "all";
"files.autoSave" = "onFocusChange";
"editor.rulers" = [ 80 120 ];
"telemetry.enableTelemetry" = false;
"telemetry.enableCrashReporter" = false;
"editor.tabSize" = 2;
"files.exclude" = { "**/node_modules/**" = true; };
"editor.formatOnSave" = false;
"breadcrumbs.enabled" = true;
"editor.useTabStops" = false;
"editor.fontFamily" = "JetBrainsMono Nerd Font";
"editor.fontSize" = 16;
"editor.fontLigatures" = true;
"editor.lineHeight" = 20;
"workbench.fontAliasing" = "antialiased";
"files.trimTrailingWhitespace" = true;
"editor.minimap.enabled" = false;
"workbench.editor.enablePreview" = false;
"terminal.integrated.fontFamily" = "JetBrainsMono Nerd Font";
};
# pkgs.vscode-extensions 里包含的 vscode 太少了
# 必须使用社区的 <https://github.com/nix-community/nix-vscode-extensions> 才能安装更多插件
# TODO 安装有点麻烦,后面再整
extensions = with pkgs.vscode-extensions; [
# aaron-bond.better-comments
# anweber.vscode-httpyac
# arrterian.nix-env-selector
# bierner.markdown-mermaid
# christian-kohler.path-intellisense
# cschlosser.doxdocgen
# DanishSarwar.reverse-search
# eamodio.gitlens
# esbenp.prettier-vscode
# espressif.esp-idf-extension
# fabiospampinato.vscode-diff
# GitHub.copilot
# golang.go
# hashicorp.terraform
# janisdd.vscode-edit-csv
# jebbs.plantuml
# jeff-hykin.better-cpp-syntax
# jnoortheen.nix-ide
# JuanBlanco.solidity
# k--kato.intellij-idea-keybindings
# llvm-vs-code-extensions.vscode-clangd
# mcu-debug.debug-tracker-vscode
# mcu-debug.memory-view
# mcu-debug.rtos-views
# mikestead.dotenv
# mkhl.direnv
# ms-azuretools.vscode-docker
# ms-dotnettools.vscode-dotnet-runtime
# ms-kubernetes-tools.vscode-kubernetes-tools
# ms-python.isort
# ms-python.python
# ms-python.vscode-pylance
# ms-toolsai.jupyter
# ms-toolsai.jupyter-keymap
# ms-toolsai.jupyter-renderers
# ms-toolsai.vscode-jupyter-cell-tags
# ms-toolsai.vscode-jupyter-slideshow
# ms-vscode-remote.remote-containers
# ms-vscode-remote.remote-ssh
# ms-vscode-remote.remote-ssh-edit
# ms-vscode-remote.vscode-remote-extensionpack
# ms-vscode.cmake-tools
# ms-vscode.cpptools
# ms-vscode.cpptools-extension-pack
# ms-vscode.cpptools-themes
# ms-vscode.remote-explorer
# ms-vscode.remote-server
# pinage404.nix-extension-pack
# platformio.platformio-ide
# pomdtr.excalidraw-editor
# redhat.java
# redhat.vscode-commons
# redhat.vscode-xml
# redhat.vscode-yaml
# rust-lang.rust-analyzer
# shd101wyy.markdown-preview-enhanced
# sumneko.lua
# tamasfe.even-better-toml
# timonwong.shellcheck
# tintinweb.graphviz-interactive-preview
# tintinweb.solidity-visual-auditor
# tintinweb.vscode-inline-bookmarks
# tintinweb.vscode-solidity-flattener
# tintinweb.vscode-solidity-language
# twxs.cmake
# vadimcn.vscode-lldb
# VisualStudioExptTeam.intellicode-api-usage-examples
# VisualStudioExptTeam.vscodeintellicode
# vscjava.vscode-java-debug
# vscjava.vscode-java-pack
# vscjava.vscode-java-test
# vscjava.vscode-maven
# vscode-icons-team.vscode-icons
# WakaTime.vscode-wakatime
yzhang.markdown-all-in-one
zxh404.vscode-proto3
];
};
}
+1 -1
View File
@@ -18,7 +18,7 @@
"x-scheme-handler/unknown" = browser;
"audio/*" = ["mpv.desktop"];
"video/*" = ["mpv.dekstop"];
"video/*" = ["mpv.desktop"];
"image/*" = ["imv.desktop"];
"application/json" = browser;
"application/pdf" = ["org.pwmt.zathura.desktop.desktop"];
-1
View File
@@ -16,7 +16,6 @@ in {
LESSHISTFILE = cache + "/less/history";
LESSKEY = c + "/less/lesskey";
WINEPREFIX = d + "/wine";
XAUTHORITY = "$XDG_RUNTIME_DIR/Xauthority";
# set default applications
EDITOR = "vim";
+973
View File
@@ -0,0 +1,973 @@
# Based on the default config generated by:
# ```
# config nu --doc
# ```
#
# Nushell Config File Documentation
#
# Warning: This file is intended for documentation purposes only and
# is not intended to be used as an actual configuration file as-is.
#
# version = "0.105.1"
#
# A `config.nu` file is used to override default Nushell settings,
# define (or import) custom commands, or run any other startup tasks.
# See https://www.nushell.sh/book/configuration.html
#
# Nushell sets "sensible defaults" for most configuration settings, so
# the user's `config.nu` only needs to override these defaults if
# desired.
#
# This file serves as simple "in-shell" documentation for these
# settings, or you can view a more complete discussion online at:
# https://nushell.sh/book/configuration
#
# You can pretty-print and page this file using:
# config nu --doc | nu-highlight | less -R
# $env.config
# -----------
# The $env.config environment variable is a record containing most Nushell
# configuration settings. Keep in mind that, as a record, setting it to a
# new record will remove any keys which aren't in the new record. Nushell
# will then automatically merge in the internal defaults for missing keys.
#
# The same holds true for keys in the $env.config which are also records
# or lists.
#
# For this reason, settings are typically changed by updating the value of
# a particular key. Merging a new config record is also possible. See the
# Configuration chapter of the book for more information.
# ------------------------
# History-related settings
# ------------------------
# $env.config.history.*
# file_format (string): Either "sqlite" or "plaintext". While text-backed history
# is currently the default for historical reasons, "sqlite" is stable and
# provides more advanced history features.
$env.config.history.file_format = "sqlite"
# max_size (int): The maximum number of entries allowed in the history.
# After exceeding this value, the oldest history items will be removed
# as new commands are added.
$env.config.history.max_size = 5_000_000
# sync_on_enter (bool): Whether the plaintext history file is updated
# each time a command is entered. If set to `false`, the plaintext history
# is only updated/written when the shell exits. This setting has no effect
# for SQLite-backed history.
$env.config.history.sync_on_enter = true
# isolation (bool):
# `true`: New history from other currently-open Nushell sessions is not
# seen when scrolling through the history using PrevHistory (typically
# the Up key) or NextHistory (Down key)
# `false`: All commands entered in other Nushell sessions will be mixed with
# those from the current shell.
# Note: Older history items (from before the current shell was started) are
# always shown.
# This setting only applies to SQLite-backed history
$env.config.history.isolation = true
# ----------------------
# Miscellaneous Settings
# ----------------------
# show_banner (bool): Enable or disable the welcome banner at startup
$env.config.show_banner = true
# rm.always_trash (bool):
# true: rm behaves as if the --trash/-t option is specified
# false: rm behaves as if the --permanent/-p option is specified (default)
# Explicitly calling `rm` with `--trash` or `--permanent` always override this setting
# Note that this feature is dependent on the host OS trashcan support.
$env.config.rm.always_trash = false
# recursion_limit (int): how many times a command can call itself recursively
# before an error will be generated.
$env.config.recursion_limit = 50
# ---------------------------
# Commandline Editor Settings
# ---------------------------
# edit_mode (string) "vi" or "emacs" sets the editing behavior of Reedline
$env.config.edit_mode = "emacs"
# Command that will be used to edit the current line buffer with Ctrl+O.
# If unset, uses $env.VISUAL and then $env.EDITOR
#
# Tip: Set to "editor" to use the default editor on Unix platforms using
# the Alternatives system or equivalent
$env.config.buffer_editor = "editor"
# To set arguments for the editor, a list can be used:
$env.config.buffer_editor = ["emacsclient", "-s", "light", "-t"]
# cursor_shape_* (string)
# -----------------------
# The following variables accept a string from the following selections:
# "block", "underscore", "line", "blink_block", "blink_underscore", "blink_line", or "inherit"
# "inherit" skips setting cursor shape and uses the current terminal setting.
$env.config.cursor_shape.emacs = "inherit" # Cursor shape in emacs mode
$env.config.cursor_shape.vi_insert = "block" # Cursor shape in vi-insert mode
$env.config.cursor_shape.vi_normal = "underscore" # Cursor shape in normal vi mode
# --------------------
# Completions Behavior
# --------------------
# $env.config.completions.*
# Apply to the Nushell completion system
# algorithm (string): "prefix", "substring" or "fuzzy"
$env.config.completions.algorithm = "prefix"
# sort (string): One of "smart" or "alphabetical"
# In "smart" mode sort order is based on the "algorithm" setting.
# When using the "prefix" algorithm, results are alphabetically sorted.
# When using the "substring" algorithm, results are alphabetically sorted.
# When using the "fuzzy" algorithm, results are sorted based on their fuzzy score.
$env.config.completions.sort = "smart"
# case_sensitive (bool): true/false to enable/disable case-sensitive completions
$env.config.completions.case_sensitive = false
# quick (bool):
# true: auto-select the completion when only one remains
# false: prevents auto-select of the final result
$env.config.completions.quick = true
# partial (bool):
# true: Partially complete up to the best possible match
# false: Do not partially complete
# Partial Example: If a directory contains only files named "forage", "food", and "forest",
# then typing "ls " and pressing <Tab> will partially complete the first two
# letters, "f" and "o". If the directory also includes a file named "faster",
# then only "f" would be partially completed.
$env.config.completions.partial = true
# use_ls_colors (bool): When true, apply LS_COLORS to file/path/directory matches
$env.config.completions.use_ls_colors = true
# --------------------
# External Completions
# --------------------
# completions.external.*: Settings related to completing external commands
# and additional completers
# external.enable (bool)
# true: search for external commands on the Path
# false: disabling might be desired for performance if your path includes
# directories on a slower filesystem
$env.config.completions.external.enable = true
# max_results (int): Limit the number of external commands retrieved from
# path to this value. Has no effect if `...external.enable` (above) is set to `false`
$env.config.completions.external.max_results = 50
# completer (closure with a |spans| parameter): A command to call for *argument* completions
# to commands (internal or external).
#
# The |spans| parameter is a list of strings representing the tokens (spans)
# on the current commandline. It is always a list of at least two strings - The
# command being completed plus the first argument of that command ("" if no argument has
# been partially typed yet), and additional strings for additional arguments beyond
# the first.
#
# This setting is usually set to a closure which will call a third-party completion system, such
# as Carapace.
#
# Note: The following is an over-simplified completer command that will call Carapace if it
# is installed. Please use the official Carapace completer, which can be generated automatically
# by Carapace itself. See the Carapace documentation for the proper syntax.
$env.config.completions.external.completer = {|spans|
carapace $spans.0 nushell ...$spans | from json
}
# --------------------
# Terminal Integration
# --------------------
# Nushell can output a number of escape codes to enable advanced features in Terminal Emulators
# that support them. Settings in this section enable or disable these features in Nushell.
# Features aren't supported by your Terminal can be disabled. Features can also be disabled,
# of course, if there is a conflict between the Nushell and Terminal's implementation.
# use_kitty_protocol (bool):
# A keyboard enhancement protocol supported by the Kitty Terminal. Additional keybindings are
# available when using this protocol in a supported terminal. For example, without this protocol,
# Ctrl+I is interpreted as the Tab Key. With this protocol, Ctrl+I and Tab can be mapped separately.
$env.config.use_kitty_protocol = false
# osc2 (bool):
# When true, the current directory and running command are shown in the terminal tab/window title.
# Also abbreviates the directory name by prepending ~ to the home directory and its subdirectories.
$env.config.shell_integration.osc2 = true
# osc7 (bool):
# Nushell will report the current directory to the terminal using OSC 7. This is useful when
# spawning new tabs in the same directory.
# This is disabled by default on Windows in favor of the `osc9_9` option.
$env.config.shell_integration.osc7 = true
# osc9_9 (bool):
# Enables/Disables OSC 9;9 support, originally a ConEmu terminal feature. This is an
# alternative to OSC 7 which also communicates the current path to the terminal.
# This is enabled by default on Windows as it is used by the Windows Terminal.
$env.config.shell_integration.osc9_9 = false
# osc8 (bool):
# When true, the `ls` command will generate clickable links that can be launched in another
# application by the terminal.
# Note: This setting replaces the now deprecated `ls.clickable_links`
$env.config.shell_integration.osc8 = true
# Deprecated
# $env.config.ls.clickable_links = true
# osc133 (bool):
# true/false to enable/disable OSC 133 support, a set of several escape sequences which
# report the (1) starting location of the prompt, (2) ending location of the prompt,
# (3) starting location of the command output, and (4) the exit code of the command.
# originating with Final Term. These sequences report information regarding the prompt
# location as well as command status to the terminal. This enables advanced features in
# some terminals, including the ability to provide separate background colors for the
# command vs. the output, collapsible output, or keybindings to scroll between prompts.
$env.config.shell_integration.osc133 = true
# osc633 (bool):
# true/false to enable/disable OSC 633, an extension to OSC 133 for Visual Studio Code
$env.config.shell_integration.osc633 = true
# reset_application_mode (bool):
# true/false to enable/disable sending ESC[?1l to the terminal
# This sequence is commonly used to keep cursor key modes in sync between the local
# terminal and a remote SSH host.
$env.config.shell_integration.reset_application_mode = true
# bracketed_paste (bool):
# true/false to enable/disable the bracketed-paste feature, which allows multiple-lines
# to be pasted into Nushell at once without immediate execution. When disabled,
# each pasted line is executed as it is received.
# Note that bracketed paste is not currently supported on the Windows version of
# Nushell.
$env.config.bracketed_paste = true
# use_ansi_coloring ("auto" or bool):
# The default value `"auto"` dynamically determines if ANSI coloring is used.
# It evaluates the following environment variables in decreasingly priority:
# `FORCE_COLOR`, `NO_COLOR`, and `CLICOLOR`.
# - If `FORCE_COLOR` is set, coloring is always enabled.
# - If `NO_COLOR` is set, coloring is disabled.
# - If `CLICOLOR` is set, its value (0 or 1) decides whether coloring is used.
# If none of these are set, it checks whether the standard output is a terminal
# and enables coloring if it is.
# A value of `true` or `false` overrides this behavior, explicitly enabling or
# disabling ANSI coloring in Nushell's internal commands.
# When disabled, built-in commands will only use the default foreground color.
# Note: This setting does not affect the `ansi` command.
$env.config.use_ansi_coloring = "auto"
# ----------------------
# Error Display Settings
# ----------------------
# error_style (string): One of "fancy" or "plain"
# Plain: Display plain-text errors for screen-readers
# Fancy: Display errors using line-drawing characters to point to the span in which the
# problem occurred.
$env.config.error_style = "fancy"
# display_errors.exit_code (bool):
# true: Display a Nushell error when an external command returns a non-zero exit code
# false: Display only the error information printed by the external command itself
# Note: Core dump errors are always printed; SIGPIPE never triggers an error
$env.config.display_errors.exit_code = false
# display_errors.termination_signal (bool):
# true/false to enable/disable displaying a Nushell error when a child process is
# terminated via any signal
$env.config.display_errors.termination_signal = true
# -------------
# Table Display
# -------------
# footer_mode (string or int):
# Specifies when to display table footers with column names. Allowed values:
# "always"
# "never"
# "auto": When the length of the table would scroll the header past the first line of the terminal
# (int): When the number of table rows meets or exceeds this value
# Note: Does not take into account rows with multiple lines themselves
$env.config.footer_mode = 25
# table.*
# mode (string):
# Specifies the visual display style of a table
# One of: "default", "basic", "compact", "compact_double", "heavy", "light", "none", "reinforced",
# "rounded", "thin", "with_love", "psql", "markdown", "dots", "restructured", "ascii_rounded",
# "basic_compact" or "single"
# Can be overridden by passing a table to `| table --theme/-t`
$env.config.table.mode = "default"
# index_mode (string) - One of:
# "never": never show the index column in a table or list
# "always": always show the index column in tables and lists
# "auto": show the column only when there is an explicit "index" column in the table
# Can be overridden by passing a table to `| table --index/-i`
$env.config.table.index_mode = "always"
# show_empty (bool):
# true: show "empty list" or "empty table" when no values exist
# false: display no output when no values exist
$env.config.table.show_empty = true
# padding.left/right (int): The number of spaces to pad around values in each column
$env.config.table.padding.left = 1
$env.config.table.padding.right = 1
# trim.*: The rules that will be used to display content in a table row when it would cause the
# table to exceed the terminal width.
# methodology (string): One of "wrapping" or "truncating"
# truncating_suffix (string): The text to show at the end of the row to indicate that it has
# been truncated. Only valid when `methodology = "truncating"`.
# wrapping_try_keep_words (bool): true to keep words together based on whitespace
# false to allow wrapping in the middle of a word.
# Only valid when `methodology = wrapping`.
$env.config.table.trim = {
methodology: "wrapping"
wrapping_try_keep_words: true
}
# or
$env.config.table.trim = {
methodology: "truncating"
truncating_suffix: "..."
}
# header_on_separator (bool):
# true: Displays the column headers as part of the top (or bottom) border of the table
# false: Displays the column header in its own row with a separator below.
$env.config.table.header_on_separator = false
# abbreviated_row_count (int or nothing):
# If set to an int, all tables will be abbreviated to only show the first <n> and last <n> rows
# If set to `null`, all table rows will be displayed
# Can be overridden by passing a table to `| table --abbreviated/-a`
$env.config.table.abbreviated_row_count = null
# footer_inheritance (bool): Footer behavior in nested tables
# true: If a nested table is long enough on its own to display a footer (per `footer_mode` above),
# then also display the footer for the parent table
# false: Always apply `footer_mode` rules to the parent table
$env.config.table.footer_inheritance = false
# missing_value_symbol (string): The symbol shown for missing values
$env.config.table.missing_value_symbol = "❎"
# ----------------
# Datetime Display
# ----------------
# datetime_format.* (string or nothing):
# Format strings that will be used for datetime values.
# When set to `null`, the default behavior is to "humanize" the value (e.g., "now" or "a day ago")
# datetime_format.table (string or nothing):
# The format string (or `null`) that will be used to display a datetime value when it appears in a
# structured value such as a table, list, or record.
$env.config.datetime_format.table = null
# datetime_format.normal (string or nothing):
# The format string (or `null`) that will be used to display a datetime value when it appears as
# a raw value.
$env.config.datetime_format.normal = "%m/%d/%y %I:%M:%S%p"
# ----------------
# Filesize Display
# ----------------
# filesize.unit (string): One of either:
# - A filesize unit: "B", "kB", "KiB", "MB", "MiB", "GB", "GiB", "TB", "TiB", "PB", "PiB", "EB", or "EiB".
# - An automatically scaled unit: "metric" or "binary".
# "metric" will use units with metric (SI) prefixes like kB, MB, or GB.
# "binary" will use units with binary prefixes like KiB, MiB, or GiB.
# Otherwise, setting this to one of the filesize units will use that particular unit when displaying all file sizes.
$env.config.filesize.unit = 'metric'
# filesize.show_unit (bool):
# Whether to show or hide the file size unit. Useful if `$env.config.filesize.unit` is set to a fixed unit,
# and you don't want that same unit repeated over and over again in which case you can set this to `false`.
$env.config.filesize.show_unit = true
# filesize.precision (int or nothing):
# The number of digits to display after the decimal point for file sizes.
# When set to `null`, all digits after the decimal point, if any, will be displayed.
$env.config.filesize.precision = 1
# ---------------------
# Miscellaneous Display
# ---------------------
# render_right_prompt_on_last_line(bool):
# true: When using a multi-line left-prompt, the right-prompt will be displayed on the last line
# false: The right-prompt is displayed on the first line of the left-prompt
$env.config.render_right_prompt_on_last_line = false
# float_precision (int):
# Float values will be rounded to this precision when displaying in structured values such as lists,
# tables, or records.
$env.config.float_precision = 2
# ls.use_ls_colors (bool):
# true: The `ls` command will apply the $env.LS_COLORS standard to filenames
# false: Filenames in the `ls` table will use the color_config for strings
$env.config.ls.use_ls_colors = true
# Hooks
# -----
# $env.config.hooks is a record containing the five different types of Nushell hooks.
# See the Hooks documentation at https://www.nushell.sh/book/hooks for details
#
# Most hooks can accept a string, a closure, or a list containing strings and/or closures.
# The display_output record can only accept a string or a closure, but never a list
#
# WARNING: A malformed display_output hook can suppress all Nushell output to the terminal.
# It can be reset by assigning an empty string as below:
# Before each prompt is displayed
$env.config.hooks.pre_prompt = []
# After <enter> is pressed; before the commandline is executed
$env.config.hooks.pre_execution = []
# When a specified environment variable changes
$env.config.hooks.env_change = {
# Example: Run if the PWD environment is different since the last REPL input
PWD: [{|before, after| null }]
}
# Before Nushell output is displayed in the terminal
$env.config.hooks.display_output = "if (term size).columns >= 100 { table -e } else { table }"
# When a command is not found
$env.config.hooks.command_not_found = []
# The env_change hook accepts a record with environment variable names as keys, and a list
# of hooks to run when that variable changes
$env.config.hooks.env_change = {}
# -----------
# Keybindings
# -----------
# keybindings (list): A list of user-defined keybindings
# Nushell/Reedline keybindings can be added or overridden using this setting.
# See https://www.nushell.sh/book/line_editor.html#keybindings for details.
#
# Example - Add a new Alt+. keybinding to insert the last token used on the previous commandline
$env.config.keybindings ++= [
{
name: insert_last_token
modifier: alt
keycode: char_.
mode: [emacs vi_normal vi_insert]
event: [
{ edit: InsertString, value: "!$" }
{ send: Enter }
]
}
]
# Example: Override the F1 keybinding with a user-defined help menu (see "Menus" below):
$env.config.keybindings ++= [
{
name: help_menu
modifier: none
keycode: f1
mode: [emacs, vi_insert, vi_normal]
event: { send: menu name: help_menu }
}
]
# -----
# Menus
# -----
# menus (list):
#
# Nushell/Reedline menus can be created and modified using this setting.
# See https://www.nushell.sh/book/line_editor.html#menus for details.
#
# Note that menus are usually activated via keybindings, which are defined in
# $env.config.keybindings (above).
#
# Simple example - Add a new Help menu to the list (note that a similar menu is already
# defined internally):
$env.config.menus ++= [
{
name: help_menu
only_buffer_difference: true
marker: "? "
type: {
layout: description
columns: 4
# col_width is an optional value. If missing, the entire screen width is used to
# calculate the column width
col_width: 20
col_padding: 2
selection_rows: 4
description_rows: 10
}
style: {
text: green
selected_text: green_reverse
description_text: yellow
}
}
]
# ---------------
# Plugin behavior
# ---------------
# Per-plugin configuration. See https://www.nushell.sh/contributor-book/plugins.html#plugin-configuration
$env.config.plugins = {}
# Plugin garbage collection configuration
# $env.config.plugin_gc.*
# enabled (bool): true/false to enable/disable stopping inactive plugins
$env.config.plugin_gc.default.enabled = true
# stop_after (duration): How long to wait after a plugin is inactive before stopping it
$env.config.plugin_gc.default.stop_after = 10sec
# plugins (record): Alternate garbage collection configuration per-plugin.
$env.config.plugin_gc.plugins = {
# gstat: {
# enabled: false
# }
}
# -------------------------------------
# Themes/Colors and Syntax Highlighting
# -------------------------------------
# For more information on defining custom themes, see
# https://www.nushell.sh/book/coloring_and_theming.html
# Use and/or contribute to the theme collection at
# https://github.com/nushell/nu_scripts/tree/main/themes
# Values:
# highlight_resolved_externals (bool):
# true: Applies the `color_config.shape_external_resolved` color (below) to external commands
# which are found (resolved) on the path
# false: Applies the `color_config.shape_external` color to *all* externals simply based on whether
# or not they would be *parsed* as an external command based on their position.
# Defaults to false for systems with a slower search path
$env.config.highlight_resolved_externals = true
# color_config (record): A record of shapes, types, UI elements, etc. that can be styled (e.g.,
# colorized) in Nushell, either on the commandline itself (shapes) or in output.
#
# Note that this is usually set through a theme provided by a record in a custom command. For
# instance, the standard library contains two "starter" theme commands: "dark-theme" and
# "light-theme". For example:
use std/config dark-theme
$env.config.color_config = (dark-theme)
# Or, individual color settings can be configured or overridden.
#
# Values can be one of:
# - A color name such as "red" (see `ansi -l` for a list)
# - A color RGB value in the form of "#C4C9C6"
# - A record including:
# * `fg` (color)
# * `bg` (color)
# * `attr`: a string with one or more of:
# - 'n': normal
# - 'b': bold
# - 'u': underline
# - 'r': reverse
# - 'i': italics
# - 'd': dimmed
# foreground, background, and cursor colors are not handled by Nushell, but can be used by
# custom-commands such as `theme` from the nu_scripts repository. That `theme` command can be
# used to set the terminal foreground, background, and cursor colors.
$env.config.color_config.foreground
$env.config.color_config.background
$env.config.color_config.cursor
# -------------------------------------------------------------------------------------------------
# shape_: Applies syntax highlighting based on the "shape" (inferred or declared type) of an
# element on the commandline. Nushell's parser can identify shapes based on many criteria, often
# as the commandline is being typed.
# shape_string: Can appear as a single-or-quoted value, a bareword string, the key of a record,
# an argument which has been declared as a string, and other parsed strings.
$env.config.color_config.shape_string
# shape_string_interpolation: A single-or-double-quoted string interpolation. This style
# applies to the dollar sign and quotes of the string. The elements inside the string are
# styled according to their own shape.
$env.config.color_config.shape_string_interpolation
# shape_raw_string: a raw string literal. E.g., r#'This is a raw string'#. This style applies
# to the entire raw string.
$env.config.color_config.shape_raw_string
# shape_record: A record-literal. This style applies to the brackets around the record. The keys
# and values will be styled according to their individual shapes.
$env.config.color_config.shape_record
# shape_list: A list-literal. This style applies to the brackets and list separator only. The
# items in a list are styled according to their individual shapes.
$env.config.color_config.shape_list
# shape_table: A table-literl. Color applies to the brackets, semicolon, and list separators. The
# items in the table are style according to their individual shapes.
$env.config.color_config.shape_table
# shape_bool: A boolean-literal `true` or `false` value
$env.config.color_config.shape_bool
# shape_int: Integer literals
$env.config.color_config.shape_int
# shape_float: Float literals. E.g., 5.4
# Also integer literals in a float-argument position
$env.config.color_config.shape_float
# shape_range: Range literals
$env.config.color_config.shape_range
# shape_binary: Binary literals
$env.config.color_config.shape_binary
# shape_datetime: Datetime literals
$env.config.color_config.shape_datetime
# shape_custom: A custom value, usually from a plugin
$env.config.color_config.shape_custom
# shape_nothing: A literal `null`
$env.config.color_config.shape_nothing
# shape_literal: Not currently used
$env.config.color_config.shape_literal
# shape_operator: An operator such as +, -, ++, in, not-in, etc.
$env.config.color_config.shape_operator
# shape_filepath: An argument that appears in the position of a `path` shape for a command
$env.config.color_config.shape_filepath
# shape_directory: A more specific 'path' shape that only accepts a directory.
$env.config.color_config.shape_directory
# shape_globpattern: An argument in the position of a glob parameter. E.g., the asterisk (or any other string) in `ls *`.
$env.config.color_config.shape_globpattern
# shape_glob_interpolation: Deprecated
$env.config.color_config.shape_glob_interpolation
# shape_garbage: When an argument is of the wrong type or cannot otherwise be parsed.
# E.g., `ls {a: 5}` - A record argument to `ls` is 'garbage'. Also applied in real-time when
# an expression is not (yet) properly closed.
$env.config.color_config.shape_garbage
# shape_variable: The *use* of a variable. E.g., `$env` or `$a`.
$env.config.color_config.shape_variable
# shape_vardecl: The *declaration* of a variable. E.g. the "a" in `let a = 5`.
$env.config.color_config.shape_vardecl
# shape_matching_brackets: When the cursor is positioned on an opening or closing bracket (e.g,
# braces, curly braces, or parenthesis), and there is a matching opening/closing bracket, both will
# temporarily have this style applied.
$env.config.color_config.shape_matching_brackets
# shape_pipe: The pipe `|` when used to separate expressions in a pipeline
$env.config.color_config.shape_pipe
# shape_internalcall: A known Nushell built-in or custom command in the "command position" (usually
# the first bare word of an expression).
$env.config.color_config.shape_internalcall
# shape_external: A token in the "command position" (see above) that is not a known Nushell
# built-in or custom command. This is assumed to be an external command.
$env.config.color_config.shape_external
# shape_external_resolved: Requires "highlight_resolved_externals" (above) to be enabled.
# When a token matches the "external" requirement (above) and is also a *confirmed* external
# command, this style will be applied.
$env.config.color_config.shape_external_resolved
# shape_externalarg: Arguments to an external command (whether resolved or not)
$env.config.color_config.shape_externalarg
# shape_match_pattern: The matching pattern for each arm in a match expression. Does not
# include the guard expression (if present).
$env.config.color_config.shape_match_pattern
# shape_block: The curly-braces around a block. Expressions within the block will have their
# their own shapes' styles applied.
$env.config.color_config.shape_block
# shape_signature: The parameter definitions and input/output types for a command signature.
$env.config.color_config.shape_signature
# shape_keyword: Not current used
$env.config.color_config.shape_keyword
# shape_closure: Styles the brackets and arguments of a closure.
$env.config.color_config.shape_closure
# shape_direction: The redirection symbols such as `o>`, `error>`, `e>|`, etc.
$env.config.color_config.shape_redirection
# shape_flag: Flags and switches to internal and custom-commands. Only the `--flag` (`-f`) portion
# is styled. The argument to a flag will be styled using its own shape.
$env.config.color_config.shape_flag
# -------------------------------------------------------------------------------------------------
# color.config.<type>
# *Values* of a particular *type* can be styled differently than the *shape*.
# Note that the style is applied only when this type is displayed in *structured* data (list,
# record, or table). It is not currently applied to basic raw values.
#
# Note that some types are rarely or never seen in a context in which styling would be applied.
# For example, a cell-path *value* is unlikely to (but can) appear in a list, record, or table.
#
# Tip: In addition to the styles above (fg, bg, attr), types typically accept a closure which can
# dynamically change the style based on the *value*. For instance, the themes in the nu_scripts
# repository will style filesizes difference in an `ls` (or other table) differently depending on
# their magnitude.
# Simple examples:
# bool: A boolean value
$env.config.color_config.bool = {||
if $in {
{
bg: 'light_green'
fg: 'white'
attr: 'b'
}
} else {
{
bg: 'yellow'
fg: 'black'
attr: 'b'
}
}
}
# int: An integer value
$env.config.color_config.int = {||
if $in == 42 { 'green' } else { 'red' }
}
# Additional type values (without examples):
$env.config.color_config.string # String
$env.config.color_config.float # Float value
$env.config.color_config.glob # Glob value (must be declared)
$env.config.color_config.binary # Binary value
$env.config.color_config.custom # Custom value (often from a plugin)
$env.config.color_config.nothing # Not used, since a null is not displayed
$env.config.color_config.date # datetime value
$env.config.color_config.filesize # filesize value
$env.config.color_config.list # Not currently used. Lists are displayed using their
# members' styles
$env.config.color_config.record # Not currently used. Records are displayed using their
# member's styles
$env.config.color_config.duration # Duration type
$env.config.color_config.range # Range value
$env.config.color_config.cell-path # Cell-path value
$env.config.color_config.closure # Not currently used
$env.config.color_config.block # Not currently used
# Additional UI elements
# hints: The (usually dimmed) style in which completion hints are displayed
$env.config.color_config.hints
# search_result: The style applied to `find` search results
$env.config.color_config.search_result
# header: The column names in a table header
$env.config.color_config.header
# separator: Used for table/list/record borders
$env.config.color_config.separator
# row_index: The `#` or `index` column of a table or list
$env.config.color_config.row_index
# empty: This style is applied to empty/missing values in a table. However, since the ❎
# emoji is used for this purpose, there is limited styling that can be applied.
$env.config.color_config.empty
# leading_trailing_space_bg: When a string value inside structured data has leading or trailing
# whitespace, that whitespace will be displayed using this style.
# Use { attr: n } to disable.
$env.config.color_config.leading_trailing_space_bg = { bg: 'red' }
# banner_foreground: The default text style for the Welcome Banner displayed at startup
$env.config.color_config.banner_foreground = "attr_normal"
# banner_highlight1 and banner_highlight2: Colors for highlighted text in the Welcome Banner
$env.config.color_config.banner_highlight1 = "green"
$env.config.color_config.banner_highlight2 = "purple"
# ------------------------
# `explore` command colors
# ------------------------
# Configure the UI colors of the `explore` command
# Allowed values are the same as for the `color_config` options above.
# Example:
$env.config.explore = {
status_bar_background: { fg: "#1D1F21", bg: "#C4C9C6" },
command_bar_text: { fg: "#C4C9C6" },
highlight: { fg: "black", bg: "yellow" },
status: {
error: { fg: "white", bg: "red" },
warn: {}
info: {}
},
selected_cell: { bg: light_blue },
}
# ---------------------------------------------------------------------------------------
# Environment Variables
# ---------------------------------------------------------------------------------------
# In addition to the $env.config record, a number of other environment variables
# also affect Nushell's behavior:
# PROMPT_*
# --------
# Prompt configuration
# PROMPT_ variables accept either a string or a closure that returns a string
# PROMPT_COMMAND
# --------------
# Defines the primary prompt. Note that the PROMPT_INDICATOR (below) is appended to this value.
# Simple example - Static string:
$env.PROMPT_COMMAND = "Nushell"
# Simple example - Dynamic closure displaying the path:
$env.PROMPT_COMMAND = {|| pwd}
# PROMPT_COMMAND_RIGHT
# --------------------
# Defines a prompt which will appear right-aligned in the terminal
$env.PROMPT_COMMAND_RIGHT = {|| date now | format date "%d-%a %r" }
# PROMPT_INDICATOR*
# -----------------
# The prompt indicators are environmental variables that represent
# the state of the prompt. The specified character(s) will appear
# immediately following the PROMPT_COMMAND
# When in Emacs mode (default):
$env.PROMPT_INDICATOR = "> "
# When in normal vi mode:
$env.PROMPT_INDICATOR_VI_NORMAL = "> "
# When in vi insert-mode:
$env.PROMPT_INDICATOR_VI_INSERT = ": "
# When a commandline extends across multiple lines:
$env.PROMPT_MULTILINE_INDICATOR = "::: "
# TRANSIENT_PROMPT_*
# ------------------
# Allows a different prompt to be shown after a command has been executed. This
# can be useful if you have a 2-line prompt. Instead of each previously-entered
# command taking up at least 2 lines, the transient prompt can condense it to a
# shorter version. The following example shows a rocket emoji before each
# previously-entered command:
$env.TRANSIENT_PROMPT_COMMAND = "🚀 "
$env.TRANSIENT_PROMPT_INDICATOR = ""
$env.TRANSIENT_PROMPT_INDICATOR_VI_INSERT = ""
$env.TRANSIENT_PROMPT_INDICATOR_VI_NORMAL = ""
# Tip: Removing the transient multiline indicator and right-prompt can simplify
# copying from the terminal
$env.TRANSIENT_PROMPT_MULTILINE_INDICATOR = ""
$env.TRANSIENT_PROMPT_COMMAND_RIGHT = ""
# ENV_CONVERSIONS
# ---------------
# Certain variables, such as those containing multiple paths, are often stored as a
# colon-separated string in other shells. Nushell can convert these automatically to a
# more convenient Nushell list. The ENV_CONVERSIONS variable specifies how environment
# variables are:
# - converted from a string to a value on Nushell startup (from_string)
# - converted from a value back to a string when running external commands (to_string)
#
# Note: The OS Path variable is automatically converted before env.nu loads, so it can
# be treated a list in this file.
#
# Note: Environment variables are not case-sensitive, so the following will work
# for both Windows and Unix-like platforms.
#
# By default, the internal conversion looks something like the following, so there
# is no need to add this in your actual env.nu:
$env.ENV_CONVERSIONS = {
"Path": {
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
}
}
# Here's an example converts the XDG_DATA_DIRS variable to and from a list:
$env.ENV_CONVERSIONS = $env.ENV_CONVERSIONS | merge {
"XDG_DATA_DIRS": {
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
}
}
#
# Other common directory-lists for conversion: TERMINFO_DIRS.
# Note that other variable conversions take place after `config.nu` is loaded.
# NU_LIB_DIRS
# -----------
# Directories in this constant are searched by the
# `use` and `source` commands.
#
# By default, the `scripts` subdirectory of the default configuration
# directory is included:
const NU_LIB_DIRS = [
($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts
($nu.data-dir | path join 'completions') # default home for nushell completions
]
# You can replace (override) or append to this list by shadowing the constant
const NU_LIB_DIRS = $NU_LIB_DIRS ++ [($nu.default-config-dir | path join 'modules')]
# An environment variable version of this also exists. It is searched after the constant.
$env.NU_LIB_DIRS ++= [ ($nu.data-dir | path join "nu_scripts") ]
# NU_PLUGIN_DIRS
# --------------
# Directories to search for plugin binaries when calling add.
# By default, the `plugins` subdirectory of the default configuration
# directory is included:
const NU_PLUGIN_DIRS = [
($nu.default-config-dir | path join 'plugins') # add <nushell-config-dir>/plugins
]
# You can replace (override) or append to this list by shadowing the constant
const NU_PLUGIN_DIRS = $NU_PLUGIN_DIRS ++ [($nu.default-config-dir | path join 'plugins')]
# As with NU_LIB_DIRS, an $env.NU_PLUGIN_DIRS is searched after the constant version
# Appending to the OS path is a common configuration task.
# Because of the previous ENV_CONVERSIONS (performed internally
# before your config.nu loads), the path variable is a list that can
# be appended to using, for example:
$env.PATH ++= [ "~/.local/bin" ]
# Or prepend using
$env.PATH = [ "~/.local/bin" ] ++ $env.PATH
# The `path add` function from the Standard Library also provides
# a convenience method for prepending to the path:
use std/util "path add"
path add "~/.local/bin"
path add ($env.CARGO_HOME | path join "bin")
# You can remove duplicate directories from the path using:
$env.PATH = ($env.PATH | uniq)
-1
View File
@@ -2,6 +2,5 @@
programs.nushell = {
enable = true;
configFile.source = ./config.nu;
envFile.source = ./env.nu;
};
}
-36
View File
@@ -1,36 +0,0 @@
# Nushell Environment Config File
# Specifies how environment variables are:
# - converted from a string to a value on Nushell startup (from_string)
# - converted from a value back to a string when running external commands (to_string)
# Note: The conversions happen *after* config.nu is loaded
let-env ENV_CONVERSIONS = {
"PATH": {
from_string: { |s| $s | split row (char esep) | path expand -n }
to_string: { |v| $v | path expand -n | str join (char esep) }
}
"Path": {
from_string: { |s| $s | split row (char esep) | path expand -n }
to_string: { |v| $v | path expand -n | str join (char esep) }
}
}
# Directories to search for scripts when calling source or use
#
# By default, <nushell-config-dir>/scripts is added
let-env NU_LIB_DIRS = [
($nu.config-path | path dirname | path join 'scripts')
]
# Directories to search for plugin binaries when calling register
#
# By default, <nushell-config-dir>/plugins is added
let-env NU_PLUGIN_DIRS = [
($nu.config-path | path dirname | path join 'plugins')
]
# To add entries to PATH (on Windows you might use Path), you can use the following pattern:
# let-env PATH = ($env.PATH | split row (char esep) | prepend '/some/path')
mkdir ~/.cache/starship
starship init nu | sed "s/size -c/size/" | save ~/.cache/starship/init.nu
+3
View File
@@ -3,6 +3,9 @@
programs.starship = {
enable = true;
enableBashIntegration = true;
enableZshIntegration = true;
enableNushellIntegration = true;
settings = {
character = {
success_symbol = "[](bold green)";
-10
View File
@@ -1,10 +0,0 @@
{
...
}: {
imports =
[
./nixos-test
../modules/system.nix
../modules/i3.nix
];
}
+52
View File
@@ -0,0 +1,52 @@
# 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. Its 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 = "25.05"; # 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;
}
+13 -12
View File
@@ -1,14 +1,18 @@
# 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 =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
config,
pkgs,
...
}: {
imports = [
../../modules/system.nix
../../modules/i3.nix
# Include the results of the hardware scan.
./hardware-configuration.nix
];
# Bootloader.
boot.loader = {
@@ -18,7 +22,7 @@
# };
grub = {
enable = true;
device = "/dev/sda"; # "nodev"
device = "/dev/sda"; # "nodev"
efiSupport = false;
useOSProber = true;
#efiInstallAsRemovable = true; # in case canTouchEfiVariables doesn't work for your system
@@ -42,8 +46,5 @@
# 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?
system.stateVersion = "25.05"; # Did you read the comment?
}
+24 -28
View File
@@ -1,10 +1,7 @@
{pkgs, ...}:
{
{pkgs, ...}: {
# 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.displayManager.defaultSession = "none+i3";
services.xserver = {
enable = true;
@@ -13,36 +10,35 @@
};
displayManager = {
defaultSession = "none+i3";
lightdm.enable = false;
gdm.enable = true;
lightdm.enable = false;
gdm.enable = true;
};
windowManager.i3 = {
enable = true;
extraPackages = with pkgs; [
rofi # application launcher, the same as dmenu
dunst # notification daemon
i3blocks # status bar
i3lock # default i3 screen locker
xautolock # lock screen after some time
i3status # provide information to i3bar
i3-gaps # i3 with gaps
picom # transparency and shadows
feh # set wallpaper
acpi # battery information
arandr # screen layout manager
dex # autostart applications
xbindkeys # bind keys to commands
xorg.xbacklight # control screen brightness
xorg.xdpyinfo # get screen information
sysstat # get system information
];
rofi # application launcher, the same as dmenu
dunst # notification daemon
i3blocks # status bar
i3lock # default i3 screen locker
xautolock # lock screen after some time
i3status # provide information to i3bar
i3-gaps # i3 with gaps
picom # transparency and shadows
feh # set wallpaper
acpi # battery information
arandr # screen layout manager
dex # autostart applications
xbindkeys # bind keys to commands
xorg.xbacklight # control screen brightness
xorg.xdpyinfo # get screen information
sysstat # get system information
];
};
# Configure keymap in X11
layout = "us";
xkbVariant = "";
xkb.layout = "us";
xkb.variant = "";
};
# thunar file manager(part of xfce) related options
+68 -32
View File
@@ -1,6 +1,53 @@
{ config, pkgs, ... }:
{
pkgs,
lib,
username,
...
}: {
# ============================= User related =============================
# Define a user account. Don't forget to set a password with passwd.
users.users.${username} = {
isNormalUser = true;
description = username;
extraGroups = ["networkmanager" "wheel"];
};
# given the users in this list the right to specify additional substituters via:
# 1. `nixConfig.substituers` in `flake.nix`
# 2. command line args `--options substituers http://xxx`
nix.settings.trusted-users = [username];
# customise /etc/nix/nix.conf declaratively via `nix.settings`
nix.settings = {
# enable flakes globally
experimental-features = ["nix-command" "flakes"];
substituters = [
# cache mirror located in China
# status: https://mirror.sjtu.edu.cn/
"https://mirror.sjtu.edu.cn/nix-channels/store"
# status: https://mirrors.ustc.edu.cn/status/
# "https://mirrors.ustc.edu.cn/nix-channels/store"
"https://cache.nixos.org"
];
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
];
builders-use-substitutes = true;
};
# do garbage collection weekly to keep disk usage low
nix.gc = {
automatic = lib.mkDefault true;
dates = lib.mkDefault "weekly";
options = lib.mkDefault "--delete-older-than 7d";
};
# Allow unfree packages
nixpkgs.config.allowUnfree = true;
# Set your time zone.
time.timeZone = "Asia/Shanghai";
@@ -22,32 +69,35 @@
# Enable CUPS to print documents.
services.printing.enable = true;
fonts = {
fonts = with pkgs; [
packages = with pkgs; [
# icon fonts
material-design-icons
# normal fonts
noto-fonts
noto-fonts-cjk
noto-fonts-cjk-sans
noto-fonts-emoji
# nerdfonts
(nerdfonts.override { fonts = [ "FiraCode" "JetBrainsMono" ]; })
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable-small/pkgs/data/fonts/nerd-fonts/manifests/fonts.json
nerd-fonts.symbols-only # symbols icon only
nerd-fonts.fira-code
nerd-fonts.jetbrains-mono
nerd-fonts.iosevka
];
# use fonts specified by user rather than default ones
enableDefaultFonts = false;
enableDefaultPackages = false;
# user defined fonts
# the reason there's Noto Color Emoji everywhere is to override DejaVu's
# B&W emojis that would sometimes show instead of some Color emojis
fontconfig.defaultFonts = {
serif = [ "Noto Serif" "Noto Color Emoji" ];
sansSerif = [ "Noto Sans" "Noto Color Emoji" ];
monospace = [ "JetBrainsMono Nerd Font" "Noto Color Emoji" ];
emoji = [ "Noto Color Emoji" ];
serif = ["Noto Serif" "Noto Color Emoji"];
sansSerif = ["Noto Sans" "Noto Color Emoji"];
monospace = ["JetBrainsMono Nerd Font" "Noto Color Emoji"];
emoji = ["Noto Color Emoji"];
};
};
@@ -63,15 +113,12 @@
enable = true;
settings = {
X11Forwarding = true;
PermitRootLogin = "no"; # disable root login
PermitRootLogin = "no"; # disable root login
PasswordAuthentication = false; # disable password login
};
openFirewall = true;
};
# Allow unfree packages
nixpkgs.config.allowUnfree = true;
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs; [
@@ -80,25 +127,24 @@
curl
git
sysstat
lm_sensors # for `sensors` command
lm_sensors # for `sensors` command
# minimal screen capture tool, used by i3 blur lock to take a screenshot
# print screen key is also bound to this tool in i3 config
scrot
neofetch
xfce.thunar # xfce4's file manager
nnn # terminal file manager
xfce.thunar # xfce4's file manager
nnn # terminal file manager
];
# Enable sound with pipewire.
sound.enable = true;
hardware.pulseaudio.enable = false;
services.pulseaudio.enable = false;
services.power-profiles-daemon = {
enable = true;
};
security.polkit.enable = true;
services = {
dbus.packages = [ pkgs.gcr ];
dbus.packages = [pkgs.gcr];
geoclue2.enable = true;
@@ -115,16 +161,6 @@
#media-session.enable = true;
};
udev.packages = with pkgs; [ gnome.gnome-settings-daemon ];
};
# Define a user account. Don't forget to set a password with passwd.
users.users.ryan = {
isNormalUser = true;
description = "ryan";
extraGroups = [ "networkmanager" "wheel" ];
openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJx3Sk20pLL1b2PPKZey2oTyioODrErq83xG78YpFBoj admin@ryan-MBP"
];
udev.packages = with pkgs; [gnome-settings-daemon];
};
}
+22
View File
@@ -0,0 +1,22 @@
{pkgs, ...}: {
##################################################################################################################
#
# All Ryan's Home Manager Configuration
#
##################################################################################################################
imports = [
../../home/core.nix
../../home/fcitx5
../../home/i3
../../home/programs
../../home/rofi
../../home/shell
];
programs.git = {
userName = "Ryan Yin";
userEmail = "xiaoyin_c@qq.com";
};
}
+14
View File
@@ -0,0 +1,14 @@
{
##################################################################################################################
#
# NixOS Configuration
#
##################################################################################################################
users.users.ryan = {
# Ryan's authorizedKeys
openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJx3Sk20pLL1b2PPKZey2oTyioODrErq83xG78YpFBoj ryan@ryan"
];
};
}
+22
View File
@@ -0,0 +1,22 @@
{pkgs, ...}: {
##################################################################################################################
#
# All Suzi's Home Manager Configuration
#
##################################################################################################################
imports = [
../../home/core.nix
./fcitx5
./i3
./programs
./rofi
./shell
];
programs.git = {
userName = "Suzi";
userEmail = "suzi@writefor.fun";
};
}
+14
View File
@@ -0,0 +1,14 @@
{
##################################################################################################################
#
# NixOS Configuration
#
##################################################################################################################
users.users.suzi = {
# Suzi's authorizedKeys
openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJx3Sk20pLL1b2PPKZey2oTyioODrErq83xG78YpFBoj suzi@suzi"
];
};
}