feat: nixos configs & docs

This commit is contained in:
Ryan Yin
2023-04-23 01:30:45 +08:00
committed by ryan4yin
parent 13efbb259e
commit 699f541539
74 changed files with 16056 additions and 1 deletions

471
Nix_Flake_Basics.md Normal file
View File

@@ -0,0 +1,471 @@
# 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

View File

@@ -1 +1,33 @@
# nix-config
# Nix Configuration
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
- [Nix Flake Basics](./Nix_Flake_Basics.md)

117
flake.lock generated Normal file
View File

@@ -0,0 +1,117 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"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",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1682176386,
"narHash": "sha256-xwYjQ8PjfdHlggi8Dq0PXWby/1oXegSUuNuBvoTcnpA=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "6169690ae38175295605d521bd778d999fbd85cd",
"type": "github"
},
"original": {
"owner": "nix-community",
"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=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "645bc49f34fa8eff95479f0345ff57e55b53437e",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"home-manager": "home-manager",
"nix-vscode-extensions": "nix-vscode-extensions",
"nixpkgs": "nixpkgs_2"
}
}
},
"root": "root",
"version": 7
}

93
flake.nix Normal file
View File

@@ -0,0 +1,93 @@
{
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/"
];
# nix community's cache server
extra-substituters = [
"https://nix-community.cachix.org"
];
extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};
# 这是 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 版本不一致导致问题
home-manager.inputs.nixpkgs.follows = "nixpkgs";
# vscode 插件库
nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions";
};
# outputs 的参数都是 inputs 中定义的依赖项,可以通过它们的名称来引用。
# 不过 self 是个例外,这个特殊参数指向 outputs 自身(自引用),以及 flake 根目录
# 这里的 @ 语法将函数的参数 attribute set 取了个别名,方便在内部使用
outputs = inputs@{
self,
nixpkgs,
home-manager,
nix-vscode-extensions,
...
}: {
# 名为 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";
# 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
# 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 的配置
# packages.x86_64-linux.default =
};
};
}

32
home/default.nix Normal file
View File

@@ -0,0 +1,32 @@
{ config, pkgs, ... }:
{
imports = [
./fcitx5
./i3
./programs
./rofi
./shell
];
# Home Manager needs a bit of information about you and the
# paths it should manage.
home = {
username = "ryan";
homeDirectory = "/home/ryan";
# This value determines the Home Manager release that your
# configuration is compatible with. This helps avoid breakage
# when a new Home Manager release introduces backwards
# incompatible changes.
#
# 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";
};
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
}

24
home/fcitx5/default.nix Normal file
View File

@@ -0,0 +1,24 @@
{ config, pkgs, ... }:
{
i18n.inputMethod = {
enabled = "fcitx5";
fcitx5.addons =
let
# 为了不使用默认的 rime-data改用我自定义的小鹤音形数据这里需要 override
# 参考 https://github.com/NixOS/nixpkgs/blob/e4246ae1e7f78b7087dce9c9da10d28d3725025f/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix
config.packageOverrides = pkgs: {
fcitx5-rime = pkgs.fcitx5-rime.override {rimeDataPkgs = [
# 小鹤音形配置,配置来自 flypy.com 官方网盘的鼠须管配置压缩包「小鹤音形“鼠须管”for macOS.zip」
# 我仅修改了 default.yaml 文件,将其中的半角括号改为了直角括号「 与 」。
./rime-data-flypy
];};
};
in
with pkgs; [
fcitx5-rime
fcitx5-configtool
fcitx5-chinese-addons
];
};
}

View File

@@ -0,0 +1,152 @@
# 小鹤双拼自定义方案配置
# encoding: utf-8
config_version: "0.38"
schema_list:
- schema: flypy
switcher:
caption: 〔方案选单〕
hotkeys:
- Control+grave
- Control+Shift+grave
- F4
save_options:
- full_shape
- ascii_punct
- simplification
fold_options: true
abbreviate_options: true
#option_list_separator: ''
menu:
page_size: 5
punctuator:
full_shape:
' ' : { commit: ' ' }
',' : { commit: }
'.' : { commit: 。 }
'<' : [ 《, 〈, «, ]
'>' : [ 》, 〉, », ]
'/' : { commit: 、 }
'?' : { commit: }
';' : { commit: }
':' : { commit: }
'''' : { pair: [ '', '' ] }
'"' : { pair: [ '“', '”' ] }
'\' : { commit: 、 }
'|' : ''
'`' :
'~' :
'!' : { commit: }
'@' : ''
'#' : ''
'%' : ''
'$' : [ ¥, '$', '€', '£', '¥', '¢', '¤' ]
'^' : { commit: …… }
'&' :
'*' : ''
'(' :
')' :
'-' :
'_' : ——
'+' :
'=' :
'[' : [ 「, 【, , ]
']' : [ 」, 】, , ]
'{' : [ 『, 〖, ]
'}' : [ 』, 〗, ]
half_shape:
',' : { commit: }
'.' : { commit: 。 }
'<' : [ 《, 〈, «, ]
'>' : [ 》, 〉, », ]
'/' : { commit: 、 }
'?' : { commit: }
';' : { commit: }
':' : { commit: }
'''' : { pair: [ '', '' ] }
'"' : { pair: [ '“', '”' ] }
'\' : { commit: 、 }
'|' : '|'
'`' : '`'
'~' : { commit: }
'!' : { commit: }
'@' : '@'
'#' : '#'
'%' : { commit: '%' }
'$' : { commit: "$" }
'^' : { commit: …… }
'&' : '&'
'*' : { commit: '*' }
'(' :
')' :
'-' : '-'
'_' : ——
'+' : '+'
'=' : '='
# '[' : { commit: '【' }
# ']' : { commit: '】' }
# '{' : { commit: '' }
# '}' : { commit: '' }
'[' : { commit: '「' }
']' : { commit: '」' }
'{' : { commit: '『' }
'}' : { commit: '』' }
key_binder:
bindings:
# Emacs style
- { when: composing, accept: Control+p, send: Up }
- { when: composing, accept: Control+n, send: Down }
- { when: composing, accept: Control+b, send: Left }
- { when: composing, accept: Control+f, send: Right }
- { when: composing, accept: Control+a, send: Home }
- { when: composing, accept: Control+e, send: End }
- { when: composing, accept: Control+d, send: Delete }
- { when: composing, accept: Control+k, send: Shift+Delete }
- { when: composing, accept: Control+h, send: BackSpace }
- { when: composing, accept: Control+g, send: Escape }
- { when: composing, accept: Control+bracketleft, send: Escape }
- { when: composing, accept: Alt+v, send: Page_Up }
- { when: composing, accept: Control+v, send: Page_Down }
# move by word
- { when: composing, accept: ISO_Left_Tab, send: Shift+Left }
- { when: composing, accept: Shift+Tab, send: Shift+Left }
- { when: composing, accept: Tab, send: Shift+Right }
# flip page
- { when: has_menu, accept: minus, send: Page_Up }
- { when: has_menu, accept: equal, send: Page_Down }
- { when: paging, accept: comma, send: Page_Up }
- { when: has_menu, accept: period, send: Page_Down }
# hotkey switch
- { when: always, accept: Control+Shift+1, select: .next }
- { when: always, accept: Control+Shift+2, toggle: ascii_mode }
- { when: always, accept: Control+Shift+3, toggle: full_shape }
- { when: always, accept: Control+Shift+4, toggle: simplification }
- { when: always, accept: Control+Shift+5, toggle: extended_charset }
- { when: always, accept: Control+Shift+exclam, select: .next }
- { when: always, accept: Control+Shift+at, toggle: ascii_mode }
- { when: always, accept: Control+Shift+numbersign, toggle: full_shape }
- { when: always, accept: Control+Shift+dollar, toggle: simplification }
- { when: always, accept: Control+Shift+percent, toggle: extended_charset }
- { when: always, accept: Shift+space, toggle: full_shape }
- { when: always, accept: Control+period, toggle: ascii_punct }
recognizer:
patterns:
uppercase: "[A-Z][-_+.'0-9A-Za-z]*$"
reverse_lookup: "[a-z`]*`+[a-z`]*"
punct: ""
ascii_composer:
good_old_caps_lock: true
switch_key:
Shift_L: inline_ascii
Shift_R: commit_text
Control_L: noop
Control_R: noop
Caps_Lock: clear
Eisu_toggle: clear

View File

@@ -0,0 +1,163 @@
# Rime schema settings
# encoding: utf-8
schema:
schema_id: flypy
name: 小鹤音形
version: "10.9.3"
author:
- 方案设计:何海峰 <flypy@qq.com>
description: |
小鹤音形输入法
punctuator:
import_preset: default
switches:
- name: ascii_mode
reset: 0
# states: [ 中文, 英文 ]
- name: full_shape
# states: [ 半角, 全角 ]
- name: simplification
# states: [ 简, 繁 ]
reset: 0
- name: ascii_punct
# states: [ 。,, ]
reset: 0
engine:
processors:
- ascii_composer
- recognizer
- key_binder
- speller
- punctuator
- selector
- navigator
- express_editor
segmentors:
- ascii_segmentor
- matcher
- abc_segmentor
- punct_segmentor
- fallback_segmentor
translators:
- punct_translator
- table_translator
- lua_translator@date_translator
- lua_translator@time_translator
- table_translator@custom_phraseVD
- table_translator@custom_phraseXT
- table_translator@custom_phraseYH
- table_translator@custom_phraseQMZ
- reverse_lookup_translator
- history_translator@history
- lua_translator@calculator_translator
filters:
- simplifier
- simplifier@simplification
- uniquifier
speller:
alphabet: "abcdefghijklmnopqrstuvwxyz;'"
initials: ';abcdefghijklmnopqrstuvwxyz'
finals: "'"
#delimiter: " '"
max_code_length: 4
auto_select: true #顶字上屏
auto_select_pattern: ^;.$|^\w{4}$
auto_clear: max_length #manual|auto|max_length 空码按下一键确认清屏|空码自动清|达到最长码时后码顶上清屏
translator:
dictionary: flypy
enable_charset_filter: false
enable_sentence: false
enable_completion: false # 编码提示开关
enable_user_dict: false
disable_user_dict_for_patterns:
- "^z.*$"
history:
input: ;f
size: 1 #重复前几次上屏
initial_quality: 1 #首选
simplification:
opencc_config: s2tw.json
option_name: simplification
tips: all #简繁对照
custom_phraseVD:
dictionary: ""
user_dict: flypy_top
db_class: stabledb
enable_sentence: false
enable_completion: false
initial_quality: 0 #用户词和系统词重码 置顶
custom_phraseXT:
dictionary: ""
user_dict: flypy_sys
db_class: stabledb
enable_sentence: false
enable_completion: false
initial_quality: -1 #本表词和系统词重码居后
custom_phraseYH:
dictionary: ""
user_dict: flypy_user
db_class: stabledb
enable_sentence: false
enable_completion: false
initial_quality: -1 #用户词和系统词重码居后
custom_phraseQMZ:
dictionary: ""
user_dict: flypy_full
db_class: stabledb
enable_sentence: false
enable_completion: false
initial_quality: -1 #和系统词重码时居后
reverse_lookup:
dictionary: flypydz
comment_format:
# - xform/^//
# - xform/$//
- xform/ / /
key_binder:
import_preset: default #方案切换相关
bindings:
- {accept: bracketleft, send: Page_Up, when: paging} # [上翻页
- {accept: bracketright, send: Page_Down, when: has_menu} # ]下翻页
- {accept: comma, send: comma, when: paging} #注销逗号翻页
- {accept: period, send: period, when: has_menu} #注销句号翻页
- {accept: semicolon, send: 2, when: has_menu} #分号次选
# - {accept: Release+semicolon, send: semicolon, when: has_menu} #如启用此行,则分号引导符号功能无效
- {accept: Release+period, send: period, when: composing} #句号顶屏
- {accept: Release+comma, send: comma, when: composing} #逗号顶屏
- {accept: "Tab", send: Escape, when: composing}
- {accept: "Shift_R", send: Escape, when: composing}
- {accept: "Shift+space", toggle: full_shape, when: always} #切换全半角
- {accept: "Control+period", toggle: ascii_punct, when: always} #切换中英标点
- {accept: "Control+j", toggle: simplification, when: always} #切换简繁
recognizer:
import_preset: default
patterns:
#uppercase: "[A-Z][-_+.'0-9A-Za-z]*$"
uppercase: "" #中文状态大写锁定直接上屏
reverse_lookup: "[a-z`]*`+[a-z`]*"
punct: ""
expression: "^=.*$"
menu:
page_size: 5 #候选项数
style:
horizontal: true #竖排为false

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,51 @@
# coding: utf-8
# 置顶词库(与系统词条重码时居前)
#
# 编码格式:字词+Tab符+编码(用户词库本身有重码则还需后面+Tab符+权重,权重大者居前,权重数字随意)
#
# ------------ 强调一下 ------------
#
# 词条和编码之间的不是空格而是Tab符如果你不知道就复制下面编码中的空白处
# 或者按住键盘 G 键切换到功能键盘使用上面的Tab键
#
# ---------------------------------------
#
# 分号冒号编码只能放此文件才能调频,如分号做次选需删除权重,外接键盘适用
;
; 90
# 如用户词无重或和系统词条重码时居前则无需权重如想居于系统词条后请把词条放到flypy_user.txt文件内
# 虽然文本码表编辑较为方便,但不适合导入大量条目
# 置顶用户词库,下一行开始添加,部署后生效
# 全码词
即可 jike
知道 vidc
只能 ving
简单 jmdj
计算 jisr
一下 yixx
一直 yivi
只是 viui
按时 anui
而是 erui
成为 igww
小时 xnui
简直 jmvi
任务 rfwu
时间 uijm
水平 uvpk
试试 uiui
神似 ufsi
传统 irts
台湾 tdwj
反应 fjyk
每周 mwvz
联系 lmxi
现金 xmjb
期间 qijm
极其 jiqi
在线 zdxm
只会 vihv
一片 yipm
美丽 mwli
几位 jiww

View File

@@ -0,0 +1,520 @@
# coding: utf-8
# 用户词库
# 与系统词条重码时居后如想居前请把词条放到flypy_top.txt文件内
#
# 编码格式:字词+Tab符+编码(用户词库本身有重码则还需后面+Tab符+权重,权重大者居前,权重数字随意)
#
# -------- 强调一下 --------
#
# 词条和编码之间的不是空格而是Tab符
# 按住键盘 G 键切换到功能键盘使用上面的Tab键
#
# -------------------------------
#
# 系统次选词放在flypy_sys.txt文件内可修改删除
# 简词补全放本文件内,不需要可删除
# 用户词库,下行开始添加,编码格式见上,部署后生效
# 全码词
即使 jiui
回忆 hvyi
华为 hxww
一边 yibm
两边 llbm
整句 vgju
按键 anjm
单元 djyr
反思 fjsi
大于 dayu
改编 gdbm
打架 dajx
叫唤 jnhr
尝尝 ihih
背景 bwjk
伤害 uhhd
程度 igdu
附件 fujm
世纪 uiji
假如 jxru
统一 tsyi
不再 buzd
猥琐 wwso
险恶 xmee
恶毒 eedu
达到 dadc
回复 hvfu
指定 vidk
链接 lmjp
束缚 uufu
征服 vgfu
歧视 qiui
为止 wwvi
瑕疵 xxci
微信 wwxb
妥妥当当 ttdd
反悔 fjhv
补全 buqr
举例 juli
音形 ybxk
想想 xlxl
导出 dciu
把守 bauz
把戏 baxi
报仇 bciz
宝剑 bcjm
报幕 bcmu
保鲜 bcxm
拜年 bdnm
摆脱 bdto
鼻塞 bise
编程 bmig
辩解 bmjp
便签 bmqm
表哥 bnge
博学 boxt
波音 boyb
憋屈 bpqu
背部 bwbu
采风 cdfg
猜忌 cdji
伺候 cihz
餐馆 cjgr
残局 cjju
惨死 cjsi
撺掇 crdo
存管 cygr
搭车 daie
打理 dali
倒逼 dcbi
呆板 ddbj
代购 ddgz
带回 ddhv
代驾 ddjx
得志 devi
得以 deyi
登记 dgji
当众 dhvs
地痞 dipi
淡季 djji
顶住 dkvu
屌丝 dnsi
跌价 dpjx
断点 drdm
短篇 drpm
短线 drxm
动机 dsji
独唱 duih
独自 duzi
对账 dvvh
儿媳 erxi
发火 faho
发力 fali
发型 faxk
发炎 fayj
分割 ffge
粉红 ffhs
分界 ffjp
奋力 ffli
分神 ffuf
风力 fgli
奉献 fgxm
访客 fhke
防守 fhuz
防伪 fhww
反腐 fjfu
凡人 fjrf
反之 fjvi
抚慰 fuww
废了 fwle
费时 fwui
飞舞 fwwu
搞鬼 gcgv
高超 gcic
搞清 gcqk
鸽子 gezi
钢笔 ghbi
纲要 ghyc
光纤 glxm
国徽 gohv
国民 gomb
裹挟 goxp
聒噪 gozc
惯例 grli
关头 grtz
公会 gshv
共计 gsji
功名 gsmk
攻破 gspo
共用 gsys
公子 gszi
古文 guwf
桂花 gvhx
龟速 gvsu
浩瀚 hchj
豪绅 hcuf
何妨 hefh
何尝 heih
汉奸 hjjm
皇权 hlqr
火势 houi
火灾 hozd
换了 hrle
换手 hruz
宏图 hstu
回报 hvbc
徽章 hvvh
滑雪 hxxt
后腿 hztv
后市 hzui
插画 iahx
查出 iaiu
撤诉 iesu
车展 ievj
城堡 igbc
诚实 igui
诚信 igxb
尝到 ihdc
长篇 ihpm
场子 ihzi
迟了 iile
创伤 iluh
传导 irdc
冲高 isgc
重组 iszu
橱柜 iugv
初衷 iuvs
出于 iuyu
春节 iyjp
踌躇 iziu
浆糊 jlhu
奖金 jljb
剑鞘 jmqn
监听 jmtk
浇灌 jngr
接口 jpkz
解围 jpww
纠葛 jqge
军师 jyui
客服 kefu
堪称 kjig
快了 kkle
空缺 ksqt
亏钱 kvqm
喟叹 kvtj
跨过 kxgo
扣缴 kzjn
扣税 kzuv
老实 lcui
理发 lifa
理工 ligs
零星 lkxk
连同 lmts
列支 lpvi
榴莲 lqlm
乱象 lrxl
聋子 lszi
履行 lvxk
论剑 lyjm
毛线 mcxm
毛衣 mcyi
迈过 mdgo
迈出 mdiu
迈入 mdru
懵逼 mgbi
蜜蜂 mifg
秘籍 miji
满族 mjzu
明知 mkvi
明晰 mkxi
免礼 mmli
免谈 mmtj
末位 moww
木板 mubj
美食 mwui
年级 nmji
碾碎 nmsv
农妇 nsfu
农畜 nsiu
奴隶 nuli
内侧 nwce
内里 nwli
牌照 pdvc
派息 pdxi
盘升 pjug
瓶颈 pkjk
漂移 pnyi
颇费 pofw
破例 poli
岂不 qibu
清静 qkjk
青涩 qkse
情谊 qkyi
枪毙 qlbi
墙纸 qlvi
潜力 qmli
嵌套 qmtc
瞧瞧 qnqn
权力 qrli
全套 qrtc
躯壳 quqn
取笑 quxn
忍了 rfle
任职 rfvi
韧性 rfxk
若是 roui
乳汁 ruvi
入眼 ruyj
扫货 scho
私信 sixb
司仪 siyi
散布 sjbu
三维 sjww
缩编 sobm
索贿 sohv
所幸 soxk
算出 sriu
算术 sruu
俗世 suui
随即 svji
叨扰 tcrc
抬高 tdgc
特制 tevi
剔除 tiiu
体制 tivi
体温 tiwf
毯子 tjzi
停播 tkbo
跳高 tngc
跳空 tnks
条例 tnli
条约 tnyt
拖鞋 toxp
童话 tshx
同城 tsig
通气 tsqi
同事 tsui
腿部 tvbu
推导 tvdc
退费 tvfw
偷窥 tzkv
投降 tzxl
傻了 uale
涉及 ueji
赊账 uevh
深化 ufhx
神坛 uftj
身姿 ufzi
剩菜 ugcd
升幅 ugfu
生化 ughx
生姜 ugjl
生理 ugli
声明 ugmk
上场 uhih
使馆 uigr
使坏 uihk
闪亮 ujll
说到 uodc
书摊 uutj
书信 uuxb
水利 uvli
水文 uvwf
收到 uzdc
收工 uzgs
收获 uzho
收集 uzji
受理 uzli
手拿 uzna
受伤 uzuh
手下 uzxx
照办 vcbj
着凉 vcll
朝霞 vcxx
债券 vdqr
宅子 vdzi
哲理 veli
正途 vgtu
只管 vigr
值钱 viqm
质问 viwf
战线 vjxm
转圜 vrhr
转头 vrtz
专项 vrxl
专研 vryj
仲裁 vscd
终点 vsdm
重力 vsli
忠实 vsui
中心 vsxb
主体 vuti
注释 vuui
坠毁 vvhv
皱起 vzqi
外接 wdjp
外壳 wdke
外貌 wdmc
外甥 wdug
文殊 wfuu
蚊子 wfzi
王八 whba
王后 whhz
旺季 whji
往上 whuh
王者 whve
网友 whyz
晚了 wjle
玩转 wjvr
玩意 wjyi
微风 wwfg
心算 xbsr
幸好 xkhc
行程 xkig
性急 xkji
醒了 xkle
兴致 xkvi
想必 xlbi
享福 xlfu
相连 xllm
象棋 xlqi
相思 xlsi
相通 xlts
巷子 xlzi
消化 xnhx
歇着 xpve
雄起 xsqi
兄长 xsvh
雄伟 xsww
续保 xubc
虚实 xuui
下蛋 xxdj
药店 ycdm
钥匙 ycui
阉割 yjge
严厉 yjli
远离 yrli
油锅 yzgo
杂质 zavi
造反 zcfj
造就 zcjq
糟了 zcle
早起 zcqi
宰客 zdke
字符 zifu
自贡 zigs
资深 ziuf
资讯 zixy
作假 zojx
做了 zole
踪迹 zsji
宗旨 zsvi
纵向 zsxl
纵有 zsyz
阻止 zuvi
走近 zzjb
博而不精 bebj
白日飞升 brfu
不着边际 bvbj
嘟嘟囔囔 ddnn
分门别类 fmbl
飞扬跋扈 fybh
隔岸观火 gagh
高屋建瓴 gwjl
花繁叶茂 hfym
金发碧眼 jfby
将功补过 jgbg
将计就计 jjjj
济济一堂 jjyt
迷迷糊糊 mmhh
美若天仙 mrtx
卖主求荣 mvqr
破破烂烂 ppll
千娇百媚 qjbm
人欢马叫 rhmj
扰人清梦 rrqm
条条框框 ttkk
甜甜蜜蜜 ttmm
头痛欲裂 ttyl
首当其冲 udqi
深情厚谊 uqhy
时日无多 urwd
食色性也 usxy
生死攸关 usyg
我必犯人 wbfr
为期不远 wqby
万丈深渊 wvuy
毋庸讳言 wyhy
霞光万道 xgwd
有法必依 yfby
一飞冲天 yfit
一清二白 yqeb
一物降一物 ywxw
余情未了 yqwl
自毁长城 zhii
自取其辱 zqqr
在情在理 zqzl
毕其功于一役 bqgy
百思不得其解 bsbj
狗咬吕洞宾 gylb
横挑鼻子竖挑眼 htby
回头一笑百媚生 htyu
吃香的喝辣的 ixdd
临时抱佛脚 lubj
摸着石头过河 mvuh
哪能不湿鞋 nnbx
年年岁岁花相似 nnss
哪有不湿鞋 nybx
十年生死两茫茫 unum
睁只眼闭只眼 vvyy
无规矩不成方圆 wgjy
香港中文大学 xgvx
一个天上一个地下 ygtx
一亩三分地 ymsd
一年之计在于春 ynvi
远亲不如近邻 yqbl
一朝权在手 yvqu
一问三不知 ywsv
彩蛋 cddj
过渡 godu
好吗 hcma
何时 heui
哪边 nabm
哪次 naci
哪点 nadm
哪儿 naer
哪个 nage
哪里 nali
哪天 natm
哪种 navs
哪位 naww
哪些 naxp
哪样 nayh
倒是 dcui
登陆 dglu
低效 dixn
胆子 djzi
反查 fjia
高速 gcsu
高效 gcxn
国情 goqk
官网 grwh
活着 hove
话费 hxfw
超卖 icmd
卖点 mddm
卖家 mdjx
卖票 mdpn
卖主 mdvu
明明 mkmk
每期 mwqi
没人 mwrf
赏赐 uhci
谁知 uvvi
稳健 wfjm
拥护 yshu
宗师 zsui
按理 anli
黯然 anrj
暗自 anzi
五笔 wubi
座位 zoww

View File

@@ -0,0 +1,402 @@
-- Rime Script >https://github.com/baopaau/rime-lua-collection/blob/master/calculator_translator.lua
-- 簡易計算器執行任何Lua表達式
--
-- 格式:=<exp>
-- Lambda語法糖\<arg>.<exp>|
--
-- 例子:
-- =1+1 輸出 2
-- =floor(9^(8/7)*cos(deg(6))) 輸出 -3
-- =e^pi>pi^e 輸出 true
-- =max({1,7,2}) 輸出 7
-- =map({1,2,3},\x.x^2|) 輸出 {1, 4, 9}
-- =map(range(-5,5),\x.x*pi/4|,deriv(sin)) 輸出 {-0.7071, -1, -0.7071, 0, 0.7071, 1, 0.7071, 0, -0.7071, -1}
-- =$(range(-5,5,0.01))(map,\x.-60*x^2-16*x+20|)(max)() 輸出 21.066
-- =test(\x.trunc(sin(x),1e-3)==trunc(deriv(cos)(x),1e-3)|,range(-2,2,0.1)) 輸出 true
--
-- 安装:
-- - 將本文件保存至 <rime>/lua/
-- - 在 <rime>/rime.lua 新增一行:
-- `calculator_translator = require("calculator_translator")`
-- - 在 <rime>/<schema>.schema.yaml 新增:
-- `engine/translators/@next: lua_translator@calculator_translator`
-- `recognizer/patterns/expression: "^=.*$"`
-- 註:
-- - <rime> 替換爲RIME的共享目錄
-- - <schema> 替換爲自己的方案ID
-- - 如目錄/文件不存在,請自行創建
-- 定義全局函數、常數(注意命名空間污染)
cos = math.cos
sin = math.sin
tan = math.tan
acos = math.acos
asin = math.asin
atan = math.atan
rad = math.rad
deg = math.deg
abs = math.abs
floor = math.floor
ceil = math.ceil
mod = math.fmod
trunc = function (x, dc)
if dc == nil then
return math.modf(x)
end
return x - mod(x, dc)
end
round = function (x, dc)
dc = dc or 1
local dif = mod(x, dc)
if abs(dif) > dc / 2 then
return x < 0 and x - dif - dc or x - dif + dc
end
return x - dif
end
random = math.random
randomseed = math.randomseed
inf = math.huge
MAX_INT = math.maxinteger
MIN_INT = math.mininteger
pi = math.pi
sqrt = math.sqrt
exp = math.exp
e = exp(1)
ln = math.log
log = function (x, base)
base = base or 10
return ln(x)/ln(base)
end
min = function (arr)
local m = inf
for k, x in ipairs(arr) do
m = x < m and x or m
end
return m
end
max = function (arr)
local m = -inf
for k, x in ipairs(arr) do
m = x > m and x or m
end
return m
end
sum = function (t)
local acc = 0
for k,v in ipairs(t) do
acc = acc + v
end
return acc
end
avg = function (t)
return sum(t) / #t
end
isinteger = function (x)
return math.fmod(x, 1) == 0
end
-- iterator . array
array = function (...)
local arr = {}
for v in ... do
arr[#arr + 1] = v
end
return arr
end
-- iterator <- [form, to)
irange = function (from, to, step)
if to == nil then
to = from
from = 0
end
step = step or 1
local i = from - step
to = to - step
return function()
if i < to then
i = i + step
return i
end
end
end
-- array <- [form, to)
range = function (from, to, step)
return array(irange(from, to, step))
end
-- array . reversed iterator
irev = function (arr)
local i = #arr + 1
return function()
if i > 1 then
i = i - 1
return arr[i]
end
end
end
-- array . reversed array
arev = function (arr)
return array(irev(arr))
end
test = function (f, t)
for k,v in ipairs(t) do
if not f(v) then
return false
end
end
return true
end
-- # Functional
map = function (t, ...)
local ta = {}
for k,v in pairs(t) do
local tmp = v
for _,f in pairs({...}) do tmp = f(tmp) end
ta[k] = tmp
end
return ta
end
filter = function (t, ...)
local ta = {}
local i = 1
for k,v in pairs(t) do
local erase = false
for _,f in pairs({...}) do
if not f(v) then
erase = true
break
end
end
if not erase then
ta[i] = v
i = i + 1
end
end
return ta
end
-- e.g: foldr({2,3},\n,x.x^n|,2) = 81
foldr = function (t, f, acc)
for k,v in pairs(t) do
acc = f(acc, v)
end
return acc
end
-- e.g: foldl({2,3},\n,x.x^n|,2) = 512
foldl = function (t, f, acc)
for v in irev(t) do
acc = f(acc, v)
end
return acc
end
-- 調用鏈生成函數HOF for method chaining
-- e.g: chain(range(-5,5))(map,\x.x/5|)(map,sin)(map,\x.e^x*10|)(map,floor)()
-- = floor(map(map(map(range(-5,5),\x.x/5|),sin),\x.e^x*10|))
-- = {4, 4, 5, 6, 8, 10, 12, 14, 17, 20}
-- 可以用 $ 代替 chain
chain = function (t)
local ta = t
local function cf(f, ...)
if f ~= nil then
ta = f(ta, ...)
return cf
else
return ta
end
end
return cf
end
-- # Statistics
fac = function (n)
local acc = 1
for i = 2,n do
acc = acc * i
end
return acc
end
nPr = function (n, r)
return fac(n) / fac(n - r)
end
nCr = function (n, r)
return nPr(n,r) / fac(r)
end
MSE = function (t)
local ss = 0
local s = 0
local n = #t
for k,v in ipairs(t) do
ss = ss + v*v
s = s + v
end
return sqrt((n*ss - s*s) / (n*n))
end
-- # Linear Algebra
-- # Calculus
-- Linear approximation
lapproxd = function (f, delta)
local delta = delta or 1e-8
return function (x)
return (f(x+delta) - f(x)) / delta
end
end
-- Symmetric approximation
sapproxd = function (f, delta)
local delta = delta or 1e-8
return function (x)
return (f(x+delta) - f(x-delta)) / delta / 2
end
end
-- 近似導數
deriv = function (f, delta, dc)
dc = dc or 1e-4
local fd = sapproxd(f, delta)
return function (x)
return round(fd(x), dc)
end
end
-- Trapezoidal rule
trapzo = function (f, a, b, n)
local dif = b - a
local acc = 0
for i = 1, n-1 do
acc = acc + f(a + dif * (i/n))
end
acc = acc * 2 + f(a) + f(b)
acc = acc * dif / n / 2
return acc
end
-- 近似積分
integ = function (f, delta, dc)
delta = delta or 1e-4
dc = dc or 1e-4
return function (a, b)
if b == nil then
b = a
a = 0
end
local n = round(abs(b - a) / delta)
return round(trapzo(f, a, b, n), dc)
end
end
-- Runge-Kutta
rk4 = function (f, timestep)
local timestep = timestep or 0.01
return function (start_x, start_y, time)
local x = start_x
local y = start_y
local t = time
-- loop until i >= t
for i = 0, t, timestep do
local k1 = f(x, y)
local k2 = f(x + (timestep/2), y + (timestep/2)*k1)
local k3 = f(x + (timestep/2), y + (timestep/2)*k2)
local k4 = f(x + timestep, y + timestep*k3)
y = y + (timestep/6)*(k1 + 2*k2 + 2*k3 + k4)
x = x + timestep
end
return y
end
end
-- # System
date = os.date
time = os.time
path = function ()
return debug.getinfo(1).source:match("@?(.*/)")
end
local function serialize(obj)
local type = type(obj)
if type == "number" then
return isinteger(obj) and floor(obj) or obj
elseif type == "boolean" then
return tostring(obj)
elseif type == "string" then
return '"'..obj..'"'
elseif type == "table" then
local str = "{"
local i = 1
for k, v in pairs(obj) do
if i ~= k then
str = str.."["..serialize(k).."]="
end
str = str..serialize(v)..", "
i = i + 1
end
str = str:len() > 3 and str:sub(0,-3) or str
return str.."}"
elseif pcall(obj) then -- function類型
return "callable"
end
return obj
end
-- greedy隨時求值每次變化都會求值否則結尾爲特定字符時求值
local greedy = true
local function calculator_translator(input, seg)
if string.sub(input, 1, 1) ~= "=" then return end
local expfin = greedy or string.sub(input, -1, -1) == ";"
local exp = (greedy or not expfin) and string.sub(input, 2, -1) or string.sub(input, 2, -2)
-- 空格輸入可能
exp = exp:gsub("#", " ")
if not expfin then return end
local expe = exp
-- 鏈式調用語法糖
expe = expe:gsub("%$", " chain ")
-- lambda語法糖
do
local count
repeat
expe, count = expe:gsub("\\%s*([%a%d%s,_]-)%s*%.(.-)|", " (function (%1) return %2 end) ")
until count == 0
end
--yield(Candidate("number", seg.start, seg._end, expe, "展開"))
-- 防止危險操作禁用os和io命名空間
if expe:find("i?os?%.") then return end
-- return語句保證了只有合法的Lua表達式才可執行
local result = load("return "..expe)()
if result == nil then return end
result = serialize(result)
yield(Candidate("number", seg.start, seg._end, exp.."="..result, ""))
end
return calculator_translator

View File

@@ -0,0 +1,17 @@
function date_translator(input, seg)
if (input == "orq") then
--- Candidate(type, start, end, text, comment)
yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), " "))
end
end
function time_translator(input, seg)
if (input == "ouj") then
local cand = Candidate("time", seg.start, seg._end, os.date("%H:%M"), " ")
cand.quality = 1
yield(cand)
end
end
calculator_translator = require("calculator_translator")

View File

@@ -0,0 +1,39 @@
customization:
distribution_code_name: squirrel
distribution_version: 0.14.0
generator: "squirrel::UIStyleSettings"
modified_time: "2019-06-23"
rime_version: 1.5.3
patch:
"preset_color_schemes/metro":
author: "flypy.com"
back_color: 0xffffff # 候选条背景色
border_color_width: 1
#border_color: 0xe89f00 # 边框色
#preedit_back_color: 0xf0403516 #新增,未知其意
border_height: 8 # 窗口边界高度,大于圆角半径才生效
border_width: 8 # 窗口边界宽度,大于圆角半径才生效
candidate_format: "%c\u2005%@\u2005" # 用 1/6 em 空格 U+2005 来控制编号 %c 和候选词 %@ 前后的空间。
corner_radius: 6 # 窗口圆角半径
#hilited_corner_radius: 6 # 高亮圆角
hilited_text_color: 0x000000 # 编码高亮
hilited_back_color: 0xffffff # 编码背景高亮
hilited_candidate_label_color: 0xeeeeee # 首选编号色
hilited_candidate_text_color: 0xffffff # 首选文字色
hilited_candidate_back_color: 0xe89f00 # 首选背景色
hilited_comment_text_color: 0xcccccc # 首选提示字母色
label_color: 0x555555 # 次选编号色
candidate_text_color: 0x000000 # 次选文字色
candidate_back_color: 0xffffff # 次选背景色
comment_text_color: 0x555555 # 次选提示字母色
horizontal: true # 候选窗横向显示
font_point: 18 # 候选窗文字字号
label_font_point: 14 # 候选窗编号字号
inline_preedit: true # 开启嵌入编码
name: "metro"
text_color: 0x333333 # 编码行文字颜色24位色值16进制BGR顺序
"style/line_spacing": 12 # 候选词的行间距
"style/color_scheme": metro
"style/display_tray_icon": false
"style/text_orientation": horizontal # horizontal | vertical

View File

@@ -0,0 +1,372 @@
# Squirrel settings
# encoding: utf-8
config_version: '0.37'
us_keyboard_layout: true
# for veteran chord-typist
chord_duration: 0.1 # seconds
# options: always | never | appropriate
show_notifications_when: appropriate
style:
color_scheme: native
# optional: define both light and dark color schemes to match system appearance
#color_scheme: solarized_light
#color_scheme_dark: solarized_dark
# Deprecated since 0.36, Squirrel 0.15
#horizontal: false
# NOTE: do not set a default value for `candidate_list_layout`, in order to
# keep the deprecated `horizontal` option working for existing users.
#candidate_list_layout: stacked # stacked | linear
text_orientation: horizontal # horizontal | vertical
inline_preedit: true
corner_radius: 10
hilited_corner_radius: 0
border_height: 0
border_width: 0
# space between candidates in stacked layout
line_spacing: 5
# space between preedit and candidates in non-inline mode
spacing: 10
#candidate_format: '%c. %@'
# adjust the base line of vertical text
#base_offset: 6
font_face: 'Lucida Grande'
font_point: 21
#label_font_face: 'Lucida Grande'
label_font_point: 18
#comment_font_face: 'Lucida Grande'
comment_font_point: 18
preset_color_schemes:
native:
name: 系統配色
aqua:
name: 碧水Aqua
author: 佛振 <chen.sst@gmail.com>
text_color: 0x606060
back_color: 0xeeeceeee
candidate_text_color: 0x000000
hilited_text_color: 0x000000
hilited_candidate_text_color: 0xffffff
hilited_candidate_back_color: 0xeefa3a0a
comment_text_color: 0x5a5a5a
hilited_comment_text_color: 0xfcac9d
azure:
name: 青天Azure
author: 佛振 <chen.sst@gmail.com>
text_color: 0xcfa677
candidate_text_color: 0xffeacc
back_color: 0xee8b4e01
hilited_text_color: 0xffeacc
hilited_candidate_text_color: 0x7ffeff
hilited_candidate_back_color: 0x00000000
comment_text_color: 0xc69664
luna:
name: 明月Luna
author: 佛振 <chen.sst@gmail.com>
text_color: 0xa5a5a5
back_color: 0xdd000000
candidate_text_color: 0xeceeee
hilited_text_color: 0x7fffff
hilited_candidate_text_color: 0x7fffff
hilited_candidate_back_color: 0x40000000
comment_text_color: 0xa5a5a5
hilited_comment_text_color: 0x449c9d
ink:
name: 墨池Ink
author: 佛振 <chen.sst@gmail.com>
text_color: 0x5a5a5a
back_color: 0xeeffffff
candidate_text_color: 0x000000
hilited_text_color: 0x000000
#hilited_back_color: 0xdddddd
hilited_candidate_text_color: 0xffffff
hilited_candidate_back_color: 0xcc000000
comment_text_color: 0x5a5a5a
hilited_comment_text_color: 0x808080
lost_temple:
name: 孤寺Lost Temple
author: 佛振 <chen.sst@gmail.com>, based on ir_black
text_color: 0xe8f3f6
back_color: 0xee303030
hilited_text_color: 0x82e6ca
hilited_candidate_text_color: 0x000000
hilited_candidate_back_color: 0x82e6ca
comment_text_color: 0xbb82e6ca
hilited_comment_text_color: 0xbb203d34
dark_temple:
name: 暗堂Dark Temple
author: 佛振 <chen.sst@gmail.com>, based on ir_black
text_color: 0x92f6da
back_color: 0x222222
candidate_text_color: 0xd8e3e6
hilited_text_color: 0xffcf9a
hilited_back_color: 0x222222
hilited_candidate_text_color: 0x92f6da
hilited_candidate_back_color: 0x10000000 # 0x333333
comment_text_color: 0x606cff
psionics:
name: 幽能Psionics
author: 雨過之後、佛振
text_color: 0xc2c2c2
back_color: 0x444444
candidate_text_color: 0xeeeeee
hilited_text_color: 0xeeeeee
hilited_back_color: 0x444444
hilited_candidate_label_color: 0xfafafa
hilited_candidate_text_color: 0xfafafa
hilited_candidate_back_color: 0xd4bc00
comment_text_color: 0x808080
hilited_comment_text_color: 0x444444
purity_of_form:
name: 純粹的形式Purity of Form
author: 雨過之後、佛振
text_color: 0xc2c2c2
back_color: 0x444444
candidate_text_color: 0xeeeeee
hilited_text_color: 0xeeeeee
hilited_back_color: 0x444444
hilited_candidate_text_color: 0x000000
hilited_candidate_back_color: 0xfafafa
comment_text_color: 0x808080
purity_of_essence:
name: 純粹的本質Purity of Essence
author: 佛振
text_color: 0x2c2ccc
back_color: 0xfafafa
candidate_text_color: 0x000000
hilited_text_color: 0x000000
hilited_back_color: 0xfafafa
hilited_candidate_text_color: 0xeeeeee
hilited_candidate_back_color: 0x444444
comment_text_color: 0x808080
starcraft:
name: 星際我爭霸StarCraft
author: Contralisk <contralisk@gmail.com>, original artwork by Blizzard Entertainment
text_color: 0xccaa88
candidate_text_color: 0x30bb55
back_color: 0xee000000
border_color: 0x1010a0
hilited_text_color: 0xfecb96
hilited_back_color: 0x000000
hilited_candidate_text_color: 0x70ffaf
hilited_candidate_back_color: 0x00000000
comment_text_color: 0x1010d0
hilited_comment_text_color: 0x1010f0
google:
name: 谷歌Google
author: skoj <skoj@qq.com>
text_color: 0x666666 #拼音串
candidate_text_color: 0x000000 #非第一候选项
back_color: 0xFFFFFF #背景
border_color: 0xE2E2E2 #边框
hilited_text_color: 0x000000 #拼音串高亮
hilited_back_color: 0xFFFFFF #拼音串高亮背景
hilited_candidate_text_color: 0xFFFFFF #第一候选项
hilited_candidate_back_color: 0xCE7539 #第一候选项背景
comment_text_color: 0x6D6D6D #注解文字
hilited_comment_text_color: 0xEBC6B0 #注解文字高亮
solarized_rock:
name: 曬經石Solarized Rock
author: "Aben <tntaben@gmail.com>, based on Ethan Schoonover's Solarized color scheme"
back_color: 0x362b00
border_color: 0x362b00
text_color: 0x8236d3
hilited_text_color: 0x98a12a
candidate_text_color: 0x969483
comment_text_color: 0xc098a12a
hilited_candidate_text_color: 0xffffff
hilited_candidate_back_color: 0x8236d3
hilited_comment_text_color: 0x362b00
clean_white:
name: 简约白Clean White
author: Chongyu Zhu <lembacon@gmail.com>, based on 搜狗「简约白」
horizontal: true
candidate_format: '%c %@'
corner_radius: 6
border_height: 6
border_width: 6
font_point: 16
label_font_point: 12
label_color: 0x888888
text_color: 0x808080
hilited_text_color: 0x000000
candidate_text_color: 0x000000
comment_text_color: 0x808080
back_color: 0xeeeeee
hilited_candidate_label_color: 0xa0c98915
hilited_candidate_text_color: 0xc98915
hilited_candidate_back_color: 0xeeeeee
apathy:
name: 冷漠Apathy
author: LIANG Hai
horizontal: true # 水平排列
inline_preedit: true #单行显示false双行显示
candidate_format: "%c\u2005%@\u2005" # 编号 %c 和候选词 %@ 前后的空间
corner_radius: 5 #候选条圆角
border_height: 0
border_width: 0
back_color: 0xFFFFFF #候选条背景色
font_face: "PingFangSC-Regular,HanaMinB" #候选词字体
font_point: 16 #候选字词大小
text_color: 0x424242 #高亮选中词颜色
label_font_face: "STHeitiSC-Light" #候选词编号字体
label_font_point: 12 #候选编号大小
hilited_candidate_text_color: 0xEE6E00 #候选文字颜色
hilited_candidate_back_color: 0xFFF0E4 #候选文字背景色
comment_text_color: 0x999999 #拼音等提示文字颜色
dust:
name: 浮尘Dust
author: Superoutman <asticosmo@gmail.com>
horizontal: true # 水平排列
inline_preedit: true #单行显示false双行显示
candidate_format: "%c\u2005%@\u2005" # 用 1/6 em 空格 U+2005 来控制编号 %c 和候选词 %@ 前后的空间。
corner_radius: 2 #候选条圆角
border_height: 3 # 窗口边界高度,大于圆角半径才生效
border_width: 8 # 窗口边界宽度,大于圆角半径才生效
back_color: 0xeeffffff #候选条背景色
border_color: 0xE0B693 # 边框色
font_face: "HYQiHei-55S Book,HanaMinA Regular" #候选词字体
font_point: 14 #候选字词大小
label_font_face: "SimHei" #候选词编号字体
label_font_point: 10 #候选编号大小
label_color: 0xcbcbcb # 预选栏编号颜色
candidate_text_color: 0x555555 # 预选项文字颜色
text_color: 0x424242 # 拼音行文字颜色24位色值16进制BGR顺序
comment_text_color: 0x999999 # 拼音等提示文字颜色
hilited_text_color: 0x9e9e9e # 高亮拼音 (需要开启内嵌编码)
hilited_candidate_text_color: 0x000000 # 第一候选项文字颜色
hilited_candidate_back_color: 0xfff0e4 # 第一候选项背景背景色
hilited_candidate_label_color: 0x555555 # 第一候选项编号颜色
hilited_comment_text_color: 0x9e9e9e # 注解文字高亮
mojave_dark:
name: 沙漠夜Mojave Dark
author: xiehuc <xiehuc@gmail.com>
horizontal: true # 水平排列
inline_preedit: true # 单行显示false双行显示
candidate_format: "%c\u2005%@" # 用 1/6 em 空格 U+2005 来控制编号 %c 和候选词 %@ 前后的空间。
corner_radius: 5 # 候选条圆角
hilited_corner_radius: 3 # 高亮圆角
border_height: 6 # 窗口边界高度,大于圆角半径才生效
border_width: 6 # 窗口边界宽度,大于圆角半径才生效
font_face: "PingFangSC" # 候选词字体
font_point: 16 # 候选字词大小
label_font_point: 14 # 候选编号大小
text_color: 0xdedddd # 拼音行文字颜色24位色值16进制BGR顺序
back_color: 0x252320 # 候选条背景色
label_color: 0x888785 # 预选栏编号颜色
border_color: 0x020202 # 边框色
candidate_text_color: 0xdedddd # 预选项文字颜色
hilited_text_color: 0xdedddd # 高亮拼音 (需要开启内嵌编码)
hilited_back_color: 0x252320 # 高亮拼音 (需要开启内嵌编码)
hilited_candidate_text_color: 0xffffff # 第一候选项文字颜色
hilited_candidate_back_color: 0xcb5d00 # 第一候选项背景背景色
hilited_candidate_label_color: 0xffffff # 第一候选项编号颜色
comment_text_color: 0xdedddd # 拼音等提示文字颜色
#hilited_comment_text_color: 0xdedddd # 注解文字高亮
solarized_light:
name: 曬經・日Solarized Light
author: 雪齋 <lyc20041@gmail.com>
color_space: display_p3 # Only available on macOS 10.12+
back_color: 0xf0E5F6FB #Lab 97, 0, 10
border_color: 0xf0EDFFFF #Lab 100, 0, 10
preedit_back_color: 0xf0D7E8ED #Lab 92, 0, 10
candidate_text_color: 0x3942CB #Lab 50, 65, 45
label_color: 0x2566C6 #Lab 55, 45, 65
comment_text_color: 0x8144C2 #Lab 50, 65, -5
text_color: 0x756E5D #Lab 45, -7, -7
hilited_back_color: 0xf0C9DADF #Lab 87, 0, 10
hilited_candidate_back_color: 0x403516 #Lab 20, -12, -12
hilited_candidate_text_color: 0x989F52 #Lab 60, -35, -5
hilited_candidate_label_color: 0xCC8947 #Lab 55, -10, -45
hilited_comment_text_color: 0x289989 #Lab 60, -20, 65
hilited_text_color: 0xBE706D #Lab 50, 15, -45
solarized_dark:
name: 曬經・月Solarized Dark
author: 雪齋 <lyc20041@gmail.com>
color_space: display_p3 # Only available on macOS 10.12+
back_color: 0xf0352A0A #Lab 15, -12, -12
border_color: 0xf02A1F00 #Lab 10, -12, -12
preedit_back_color: 0xf0403516 #Lab 20, -12, -12
candidate_text_color: 0x989F52 #Lab 60, -35, -5
label_color: 0xCC8947 #Lab 55, -10, -45
comment_text_color: 0x289989 #Lab 60, -20, 65
text_color: 0xA1A095 #Lab 65, -05, -02
hilited_back_color: 0xf04C4022 #Lab 25, -12, -12
hilited_candidate_back_color: 0xD7E8ED #Lab 92, 0, 10
hilited_candidate_text_color: 0x3942CB #Lab 50, 65, 45
hilited_candidate_label_color: 0x2566C6 #Lab 55, 45, 65
hilited_comment_text_color: 0x8144C2 #Lab 50, 65, -5
hilited_text_color: 0x2C8BAE #Lab 60, 10, 65
app_options:
com.apple.Spotlight:
ascii_mode: true
com.alfredapp.Alfred:
ascii_mode: true
com.runningwithcrayons.Alfred-2:
ascii_mode: true
com.blacktree.Quicksilver:
ascii_mode: true
com.apple.Terminal:
ascii_mode: true
no_inline: true
com.googlecode.iterm2:
ascii_mode: true
no_inline: true
org.vim.MacVim:
ascii_mode: true # 初始爲西文模式
no_inline: true # 不使用行內編輯
vim_mode: true # 退出VIM插入模式自動切換輸入法狀態
com.apple.dt.Xcode:
ascii_mode: true
com.barebones.textwrangler:
ascii_mode: true
com.macromates.TextMate.preview:
ascii_mode: true
com.github.atom:
ascii_mode: true
com.microsoft.VSCode:
ascii_mode: true
com.sublimetext.2:
ascii_mode: true
org.gnu.Aquamacs:
ascii_mode: true
org.gnu.Emacs:
ascii_mode: true
no_inline: true
co.zeit.hyper:
ascii_mode: true
com.google.Chrome:
# 規避 https://github.com/rime/squirrel/issues/435
inline: true
ru.keepcoder.Telegram:
# 規避 https://github.com/rime/squirrel/issues/475
inline: true

537
home/i3/config Normal file
View File

@@ -0,0 +1,537 @@
# This file is a modified version based on default i3-config-wizard config
# Maintainer: ryan4yin [xiaoyin_c@qq.com]
#######################
# config starts here: #
#######################
# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
# This font is widely installed, provides lots of unicode glyphs, right-to-left
# text rendering and scalability on retina/hidpi displays (thanks to pango).
font pango: Noto Sans Regular 10
# set the mod key to the winkey:
set $mod Mod4
#####################
# workspace layout: #
#####################
# default i3 tiling mode:
workspace_layout default
# i3 stacking layout:
# Each window will be fullscreen and tabbed top to bottom.
#workspace_layout stacking
# i3 tabbed layout:
# Each new window will open fullscreen as a tab (left to right)
#workspace_layout tabbed
##############################
# extra options for windows: #
##############################
#border indicator on windows:
new_window pixel 1
# thin borders
# hide_edge_borders both
# Set inner/outer gaps
gaps inner 6
gaps outer 3
# show window title bars (not officially supported with i3gaps)
#default_border normal
# window title alignment
#title_align center
# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod
# switch/iterate between workspaces
bindsym $mod+Tab workspace next
bindsym $mod+Shift+Tab workspace prev
# switch to workspace
bindsym $mod+1 workspace $ws1
bindsym $mod+2 workspace $ws2
bindsym $mod+3 workspace $ws3
bindsym $mod+4 workspace $ws4
bindsym $mod+5 workspace $ws5
bindsym $mod+6 workspace $ws6
bindsym $mod+7 workspace $ws7
bindsym $mod+8 workspace $ws8
bindsym $mod+9 workspace $ws9
bindsym $mod+0 workspace $ws10
# switch to workspace with numpad keys
bindcode $mod+87 workspace 1
bindcode $mod+88 workspace 2
bindcode $mod+89 workspace 3
bindcode $mod+83 workspace 4
bindcode $mod+84 workspace 5
bindcode $mod+85 workspace 6
bindcode $mod+79 workspace 7
bindcode $mod+80 workspace 8
bindcode $mod+81 workspace 9
bindcode $mod+90 workspace 10
# switch to workspace with numlock numpad keys
bindcode $mod+Mod2+87 workspace $ws1
bindcode $mod+Mod2+88 workspace $ws2
bindcode $mod+Mod2+89 workspace $ws3
bindcode $mod+Mod2+83 workspace $ws4
bindcode $mod+Mod2+84 workspace $ws5
bindcode $mod+Mod2+85 workspace $ws6
bindcode $mod+Mod2+79 workspace $ws7
bindcode $mod+Mod2+80 workspace $ws8
bindcode $mod+Mod2+81 workspace $ws9
bindcode $mod+Mod2+90 workspace $ws10
# move focused container to workspace
bindsym $mod+Shift+1 move container to workspace $ws1
bindsym $mod+Shift+2 move container to workspace $ws2
bindsym $mod+Shift+3 move container to workspace $ws3
bindsym $mod+Shift+4 move container to workspace $ws4
bindsym $mod+Shift+5 move container to workspace $ws5
bindsym $mod+Shift+6 move container to workspace $ws6
bindsym $mod+Shift+7 move container to workspace $ws7
bindsym $mod+Shift+8 move container to workspace $ws8
bindsym $mod+Shift+9 move container to workspace $ws9
bindsym $mod+Shift+0 move container to workspace $ws10
# move focused container to workspace with numpad keys
bindcode $mod+Shift+Mod2+87 move container to workspace $ws1
bindcode $mod+Shift+Mod2+88 move container to workspace $ws2
bindcode $mod+Shift+Mod2+89 move container to workspace $ws3
bindcode $mod+Shift+Mod2+83 move container to workspace $ws4
bindcode $mod+Shift+Mod2+84 move container to workspace $ws5
bindcode $mod+Shift+Mod2+85 move container to workspace $ws6
bindcode $mod+Shift+Mod2+79 move container to workspace $ws7
bindcode $mod+Shift+Mod2+80 move container to workspace $ws8
bindcode $mod+Shift+Mod2+81 move container to workspace $ws9
bindcode $mod+Shift+Mod2+90 move container to workspace $ws10
# move focused container to workspace with numpad keys
bindcode $mod+Shift+87 move container to workspace $ws1
bindcode $mod+Shift+88 move container to workspace $ws2
bindcode $mod+Shift+89 move container to workspace $ws3
bindcode $mod+Shift+83 move container to workspace $ws4
bindcode $mod+Shift+84 move container to workspace $ws5
bindcode $mod+Shift+85 move container to workspace $ws6
bindcode $mod+Shift+79 move container to workspace $ws7
bindcode $mod+Shift+80 move container to workspace $ws8
bindcode $mod+Shift+81 move container to workspace $ws9
bindcode $mod+Shift+90 move container to workspace $ws10
# resize window (you can also use the mouse for that):
#mode "resize" {
# These bindings trigger as soon as you enter the resize mode
# Pressing left will shrink the window's width.
# Pressing right will grow the window's width.
# Pressing up will shrink the window's height.
# Pressing down will grow the window's height.
# bindsym j resize shrink width 10 px or 10 ppt
# bindsym k resize grow height 10 px or 10 ppt
# bindsym l resize shrink height 10 px or 10 ppt
# bindsym ntilde resize grow width 10 px or 10 ppt
# same bindings, but for the arrow keys
# bindsym Left resize shrink width 10 px or 10 ppt
# bindsym Down resize grow height 10 px or 10 ppt
# bindsym Up resize shrink height 10 px or 10 ppt
# bindsym Right resize grow width 10 px or 10 ppt
# back to normal: Enter or Escape
# bindsym Return mode "default"
# bindsym Escape mode "default"
#}
bindsym $mod+r mode "resize"
######################################
# keybindings for different actions: #
######################################
# start a terminal
bindsym $mod+Return exec alacritty
# kill focused window
bindsym $mod+q kill
# exit-menu
bindsym $mod+Shift+e exec ~/.config/i3/scripts/powermenu
# Lock the system
# lock with a picture:
#bindsym $mod+l exec i3lock -i ~/.config/i3/i3-lock-screen.png -p default|win -t
# lock by blurring the screen:
bindsym $mod+l exec ~/.config/i3/scripts/blur-lock
# reload the configuration file
bindsym $mod+Shift+c reload
# restart i3 inplace (preserves your layout/session, can be used to update i3)
bindsym $mod+Shift+r restart
# keybinding in fancy rofi (automated):
bindsym F1 exec ~/.config/i3/scripts/keyhint-2
# alternative
# keybinding list in editor:
# bindsym $mod+F1 exec xed ~/.config/i3/keybindings
# Backlight control
bindsym XF86MonBrightnessUp exec xbacklight +10 && notify-send "Brightness - $(xbacklight -get | cut -d '.' -f 1)%"
bindsym XF86MonBrightnessDown exec xbacklight -10 && notify-send "Brightness - $(xbacklight -get | cut -d '.' -f 1)%"
# change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
bindsym $mod+b focus up
bindsym $mod+o focus right
# alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
# move focused window
bindsym $mod+Shift+j move left
bindsym $mod+Shift+k move down
bindsym $mod+Shift+b move up
bindsym $mod+Shift+o move right
# alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right
# split in horizontal orientation
bindsym $mod+h split h
# split in vertical orientation
bindsym $mod+v split v
# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen toggle
# change container layout (stacked, tabbed, toggle split)
bindsym $mod+s layout stacking
bindsym $mod+g layout tabbed
bindsym $mod+e layout toggle split
# toggle tiling / floating
bindsym $mod+Shift+space floating toggle
# change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle
# focus the parent container
bindsym $mod+a focus parent
# open new empty workspace
bindsym $mod+Shift+n exec ~/.config/i3/scripts/empty_workspace
# Multimedia Keys
# volume
bindsym XF86AudioRaiseVolume exec amixer -D pulse sset Master 5%+ && pkill -RTMIN+1 i3blocks
bindsym XF86AudioLowerVolume exec amixer -D pulse sset Master 5%- && pkill -RTMIN+1 i3blocks
# gradular volume control
bindsym $mod+XF86AudioRaiseVolume exec amixer -D pulse sset Master 1%+ && pkill -RTMIN+1 i3blocks
bindsym $mod+XF86AudioLowerVolume exec amixer -D pulse sset Master 1%- && pkill -RTMIN+1 i3blocks
# mute
bindsym XF86AudioMute exec amixer sset Master toggle && killall -USR1 i3blocks
# audio control
bindsym XF86AudioPlay exec playerctl play
bindsym XF86AudioPause exec playerctl pause
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous
# Redirect sound to headphones
bindsym $mod+p exec /usr/local/bin/switch-audio-port
## App shortcuts
bindsym $mod+w exec /usr/bin/firefox
bindsym $mod+n exec /usr/bin/thunar
bindsym Print exec scrot ~/%Y-%m-%d-%T-screenshot.png && notify-send "Screenshot saved to ~/$(date +"%Y-%m-%d-%T")-screenshot.png"
# Power Profiles menu switcher (rofi)
bindsym $mod+Shift+p exec ~/.config/i3/scripts/power-profiles
##########################################
# configuration for workspace behaviour: #
##########################################
# Define names for default workspaces for which we configure key bindings later on.
# We use variables to avoid repeating the names in multiple places.
set $ws1 "1:"
set $ws2 "2:"
set $ws3 "3:"
set $ws4 "4:"
set $ws5 "5:"
set $ws6 "6"
set $ws7 "7"
set $ws8 "8"
set $ws9 "9"
set $ws10 "10"
# use workspaces on different displays:
# where you have to replace VGA-0/HDMI-0 with the names for your displays
# you can get from xrandr command
#workspace $ws1 output VGA-0
#workspace $ws2 output VGA-0
#workspace $ws3 output HDMI-0
#workspace $ws4 output HDMI-0
#workspace $ws5 output HDMI-0
# bind program to workspace and focus to them on startup:
assign [class="Terminal"] $ws1
assign [class="(?i)firefox"] $ws2
assign [class="Thunar"] $ws3
assign [class="thunderbird"] $ws4
assign [class="TelegramDesktop"] $ws5
# automatic set focus new window if it opens on another workspace than the current:
for_window [class=Terminal] focus
for_window [class=(?i)firefox] focus
for_window [class=Thunar] focus
for_window [class=Thunderbird] focus
for_window [class=TelegramDesktop] focus
##############
# compositor #
##############
# transparency
# options could need changes, related to used GPU and drivers.
# to find the right setting consult the archwiki or ask at the forum.
#
# picom: https://wiki.archlinux.org/title/Picom
# manpage: https://man.archlinux.org/man/picom.1.en
# The default configuration is available in /etc/xdg/picom.conf
# For modifications, it can be copied to ~/.config/picom/picom.conf or ~/.config/picom.conf
# install picom package (yay -S picom)
# start using default config
exec_always --no-startup-id picom -b
#
# for custom config:
#exec_always --no-startup-id picom --config ~/.config/picom.conf
#############################################
# autostart applications/services on login: #
#############################################
#get auth work with polkit-gnome
exec --no-startup-id /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1
# dex execute .desktop files + apps using /etc/xdg/autostart.
exec --no-startup-id dex --autostart --environment i3
# num lock activated
#exec --no-startup-id numlockx on
# start a script to setup displays
# uncomment the next line, use arandr to setup displays and save the file as monitor:
# exec --no-startup-id ~/.screenlayout/monitor.sh
# set wallpaper
# exec --no-startup-id sleep 2 && nitrogen --restore
exec --no-startup-id sleep 1 && feh --bg-fill ~/.config/i3/wallpaper.jpg
# set powersavings for display:
exec --no-startup-id xset s 480 dpms 600 600 600
# disable power saving (for example if using xscreensaver)
#exec --no-startup-id xset -dpms
# use xautolock to use autosuspend rules for mobile devices
# https://wiki.archlinux.org/title/Session_lock#xautolock
#exec --no-startup-id xautolock -time 60 -locker "systemctl suspend"
# xscreensaver
# https://www.jwz.org/xscreensaver
#exec --no-startup-id xscreensaver --no-splash
# Desktop notifications
# dunst config used ~/.config/dunst/dunstrc
# set alternative config if needed:
#exec --no-startup-id /usr/bin/dunst --config ~/.config/dunst/dunstrc
# may yneed to run dbus-launch explicitly:
#exec --no-startup-id dbus-launch /usr/bin/dunst
exec --no-startup-id /usr/bin/dunst
# autotiling script
# https://github.com/nwg-piotr/autotiling
# `yay -S autotiling ; (it is in AUR)
#exec_always --no-startup-id autotiling
# Autostart apps as you like
#exec --no-startup-id sleep 2 && Terminal
#exec --no-startup-id sleep 3 && thunar
###############
# system tray #
###############
# if you do not use dex: exec --no-startup-id dex --autostart --environment i3
# you need to have tray apps started manually one by one:
# start blueberry app for managing bluetooth devices from tray:
#exec --no-startup-id blueberry-tray
# networkmanager-applet
#exec --no-startup-id nm-applet
##################
# floating rules #
##################
# set floating (nontiling) for apps needing it
for_window [class="Yad" instance="yad"] floating enable
for_window [class="Galculator" instance="galculator"] floating enable
for_window [class="Blueberry.py" instance="blueberry.py"] floating enable
# set floating (nontiling) for special apps
for_window [class="Xsane" instance="xsane"] floating enable
for_window [class="Pavucontrol" instance="pavucontrol"] floating enable
for_window [class="qt5ct" instance="qt5ct"] floating enable
for_window [class="Blueberry.py" instance="blueberry.py"] floating enable
for_window [class="Bluetooth-sendto" instance="bluetooth-sendto"] floating enable
for_window [class="Pamac-manager"] floating enable
for_window [window_role="About"] floating enable
# set border of floating window
for_window [class="urxvt"] border pixel 1
# set size of floating window
#for_window [window_role="(?i)GtkFileChooserDialog"] resize set 640 480 #to set size of file choose dialog
#for_window [class=".*"] resize set 640 480 #to change size of all floating windows
# set position of floating window
#for_window [class=".*"] move position center
######################################
# color settings for bar and windows #
######################################
# Define colors variables:
set $darkbluetrans #08052be6
set $darkblue #08052b
set $lightblue #5294e2
set $urgentred #e53935
set $white #ffffff
set $black #000000
set $purple #e345ff
set $darkgrey #383c4a
set $grey #b0b5bd
set $mediumgrey #8b8b8b
set $yellowbrown #e1b700
# define colors for windows:
#class border bground text indicator child_border
client.focused $lightblue $darkblue $white $mediumgrey $mediumgrey
client.unfocused $darkblue $darkblue $grey $darkgrey $darkgrey
client.focused_inactive $darkblue $darkblue $grey $black $black
client.urgent $urgentred $urgentred $white $yellowbrown $yellowbrown
############################################
# bar settings (input comes from i3blocks) #
############################################
# Start i3bar to display a workspace bar
# (plus the system information i3status finds out, if available)
bar {
font pango: Noto Sans Regular 10
status_command i3blocks -c ~/.config/i3/i3blocks.conf
position bottom
# i3bar_command i3bar --transparency
# it could be that you have no primary display set: set one (xrandr --output <output> --primary)
# reference: https://i3wm.org/docs/userguide.html#_tray_output
#tray_output primary
tray_padding 0
# When strip_workspace_numbers is set to yes,
# any workspace that has a name of the form
# “[n][:][NAME]” will display only the name.
strip_workspace_numbers yes
##strip_workspace_name no
colors {
separator $purple
background $darkgrey
statusline $white
# border bg txt indicator
focused_workspace $mediumgrey $grey $darkgrey $purple
active_workspace $lightblue $mediumgrey $darkgrey $purple
inactive_workspace $darkgrey $darkgrey $grey $purple
urgent_workspace $urgentred $urgentred $white $purple
}
}
# you can add different bars for multidisplay setups on each display:
# set output HDMI-0 to the display you want the bar, --transparency can be set.
# Transparency needs rgba color codes to be used where the last two letters are the transparency factor see here:
# https://gist.github.com/lopspower/03fb1cc0ac9f32ef38f4
# #08052be6 --> e6=90%
# bar {
# font pango: Noto Sans Regular 10
# status_command i3blocks -c ~/.config/i3/i3blocks-2.conf
# i3bar_command i3bar --transparency
# output HDMI-0
# position bottom
#
# When strip_workspace_numbers is set to yes,
# any workspace that has a name of the form
# “[n][:][NAME]” will display only the name.
#strip_workspace_numbers yes
##strip_workspace_name no
#
# colors {
# separator $purple
# background $darkbluetrans
# statusline $white
# border bg txt indicator
# focused_workspace $lighterblue $lighterblue $darkblue $purple
# active_workspace $lightdblue $lightdblue $darkblue $purple
# inactive_workspace $darkblue $darkblue $lightdblue $purple
# urgent_workspace $urgentred $urgentred $white $purple
# }
#}
#####################################
# Application menu handled by rofi: #
#####################################
## rofi bindings fancy application menu ($mod+d /F9 optional disabled)
bindsym $mod+d exec rofi -modi drun -show drun \
-config ~/.config/rofi/rofidmenu.rasi
#bindsym F9 exec rofi -modi drun -show drun \
# -config ~/.config/rofi/rofidmenu.rasi
## rofi bindings for window menu ($mod+t /F10 optional disabled)
bindsym $mod+t exec rofi -show window \
-config ~/.config/rofi/rofidmenu.rasi
#bindsym F10 exec rofi -show window \
# -config ~/.config/rofi/rofidmenu.rasi
## rofi bindings to manage clipboard (install rofi-greenclip from the AUR)
#exec --no-startup-id greenclip daemon>/dev/null
#bindsym $mod+c exec --no-startup-id rofi -modi "clipboard:greenclip print" -show clipboard \
# -config ~/.config/rofi/rofidmenu.rasi

26
home/i3/default.nix Normal file
View File

@@ -0,0 +1,26 @@
{
pkgs,
config,
...
}: {
# i3 配置,基于 https://github.com/endeavouros-team/endeavouros-i3wm-setup
# 直接从当前文件夹中读取配置文件作为配置内容
# wallpaper, binary file
home.file.".config/i3/wallpaper.jpg".source = ../../wallpaper.jpg;
home.file.".config/i3/config".source = ./config;
home.file.".config/i3/i3blocks.conf".source = ./i3blocks.conf;
home.file.".config/i3/keybindings".source = ./keybindings;
home.file.".config/i3/scripts" = {
source = ./scripts;
# copy the scripts directory recursively
recursive = true;
executable = true; # make all scripts executable
};
# 直接以 text 的方式,在 nix 配置文件中硬编码文件内容
# home.file.".xxx".text = ''
# xxx
# '';
}

179
home/i3/i3blocks.conf Normal file
View File

@@ -0,0 +1,179 @@
# i3blocks config file changed for EndeavourOS-i3 setup
# source is available here:
# https://raw.githubusercontent.com/endeavouros-team/endeavouros-i3wm-setup/main/.config/i3/i3blocks.conf
# Maintainer: joekamprad [joekamprad@endeavouros.com]
# Former Visual Designer: Florent Valetti [@FLVAL EndeavourOS]
# created for i3wm setup on EndeavourOS
# https://endeavouros.com
# cheatsheet for icon fonts used on the block-bar:
# https://fontawesome.com/v4.7/cheatsheet/
# --> to update this run the following command:
# wget --backups=1 https://raw.githubusercontent.com/endeavouros-team/endeavouros-i3wm-setup/main/.config/i3/i3blocks.conf -P ~/.config/i3/
# Please see man i3blocks for a complete reference!
# The man page is also hosted at http://vivien.github.io/i3blocks
# List of valid properties:
#
# align
# color
# command
# full_text
# instance
# interval
# label
# min_width
# name
# separator
# separator_block_width
# short_text
# signal
# urgent
# Global properties
#
# The top properties below are applied to every block, but can be overridden.
separator=false
markup=pango
#[Weather]
#command=~/.config/i3/scripts/openweather
# or:
#command=~/.config/i3/scripts/openweather-city
#interval=1800
#color=#7275b3
[terminal]
full_text= 
color=#807dfe
command=i3-msg -q exec alacritty
[browser]
full_text= 
color=#ff7f81
command=i3-msg -q exec firefox
[files]
full_text= 
color=#7f3fbf
command=i3-msg -q exec thunar ~/
#[mail]
#full_text= 
#color=#dbcb75
#command=i3-msg -q exec thunderbird
[simple-2]
full_text=: :
color=#717171
# Disk usage
#
# The directory defaults to $HOME if the instance is not specified.
# The script may be called with a optional argument to set the alert
# (defaults to 10 for 10%).
[disk]
label=
instance=/
command=~/.config/i3/scripts/disk
interval=30
# Memory usage
#
# The type defaults to "mem" if the instance is not specified.
[memory]
label=
command=~/.config/i3/scripts/memory
interval=2
[cpu_usage]
label=
command=~/.config/i3/scripts/cpu_usage
#min_width=CPU: 100.00%
interval=2
[CPU-temperature]
label=
command=~/.config/i3/scripts/temperature
interval=30
#T_WARN=70
#T_CRIT=90
#SENSOR_CHIP=""
# where SENSOR_CHIP can be find with sensors output
# can be used also for GPU temperature or other temperature sensors lm-sensors detects.
# showing name of connected network (enable for wifi use)
#[net]
#label=
#command=echo "$(LANG=C nmcli d | grep connected | awk '{print $4}')"
#interval=30
[bandwidth]
command=~/.config/i3/scripts/bandwidth2
interval=persist
# Battery indicator
# [battery]
# command=~/.config/i3/scripts/battery2
# # for alternative battery script change to battery1
# # change this to battery-pinebook-pro if you are running on pinebook-pro
# label=
# interval=30
[simple-2]
full_text=: :
color=#717171
[pavucontrol]
full_text=
command=pavucontrol
[volume-pulseaudio]
command=~/.config/i3/scripts/volume
instance=Master
interval=1
# display keyboard layout name
# for keyboard layouts switcher
# see i3 config file
# this needs xkblayout-state installed from the AUR:
# https://aur.archlinux.org/packages/xkblayout-state-git
#[keyboard-layout]
#command=~/.config/i3/scripts/keyboard-layout
#interval=2
[keybindings]
full_text=
command=~/.config/i3/scripts/keyhint
# power-profiles-daemon implementation:
# needs package power-profiles-daemon installed and the service running see here:
# https://wiki.archlinux.org/title/CPU_frequency_scaling#power-profiles-daemon
#set power-profile
[ppd_menu]
full_text=
command=~/.config/i3/scripts/power-profiles
color=#407437
#Show the current power-profile
[ppd-status]
command=~/.config/i3/scripts/ppd-status
interval=5
[time]
#label=
command=date '+%a %d %b %H:%M:%S'
interval=1
[shutdown_menu]
full_text=
command=~/.config/i3/scripts/powermenu
[simple-2]
full_text=: :
color=#717171

106
home/i3/keybindings Normal file
View File

@@ -0,0 +1,106 @@
EndeavourOS i3wm Keybindings cheat sheet:
--> to update this run the following command:
wget --backups=1 https://raw.githubusercontent.com/endeavouros-team/endeavouros-i3wm-setup/main/.config/i3/keybindings -P ~/.config/i3/
All sources and updates are available at GitHub:
https://github.com/endeavouros-team/endeavouros-i3wm-setup
For reference consult our WIKI:
https://discovery.endeavouros.com/window-tiling-managers/i3-wm/
 = windows key
# start alacritty
+Return
# kill focused window
+q
# Application menu search by typing (fancy Rofi menu):
+d
# Window switcher menu (fancy Rofi menu):
+t
# fancy exit-menu on bottom right:
+Shift+e
# Lock the system
# lock with a picture or blurring the screen (options in config)
+l
# reload the configuration file
+Shift+c
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
+Shift+r
# keybinding in fancy rofi (automated)
F1
# full keybinding list in editor:
+F1
# change window focus
+j focus left
+k focus down
+b focus up
+o focus right
# alternatively, you can use the cursor keys:
+Left focus left
+Down focus down
+Up focus up
+Right focus right
# move a focused window
+Shift+j move left
+Shift+k move down
+Shift+b move up
+Shift+o move right
# alternatively, you can use the cursor keys:
+Shift+Left move left
+Shift+Down move down
+Shift+Up move up
+Shift+Right move right
# split in horizontal orientation
+h split h
# split in vertical orientation
+v split v
# enter fullscreen mode for the focused container
+f fullscreen toggle
# change container layout (stacked, tabbed, toggle split)
+s layout stacking
+g layout tabbed
+e layout toggle split
# toggle tiling / floating
+Shift+space floating toggle
# change focus between tiling / floating windows
+space focus mode_toggle
# focus the parent container
+a focus parent
# focus the child container
#+d focus child
# resize floating window
+right mouse button
## Multimedia Keys
# Redirect sound to headphones
+p
## App shortcuts
+w starts Firefox
+n starts Thunar
 Button screenshot

104
home/i3/scripts/bandwidth2 Executable file
View File

@@ -0,0 +1,104 @@
#!/usr/bin/env bash
#
# Copyright (C) 2015 James Murphy
# Licensed under the terms of the GNU GPL v2 only.
#
# i3blocks blocklet script to monitor bandwidth usage
iface="${BLOCK_INSTANCE}"
iface="${IFACE:-$iface}"
dt="${DT:-3}"
unit="${UNIT:-MB}"
LABEL="${LABEL:-<span font='FontAwesome'> </span>}" # down arrow up arrow
printf_command="${PRINTF_COMMAND:-"printf \"${LABEL}%1.0f/%1.0f %s/s\\n\", rx, wx, unit;"}"
function default_interface {
ip route | awk '/^default via/ {print $5; exit}'
}
function check_proc_net_dev {
if [ ! -f "/proc/net/dev" ]; then
echo "/proc/net/dev not found"
exit 1
fi
}
function list_interfaces {
check_proc_net_dev
echo "Interfaces in /proc/net/dev:"
grep -o "^[^:]\\+:" /proc/net/dev | tr -d " :"
}
while getopts i:t:u:p:lh opt; do
case "$opt" in
i) iface="$OPTARG" ;;
t) dt="$OPTARG" ;;
u) unit="$OPTARG" ;;
p) printf_command="$OPTARG" ;;
l) list_interfaces && exit 0 ;;
h) printf \
"Usage: bandwidth3 [-i interface] [-t time] [-u unit] [-p printf_command] [-l] [-h]
Options:
-i\tNetwork interface to measure. Default determined using \`ip route\`.
-t\tTime interval in seconds between measurements. Default: 3
-u\tUnits to measure bytes in. Default: Mb
\tAllowed units: Kb, KB, Mb, MB, Gb, GB, Tb, TB
\tUnits may have optional it/its/yte/ytes on the end, e.g. Mbits, KByte
-p\tAwk command to be called after a measurement is made.
\tDefault: printf \"<span font='FontAwesome'> </span>%%-5.1f/%%5.1f %%s/s\\\\n\", rx, wx, unit;
\tExposed variables: rx, wx, tx, unit, iface
-l\tList available interfaces in /proc/net/dev
-h\tShow this help text
" && exit 0;;
esac
done
check_proc_net_dev
iface="${iface:-$(default_interface)}"
while [ -z "$iface" ]; do
echo No default interface
sleep "$dt"
iface=$(default_interface)
done
case "$unit" in
Kb|Kbit|Kbits) bytes_per_unit=$((1024 / 8));;
KB|KByte|KBytes) bytes_per_unit=$((1024));;
Mb|Mbit|Mbits) bytes_per_unit=$((1024 * 1024 / 8));;
MB|MByte|MBytes) bytes_per_unit=$((1024 * 1024));;
Gb|Gbit|Gbits) bytes_per_unit=$((1024 * 1024 * 1024 / 8));;
GB|GByte|GBytes) bytes_per_unit=$((1024 * 1024 * 1024));;
Tb|Tbit|Tbits) bytes_per_unit=$((1024 * 1024 * 1024 * 1024 / 8));;
TB|TByte|TBytes) bytes_per_unit=$((1024 * 1024 * 1024 * 1024));;
*) echo Bad unit "$unit" && exit 1;;
esac
scalar=$((bytes_per_unit * dt))
init_line=$(cat /proc/net/dev | grep "^[ ]*$iface:")
if [ -z "$init_line" ]; then
echo Interface not found in /proc/net/dev: "$iface"
exit 1
fi
init_received=$(awk '{print $2}' <<< $init_line)
init_sent=$(awk '{print $10}' <<< $init_line)
(while true; do cat /proc/net/dev; sleep "$dt"; done) |\
stdbuf -oL grep "^[ ]*$iface:" |\
awk -v scalar="$scalar" -v unit="$unit" -v iface="$iface" '
BEGIN{old_received='"$init_received"';old_sent='"$init_sent"'}
{
received=$2
sent=$10
rx=(received-old_received)/scalar;
wx=(sent-old_sent)/scalar;
tx=rx+wr;
old_received=received;
old_sent=sent;
if(rx >= 0 && wx >= 0){
'"$printf_command"';
fflush(stdout);
}
}
'

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
#simple Shellscript for i3blocks on Pinebook pro
#05012020 geri123@gmx.net Gerhard S.
#battery-symbols: on Manjaro you need the awesome-terminal-fonts package installed!
PERCENT=$(cat /sys/class/power_supply/cw2015-battery/capacity)
STATUS=$(cat /sys/class/power_supply/cw2015-battery/status)
case $((
$PERCENT >= 0 && $PERCENT <= 20 ? 1 :
$PERCENT > 20 && $PERCENT <= 40 ? 2 :
$PERCENT > 40 && $PERCENT <= 60 ? 3 :
$PERCENT > 60 && $PERCENT <= 80 ? 4 : 5)) in
#
(1) echo $STATUS:"" :$PERCENT%;;
(2) echo $STATUS:"" :$PERCENT%;;
(3) echo $STATUS:"" :$PERCENT%;;
(4) echo $STATUS:"" :$PERCENT%;;
(5) echo $STATUS:"" :$PERCENT%;;
esac

114
home/i3/scripts/battery1 Executable file
View File

@@ -0,0 +1,114 @@
#!/usr/bin/perl
#
# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
#
# Licensed under the terms of the GNU GPL v3, or any later version.
#
# This script is meant to use with i3blocks. It parses the output of the "acpi"
# command (often provided by a package of the same name) to read the status of
# the battery, and eventually its remaining time (to full charge or discharge).
#
# The color will gradually change for a percentage below 85%, and the urgency
# (exit code 33) is set if there is less that 5% remaining.
# Edited by Andreas Lindlbauer <endeavouros.mousily@aleeas.com>
use strict;
use warnings;
use utf8;
# otherwise we get in console "Wide character in print at"
binmode(STDOUT, ':utf8');
# my $acpi;
my $upower;
my $percent;
my $bat_state;
my $status;
my $ac_adapt;
my $full_text;
my $short_text;
my $label = '😅';
my $bat_number = $ENV{BLOCK_INSTANCE} || 0;
open (UPOWER, "upower -i /org/freedesktop/UPower/devices/battery_BAT$bat_number | grep 'percentage' |") or die;
$upower = <UPOWER>;
close(UPOWER);
# fail on unexpected output
if ($upower !~ /: (\d+)%/) {
die "$upower\n";
}
$percent = $1;
$full_text = "$percent%";
open (BAT_STATE, "upower -i /org/freedesktop/UPower/devices/battery_BAT$bat_number | grep 'state' |") or die;
$bat_state = <BAT_STATE>;
close(BAT_STATE);
if ($bat_state !~ /: (\w+)/) {
die "$bat_state\n";
}
$status = $1;
if ($status eq 'discharging') {
$full_text .= ' ';
} elsif ($status eq 'charging') {
$full_text .= ' ';
} elsif ($status eq 'Unknown') {
open (AC_ADAPTER, "acpi -a |") or die;
$ac_adapt = <AC_ADAPTER>;
close(AC_ADAPTER);
if ($ac_adapt =~ /: ([\w-]+)/) {
$ac_adapt = $1;
if ($ac_adapt eq 'on-line') {
$full_text .= ' CHR';
} elsif ($ac_adapt eq 'off-line') {
$full_text .= ' DIS';
}
}
}
$short_text = $full_text;
if ($percent < 20) {
$label = '';
} elsif ($percent < 45) {
$label = '';
} elsif ($percent < 70) {
$label = '';
} elsif ($percent < 95) {
$label = '';
} else {
$label = '';
}
# print text
print " ${label}";
print " $full_text\n";
print " ${label}";
print " $short_text\n";
# consider color and urgent flag only on discharge
if ($status eq 'discharging') {
if ($percent < 20) {
print "#FF0000\n";
} elsif ($percent < 40) {
print "#FFAE00\n";
} elsif ($percent < 60) {
print "#FFF600\n";
} elsif ($percent < 85) {
print "#A8FF00\n";
}
if ($percent < 5) {
exit(33);
}
}
exit(0);

106
home/i3/scripts/battery2 Executable file
View File

@@ -0,0 +1,106 @@
#!/usr/bin/env python3
#
# Copyright (C) 2016 James Murphy
# Licensed under the GPL version 2 only
#
# A battery indicator blocklet script for i3blocks
from subprocess import check_output
import os
import re
config = dict(os.environ)
status = check_output(['acpi'], universal_newlines=True)
if not status:
# stands for no battery found
color = config.get("color_10", "red")
fulltext = "<span color='{}'><span font='FontAwesome'>\uf00d \uf240</span></span>".format(color)
percentleft = 100
else:
# if there is more than one battery in one laptop, the percentage left is
# available for each battery separately, although state and remaining
# time for overall block is shown in the status of the first battery
batteries = status.split("\n")
state_batteries=[]
commasplitstatus_batteries=[]
percentleft_batteries=[]
time = ""
for battery in batteries:
if battery!='':
state_batteries.append(battery.split(": ")[1].split(", ")[0])
commasplitstatus = battery.split(", ")
if not time:
time = commasplitstatus[-1].strip()
# check if it matches a time
time = re.match(r"(\d+):(\d+)", time)
if time:
time = ":".join(time.groups())
timeleft = " ({})".format(time)
else:
timeleft = ""
p = int(commasplitstatus[1].rstrip("%\n"))
if p>0:
percentleft_batteries.append(p)
commasplitstatus_batteries.append(commasplitstatus)
state = state_batteries[0]
commasplitstatus = commasplitstatus_batteries[0]
if percentleft_batteries:
percentleft = int(sum(percentleft_batteries)/len(percentleft_batteries))
else:
percentleft = 0
# stands for charging
color = config.get("color_charging", "yellow")
FA_LIGHTNING = "<span color='{}'><span font='FontAwesome'>\uf0e7</span></span>".format(color)
# stands for plugged in
FA_PLUG = "<span font='FontAwesome'>\uf1e6</span>"
# stands for using battery
FA_BATTERY = "<span font='FontAwesome'>\uf240</span>"
# stands for unknown status of battery
FA_QUESTION = "<span font='FontAwesome'>\uf128</span>"
if state == "Discharging":
fulltext = FA_BATTERY + " "
elif state == "Full":
fulltext = FA_PLUG + " "
timeleft = ""
elif state == "Unknown":
fulltext = FA_QUESTION + " " + FA_BATTERY + " "
timeleft = ""
else:
fulltext = FA_LIGHTNING + " " + FA_PLUG + " "
def color(percent):
if percent < 10:
# exit code 33 will turn background red
return config.get("color_10", "#FFFFFF")
if percent < 20:
return config.get("color_20", "#FF3300")
if percent < 30:
return config.get("color_30", "#FF6600")
if percent < 40:
return config.get("color_40", "#FF9900")
if percent < 50:
return config.get("color_50", "#FFCC00")
if percent < 60:
return config.get("color_60", "#FFFF00")
if percent < 70:
return config.get("color_70", "#FFFF33")
if percent < 80:
return config.get("color_80", "#FFFF66")
return config.get("color_full", "#FFFFFF")
form = '<span color="{}">{}%</span>'
fulltext += form.format(color(percentleft), percentleft)
#fulltext += timeleft
print(fulltext)
print(fulltext)
if percentleft < 10:
exit(33)

11
home/i3/scripts/blur-lock Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
PICTURE=/tmp/i3lock.png
SCREENSHOT="scrot -z $PICTURE"
BLUR="5x4"
$SCREENSHOT
convert $PICTURE -blur $BLUR $PICTURE
i3lock -i $PICTURE
rm $PICTURE

62
home/i3/scripts/cpu_usage Executable file
View File

@@ -0,0 +1,62 @@
#!/usr/bin/env perl
#
# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
#
# Licensed under the terms of the GNU GPL v3, or any later version.
use strict;
use warnings;
use utf8;
use Getopt::Long;
# default values
my $t_warn = $ENV{T_WARN} // 50;
my $t_crit = $ENV{T_CRIT} // 80;
my $cpu_usage = -1;
my $decimals = $ENV{DECIMALS} // 0;
my $label = $ENV{LABEL} // "";
sub help {
print "Usage: cpu_usage [-w <warning>] [-c <critical>] [-d <decimals>]\n";
print "-w <percent>: warning threshold to become yellow\n";
print "-c <percent>: critical threshold to become red\n";
print "-d <decimals>: Use <decimals> decimals for percentage (default is $decimals) \n";
exit 0;
}
GetOptions("help|h" => \&help,
"w=i" => \$t_warn,
"c=i" => \$t_crit,
"d=i" => \$decimals,
);
# Get CPU usage
$ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is
open (MPSTAT, 'mpstat 1 1 |') or die;
while (<MPSTAT>) {
if (/^.*\s+(\d+\.\d+)[\s\x00]?$/) {
$cpu_usage = 100 - $1; # 100% - %idle
last;
}
}
close(MPSTAT);
$cpu_usage eq -1 and die 'Can\'t find CPU information';
# Print short_text, full_text
print "${label}";
printf "%02.${decimals}f%%\n", $cpu_usage;
print "${label}";
printf "%02.${decimals}f%%\n", $cpu_usage;
# Print color, if needed
if ($cpu_usage >= $t_crit) {
print "#FF0000\n";
exit 33;
} elsif ($cpu_usage >= $t_warn) {
print "#FFFC00\n";
}
exit 0;

48
home/i3/scripts/disk Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
DIR="${DIR:-$BLOCK_INSTANCE}"
DIR="${DIR:-$HOME}"
ALERT_LOW="${ALERT_LOW:-$1}"
ALERT_LOW="${ALERT_LOW:-10}" # color will turn red under this value (default: 10%)
LOCAL_FLAG="-l"
if [ "$1" = "-n" ] || [ "$2" = "-n" ]; then
LOCAL_FLAG=""
fi
df -h -P $LOCAL_FLAG "$DIR" | awk -v label="$LABEL" -v alert_low=$ALERT_LOW '
/\/.*/ {
# full text
print label $4
# short text
print label $4
use=$5
# no need to continue parsing
exit 0
}
END {
gsub(/%$/,"",use)
if (100 - use < alert_low) {
# color
print "#FF0000"
}
}
'

10
home/i3/scripts/empty_workspace Executable file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
MAX_DESKTOPS=20
WORKSPACES=$(seq -s '\n' 1 1 ${MAX_DESKTOPS})
EMPTY_WORKSPACE=$( (i3-msg -t get_workspaces | tr ',' '\n' | grep num | awk -F: '{print int($2)}' ; \
echo -e ${WORKSPACES} ) | sort -n | uniq -u | head -n 1)
i3-msg workspace ${EMPTY_WORKSPACE}

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
KBD=$(/usr/bin/xkblayout-state print '%s')
echo $KBD

25
home/i3/scripts/keyhint Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
Main() {
source /usr/share/endeavouros/scripts/eos-script-lib-yad || return 1
local command=(
eos_yad --title="EndeavourOS i3-wm keybindings:" --no-buttons --geometry=400x345-15-400 --list
--column=key: --column=description: --column=command:
"ESC" "close this app" ""
"=" "modkey" "(set mod Mod4)"
"+enter" "open a terminal" ""
"+Shift+n" "new empty workspace" ""
"+w" "open Browser" ""
"+n" "open Filebrowser" ""
"+d" "app menu" ""
"+q" "close focused app" ""
"Print-key" "screenshot" ""
"+Shift+e" "logout menu" ""
"F1" "open keybinding helper" ""
)
"${command[@]}"
}
Main "$@"

6
home/i3/scripts/keyhint-2 Executable file
View File

@@ -0,0 +1,6 @@
I3_CONFIG=$HOME/.config/i3/config
mod_key=$(sed -nre 's/^set \$mod (.*)/\1/p' ${I3_CONFIG})
grep "^bindsym" ${I3_CONFIG} \
| sed "s/-\(-\w\+\)\+//g;s/\$mod/${mod_key}/g;s/Mod1/Alt/g;s/exec //;s/bindsym //;s/^\s\+//;s/^\([^ ]\+\) \(.\+\)$/\2: \1/;s/^\s\+//" \
| tr -s ' ' \
| rofi -dmenu -theme ~/.config/rofi/rofikeyhint.rasi

69
home/i3/scripts/memory Executable file
View File

@@ -0,0 +1,69 @@
#!/usr/bin/env bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
TYPE="${BLOCK_INSTANCE:-mem}"
awk -v type=$TYPE '
/^MemTotal:/ {
mem_total=$2
}
/^MemFree:/ {
mem_free=$2
}
/^Buffers:/ {
mem_free+=$2
}
/^Cached:/ {
mem_free+=$2
}
/^SwapTotal:/ {
swap_total=$2
}
/^SwapFree:/ {
swap_free=$2
}
END {
if (type == "swap") {
free=swap_free/1024/1024
used=(swap_total-swap_free)/1024/1024
total=swap_total/1024/1024
} else {
free=mem_free/1024/1024
used=(mem_total-mem_free)/1024/1024
total=mem_total/1024/1024
}
pct=0
if (total > 0) {
pct=used/total*100
}
# full text
# printf("%.1fG/%.1fG (%.f%%)\n", used, total, pct)
# short text
printf("%.f%%\n", pct)
# color
if (pct > 90) {
print("#FF0000")
} else if (pct > 80) {
print("#FFAE00")
} else if (pct > 70) {
print("#FFF600")
}
}
' /proc/meminfo

93
home/i3/scripts/openweather Executable file
View File

@@ -0,0 +1,93 @@
#!/usr/bin/env bash
# Edited by Andreas Lindlbauer <endeavouros.mousily@aleeas.com>
temps=("#0600FF" "#0500FF" "#0400FF" "#0300FF" "#0200FF" "#0100FF" "#0000FF" "#0002FF" "#0012FF" "#0022FF" "#0032FF" "#0044FF" "#0054FF" "#0064FF" "#0074FF" "#0084FF" "#0094FF" "#00A4FF" "#00B4FF" "#00C4FF" "#00D4FF" "#00E4FF" "#00FFF4" "#00FFD0" "#00FFA8" "#00FF83" "#00FF5C" "#00FF36" "#00FF10" "#17FF00" "#3EFF00" "#65FF00" "#B0FF00" "#FDFF00" "#FFF000" "#FFDC00" "#FFC800" "#FFB400" "#FFA000" "#FF8C00" "#FF7800" "#FF6400" "#FF5000" "#FF3C00" "#FF2800" "#FF1400" "#FF0000")
command -v jq >/dev/null 2>&1 || { echo >&2 "Program 'jq' required but it is not installed.
Aborting."; exit 1; }
command -v wget >/dev/null 2>&1 || { echo >&2 "Program 'wget' required but is not installed.
Aborting."; exit 1; }
# To use this script you need to create an API key here https://home.openweathermap.org
# You need to put your Open Weather APIKEY here:
APIKEY="keykeykey"
# And get your Latitute and Longitudes to put in here:
LAT="XX.XXXX"
LON="XX.XXXX"
URL="http://api.openweathermap.org/data/2.5/onecall?lat=${LAT}&lon=${LON}&units=metric&exclude=minutely,hourly,daily&APPID=${APIKEY}"
WEATHER_RESPONSE=$(wget -qO- "${URL}")
WEATHER_CONDITION=$(echo "$WEATHER_RESPONSE" | jq '.current.weather[0].main' | sed 's/"//g')
WEATHER_TEMP=$(echo "$WEATHER_RESPONSE" | jq '.current.feels_like')
WEATHER_INT=${WEATHER_TEMP%.*}
TIME_NOW=$( echo "$WEATHER_RESPONSE" | jq '.current.dt')
SUNRISE=$( echo "$WEATHER_RESPONSE" | jq '.current.sunrise')
SUNSET=$( echo "$WEATHER_RESPONSE" | jq '.current.sunset')
DESCRIPTION=$( echo "$WEATHER_RESPONSE" | jq '.current.weather[0].description' | sed 's/"//g')
WEATHER_ALERT=$( echo "$WEATHER_RESPONSE" | jq '.alerts[0].event' | sed 's/"//g')
DAYTIME="n"
if [[ "$TIME_NOW" > "$SUNRISE" ]] && [[ "$TIME_NOW" < "$SUNSET" ]]; then
DAYTIME="d"
fi
case $WEATHER_CONDITION in
'Clouds')
if [ "$DAYTIME" == "d" ]; then
WEATHER_ICON=""
else
WEATHER_ICON=""
fi
;;
'Rain')
WEATHER_ICON=""
;;
'Drizzle')
if [ "$DAYTIME" == "d" ]; then
WEATHER_ICON=""
else
WEATHER_ICON=""
fi
;;
'Thunderstorm')
WEATHER_ICON=""
;;
'Snow')
WEATHER_ICON=""
;;
'Clear')
if [ "$DAYTIME" == "d" ]; then
WEATHER_ICON=""
else
WEATHER_ICON=""
fi
;;
*)
WEATHER_ICON="🌫"
;;
esac
WEATHER_COLOR="#FFFFFF"
if [ "$WEATHER_INT" -lt "-11" ]; then
WEATHER_COLOR="#0000FF"
elif [ "$WEATHER_INT" -gt 35 ]; then
WEATHER_COLOR="#FF0000"
else
WEATHER_INT=$(( WEATHER_INT + 11 ))
WEATHER_COLOR="${temps[$WEATHER_INT]}"
fi
full_text="${WEATHER_ICON} ${WEATHER_TEMP}°C: ${DESCRIPTION} "
if [ "$WEATHER_ALERT" != "null" ]; then
WARN_START=$(echo "$WEATHER_RESPONSE" | jq '.alerts[0].start')
WARN_END=$(echo "$WEATHER_RESPONSE" | jq '.alerts[0].end')
WARN_START=$(date -d @"$WARN_START" +%a_%k:%M)
WARN_END=$(date -d @"$WARN_END" +%a_%k:%M)
full_text="${WEATHER_ICON} ${WEATHER_TEMP}°C: ${DESCRIPTION}  ${WEATHER_ALERT} from ${WARN_START} to ${WARN_END}  "
fi
echo "${full_text}"
echo "${WEATHER_TEMP}°C "
echo "${WEATHER_COLOR}"

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env bash
command -v jq >/dev/null 2>&1 || { echo >&2 "Program 'jq' required but it is not installed.
Aborting."; exit 1; }
command -v wget >/dev/null 2>&1 || { echo >&2 "Program 'wget' required but is not installed.
Aborting."; exit 1; }
# To use this script you need to create an API key here https://home.openweathermap.org
# You need to put your Open Weather APIKEY here:
APIKEY="keykey"
# find your City ID here: https://openweathermap.org/
# search for your city and copy the ID from the URL inside the browser.
CITY_ID="idid"
URL="http://api.openweathermap.org/data/2.5/weather?id=${CITY_ID}&units=metric&APPID=${APIKEY}"
WEATHER_RESPONSE=$(wget -qO- "${URL}")
WEATHER_CONDITION=$(echo $WEATHER_RESPONSE | jq '.weather[0].main' | sed 's/"//g')
WEATHER_TEMP=$(echo $WEATHER_RESPONSE | jq '.main.temp')
WIND_DIR=$( echo "$WEATHER_RESPONSE" | jq '.wind.deg')
WIND_SPEED=$( echo "$WEATHER_RESPONSE" | jq '.wind.speed')
WIND_SPEED=$(awk "BEGIN {print 60*60*$WIND_SPEED/1000}")
WIND_DIR=$(awk "BEGIN {print int(($WIND_DIR % 360)/22.5)}")
DIR_ARRAY=( N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW N )
WIND_DIR=${DIR_ARRAY[WIND_DIR]}
case $WEATHER_CONDITION in
'Clouds')
WEATHER_ICON=""
;;
'Rain')
WEATHER_ICON=""
;;
'Snow')
WEATHER_ICON=""
;;
*)
WEATHER_ICON=""
;;
esac
echo "${WEATHER_ICON} ${WEATHER_TEMP}°C: ${WIND_SPEED} km/h ${WIND_DIR}"

View File

@@ -0,0 +1,5 @@
# Weather
[Weather]
command=~/.config/i3/scripts/openweather
interval=1800
color=#7275b3

190
home/i3/scripts/power-profiles Executable file
View File

@@ -0,0 +1,190 @@
#!/usr/bin/env bash
#
# Use rofi/zenity to change system runstate thanks to systemd.
#
# Note: this currently relies on associative array support in the shell.
#
# Inspired from i3pystatus wiki:
# https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu
#
# Copyright 2015 Benjamin Chrétien <chretien at lirmm dot fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# power-profiles-daemon implementation:
# needs package power-profiles-daemon installed and the service running see here:
# https://wiki.archlinux.org/title/CPU_frequency_scaling#power-profiles-daemon
# used in i3-blocks: ~/.config/i3/i3blocks.conf together with: ~/.config/i3/scripts/ppd-status
#######################################################################
# BEGIN CONFIG #
#######################################################################
# Use a custom lock script
#LOCKSCRIPT="i3lock-extra -m pixelize"
# Colors: FG (foreground), BG (background), HL (highlighted)
FG_COLOR="#bbbbbb"
BG_COLOR="#111111"
HLFG_COLOR="#111111"
HLBG_COLOR="#bbbbbb"
BORDER_COLOR="#222222"
# Options not related to colors
#ROFI_TEXT=":"
#ROFI_OPTIONS=(-width -11 -location 0 -hide-scrollbar -bw 30 -color-window "#dd310027,#dd0310027,#dd310027" -padding 5)
#ROFI_OPTIONS=(-width -18 -location 4 -hide-scrollbar -color-window "#cc310027,#00a0009a,#cc310027" -padding 5 -font "Sourcecode Pro Regular 10, FontAwesome 9")
ROFI_OPTIONS=(-theme ~/.config/rofi/power-profiles.rasi)
# Zenity options
ZENITY_TITLE="Power Profiles"
ZENITY_TEXT="Set Profiles:"
ZENITY_OPTIONS=(--column= --hide-header)
#######################################################################
# END CONFIG #
#######################################################################
# Whether to ask for user's confirmation
enable_confirmation=false
# Preferred launcher if both are available
preferred_launcher="rofi"
usage="$(basename "$0") [-h] [-c] [-p name] -- display a menu for shutdown, reboot, lock etc.
where:
-h show this help text
-c ask for user confirmation
-p preferred launcher (rofi or zenity)
This script depends on:
- systemd,
- i3,
- rofi or zenity."
# Check whether the user-defined launcher is valid
launcher_list=(rofi zenity)
function check_launcher() {
if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then
echo "Supported launchers: ${launcher_list[*]}"
exit 1
else
# Get array with unique elements and preferred launcher first
# Note: uniq expects a sorted list, so we cannot use it
i=1
launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \
| sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' '))
fi
}
# Parse CLI arguments
while getopts "hcp:" option; do
case "${option}" in
h) echo "${usage}"
exit 0
;;
c) enable_confirmation=true
;;
p) preferred_launcher="${OPTARG}"
check_launcher "${preferred_launcher}"
;;
*) exit 1
;;
esac
done
# Check whether a command exists
function command_exists() {
command -v "$1" &> /dev/null 2>&1
}
# systemctl required
if ! command_exists systemctl ; then
exit 1
fi
# menu defined as an associative array
typeset -A menu
# Menu with keys/commands
menu=(
[ Performance]="powerprofilesctl set performance"
[ Balanced]="powerprofilesctl set balanced"
[ Power Saver]="powerprofilesctl set power-saver"
[ Cancel]=""
)
menu_nrows=${#menu[@]}
# Menu entries that may trigger a confirmation message
menu_confirm="Shutdown Reboot Hibernate Suspend Halt Logout"
launcher_exe=""
launcher_options=""
rofi_colors=""
function prepare_launcher() {
if [[ "$1" == "rofi" ]]; then
rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \
-hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}")
launcher_exe="rofi"
launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \
"${rofi_colors}" "${ROFI_OPTIONS[@]}")
elif [[ "$1" == "zenity" ]]; then
launcher_exe="zenity"
launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \
"${ZENITY_OPTIONS[@]}")
fi
}
for l in "${launcher_list[@]}"; do
if command_exists "${l}" ; then
prepare_launcher "${l}"
break
fi
done
# No launcher available
if [[ -z "${launcher_exe}" ]]; then
exit 1
fi
launcher=(${launcher_exe} "${launcher_options[@]}")
selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")"
function ask_confirmation() {
if [ "${launcher_exe}" == "rofi" ]; then
confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \
"${rofi_colors}" "${ROFI_OPTIONS[@]}")
[ "${confirmed}" == "Yes" ] && confirmed=0
elif [ "${launcher_exe}" == "zenity" ]; then
zenity --question --text "Are you sure you want to ${selection,,}?"
confirmed=$?
fi
if [ "${confirmed}" == 0 ]; then
i3-msg -q "exec --no-startup-id ${menu[${selection}]}"
fi
}
if [[ $? -eq 0 && ! -z ${selection} ]]; then
if [[ "${enable_confirmation}" = true && \
${menu_confirm} =~ (^|[[:space:]])"${selection}"($|[[:space:]]) ]]; then
ask_confirmation
else
i3-msg -q "exec --no-startup-id ${menu[${selection}]}"
fi
fi

186
home/i3/scripts/powermenu Executable file
View File

@@ -0,0 +1,186 @@
#!/usr/bin/env bash
#
# Use rofi/zenity to change system runstate thanks to systemd.
#
# Note: this currently relies on associative array support in the shell.
#
# Inspired from i3pystatus wiki:
# https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu
#
# Copyright 2015 Benjamin Chrétien <chretien at lirmm dot fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# modified to work with latest rofi update by joekamprad <joekamprad@endeavouros.com>
#######################################################################
# BEGIN CONFIG #
#######################################################################
# Use a custom lock script
#LOCKSCRIPT="i3lock-extra -m pixelize"
# Colors: FG (foreground), BG (background), HL (highlighted)
FG_COLOR="#bbbbbb"
BG_COLOR="#111111"
HLFG_COLOR="#111111"
HLBG_COLOR="#bbbbbb"
BORDER_COLOR="#222222"
# Options not related to colors (most rofi options do not work anymore)
ROFI_OPTIONS=(-theme ~/.config/rofi/powermenu.rasi)
# Zenity options
ZENITY_TITLE="Power Menu"
ZENITY_TEXT="Action:"
ZENITY_OPTIONS=(--column= --hide-header)
#######################################################################
# END CONFIG #
#######################################################################
# Whether to ask for user's confirmation
enable_confirmation=false
# Preferred launcher if both are available
preferred_launcher="rofi"
usage="$(basename "$0") [-h] [-c] [-p name] -- display a menu for shutdown, reboot, lock etc.
where:
-h show this help text
-c ask for user confirmation
-p preferred launcher (rofi or zenity)
This script depends on:
- systemd,
- i3,
- rofi or zenity."
# Check whether the user-defined launcher is valid
launcher_list=(rofi zenity)
function check_launcher() {
if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then
echo "Supported launchers: ${launcher_list[*]}"
exit 1
else
# Get array with unique elements and preferred launcher first
# Note: uniq expects a sorted list, so we cannot use it
i=1
launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \
| sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' '))
fi
}
# Parse CLI arguments
while getopts "hcp:" option; do
case "${option}" in
h) echo "${usage}"
exit 0
;;
c) enable_confirmation=true
;;
p) preferred_launcher="${OPTARG}"
check_launcher "${preferred_launcher}"
;;
*) exit 1
;;
esac
done
# Check whether a command exists
function command_exists() {
command -v "$1" &> /dev/null 2>&1
}
# systemctl required
if ! command_exists systemctl ; then
exit 1
fi
# menu defined as an associative array
typeset -A menu
# Menu with keys/commands
menu=(
[ Shutdown]="systemctl poweroff"
[ Reboot]="systemctl reboot"
[ Suspend]="systemctl suspend"
[ Hibernate]="systemctl hibernate"
[ Lock]="~/.config/i3/scripts/blur-lock"
[ Logout]="i3-msg exit"
[ Cancel]=""
)
menu_nrows=${#menu[@]}
# Menu entries that may trigger a confirmation message
menu_confirm="Shutdown Reboot Hibernate Suspend Halt Logout"
launcher_exe=""
launcher_options=""
rofi_colors=""
function prepare_launcher() {
if [[ "$1" == "rofi" ]]; then
rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \
-hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}")
launcher_exe="rofi"
launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \
"${rofi_colors}" "${ROFI_OPTIONS[@]}")
elif [[ "$1" == "zenity" ]]; then
launcher_exe="zenity"
launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \
"${ZENITY_OPTIONS[@]}")
fi
}
for l in "${launcher_list[@]}"; do
if command_exists "${l}" ; then
prepare_launcher "${l}"
break
fi
done
# No launcher available
if [[ -z "${launcher_exe}" ]]; then
exit 1
fi
launcher=(${launcher_exe} "${launcher_options[@]}")
selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")"
function ask_confirmation() {
if [ "${launcher_exe}" == "rofi" ]; then
confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \
"${rofi_colors}" "${ROFI_OPTIONS[@]}")
[ "${confirmed}" == "Yes" ] && confirmed=0
elif [ "${launcher_exe}" == "zenity" ]; then
zenity --question --text "Are you sure you want to ${selection,,}?"
confirmed=$?
fi
if [ "${confirmed}" == 0 ]; then
i3-msg -q "exec --no-startup-id ${menu[${selection}]}"
fi
}
if [[ $? -eq 0 && ! -z ${selection} ]]; then
if [[ "${enable_confirmation}" = true && \
${menu_confirm} =~ (^|[[:space:]])"${selection}"($|[[:space:]]) ]]; then
ask_confirmation
else
i3-msg -q "exec --no-startup-id ${menu[${selection}]}"
fi
fi

11
home/i3/scripts/ppd-status Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
#
# power-profiles-daemon implementation:
# needs package power-profiles-daemon installed and the service running see here:
# https://wiki.archlinux.org/title/CPU_frequency_scaling#power-profiles-daemon
# used in i3-blocks: ~/.config/i3/i3blocks.conf together with: ~/.config/i3/scripts/power-profiles
# script to show current power profile
current_profile=$(powerprofilesctl get)
echo "$current_profile"

86
home/i3/scripts/temperature Executable file
View File

@@ -0,0 +1,86 @@
#!/usr/bin/env perl
# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
# Copyright 2014 Benjamin Chretien <chretien at lirmm dot fr>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Edited by Andreas Lindlbauer <endeavouros.mousily@aleeas.com>
use strict;
use warnings;
use utf8;
use Getopt::Long;
binmode(STDOUT, ":utf8");
# default values
my $t_warn = $ENV{T_WARN} || 70;
my $t_crit = $ENV{T_CRIT} || 90;
my $chip = $ENV{SENSOR_CHIP} || "";
my $temperature = -9999;
my $label = "😀 ";
sub help {
print "Usage: temperature [-w <warning>] [-c <critical>] [--chip <chip>]\n";
print "-w <percent>: warning threshold to become yellow\n";
print "-c <percent>: critical threshold to become red\n";
print "--chip <chip>: sensor chip\n";
exit 0;
}
GetOptions("help|h" => \&help,
"w=i" => \$t_warn,
"c=i" => \$t_crit,
"chip=s" => \$chip);
# Get chip temperature
open (SENSORS, "sensors -u $chip |") or die;
while (<SENSORS>) {
if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) {
$temperature = $1;
last;
}
}
close(SENSORS);
$temperature eq -9999 and die 'Cannot find temperature';
if ($temperature < 45) {
$label = '';
} elsif ($temperature < 55) {
$label = '';
} elsif ($temperature < 65) {
$label = '';
} elsif ($temperature < 75) {
$label = '';
} else {
$label = '';
}
# Print short_text, full_text
print "${label}";
print " $temperature°C\n";
print "${label}";
print " $temperature°C\n";
# Print color, if needed
if ($temperature >= $t_crit) {
print "#FF0000\n";
exit 33;
} elsif ($temperature >= $t_warn) {
print "#FFFC00\n";
}
exit 0;

93
home/i3/scripts/volume Executable file
View File

@@ -0,0 +1,93 @@
#!/usr/bin/env bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# original source: https://github.com/vivien/i3blocks-contrib/tree/master/volume
# check the readme: https://github.com/vivien/i3blocks-contrib/blob/master/volume/README.md
#------------------------------------------------------------------------
# The second parameter overrides the mixer selection
# For PulseAudio users, eventually use "pulse"
# For Jack/Jack2 users, use "jackplug"
# For ALSA users, you may use "default" for your primary card
# or you may use hw:# where # is the number of the card desired
if [[ -z "$MIXER" ]] ; then
MIXER="default"
if command -v pulseaudio >/dev/null 2>&1 && pulseaudio --check ; then
# pulseaudio is running, but not all installations use "pulse"
if amixer -D pulse info >/dev/null 2>&1 ; then
MIXER="pulse"
fi
fi
[ -n "$(lsmod | grep jack)" ] && MIXER="jackplug"
MIXER="${2:-$MIXER}"
fi
# The instance option sets the control to report and configure
# This defaults to the first control of your selected mixer
# For a list of the available, use `amixer -D $Your_Mixer scontrols`
if [[ -z "$SCONTROL" ]] ; then
SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols |
sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" |
head -n1
)}"
fi
# The first parameter sets the step to change the volume by (and units to display)
# This may be in in % or dB (eg. 5% or 3dB)
if [[ -z "$STEP" ]] ; then
STEP="${1:-5%}"
fi
# AMIXER(1):
# "Use the mapped volume for evaluating the percentage representation like alsamixer, to be
# more natural for human ear."
NATURAL_MAPPING=${NATURAL_MAPPING:-0}
if [[ "$NATURAL_MAPPING" != "0" ]] ; then
AMIXER_PARAMS="-M"
fi
#------------------------------------------------------------------------
capability() { # Return "Capture" if the device is a capture device
amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL |
sed -n "s/ Capabilities:.*cvolume.*/Capture/p"
}
volume() {
amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL $(capability)
}
format() {
perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)'
perl_filter+='{CORE::say $4 eq "off" ? "MUTE" : "'
# If dB was selected, print that instead
perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1')
perl_filter+='"; exit}'
output=$(perl -ne "$perl_filter")
echo "$LABEL$output"
}
#------------------------------------------------------------------------
case $BLOCK_BUTTON in
3) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) toggle ;; # right click, mute/unmute
4) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase
5) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease
esac
volume | format

25
home/i3/scripts/vpn Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
#
# Copyright (C) 2021 Andreas Lindlbauer
# Licensed under the terms of EUPLv1.2.
#
# i3blocks blocklet script to monitor the (nord)vpn connection
vpnstatus="📢"
nordvpn_output=$(nordvpn status | cat -v | head -1 | sed -e 's/\^M-^M ^M//g' )
if [ "${nordvpn_output}" = "Status: Connected" ]; then
vpnstatus="🥸"
elif [ "${nordvpn_output}" = "A new version of NordVPN is available! Please update the application." ]; then
nordvpn_output=$(nordvpn status | cat -v | head -2 | tail -1 | sed -e 's/\^M-^M ^M//g' )
if [ "${nordvpn_output}" = "Status: Connected" ]; then
vpnstatus="🥴"
elif [ "${nordvpn_output}" = "Status: Disconnected" ]; then
vpnstatus="📢"
fi
elif [ "${nordvpn_output}" = "Status: Disconnected" ]; then
vpnstatus="📢"
elif [[ "$nordvpn_output" == *\/* ]] || [[ "$nordvpn_output" == *\\* ]]; then
vpnstatus="Something's very wrong"
fi
echo "$vpnstatus"

View File

@@ -0,0 +1,20 @@
{
pkgs,
config,
...
}: {
programs = {
chromium = {
enable = true;
commandLineArgs = ["--enable-features=TouchpadOverscrollHistoryNavigation"];
extensions = [
# {id = "";} // extension id, query from chrome web store
];
};
firefox = {
enable = true;
profiles.ryan = {};
};
};
}

86
home/programs/common.nix Normal file
View File

@@ -0,0 +1,86 @@
{pkgs, ...}: {
home.packages = with pkgs; [
# archives
zip
unzip
p7zip
# utils
ripgrep
yq-go # https://github.com/mikefarah/yq
htop
# misc
libnotify
wineWowPackages.wayland
xdg-utils
graphviz
# productivity
obsidian
# IDE
insomnia
# cloud native
docker-compose
kubectl
nodejs
nodePackages.npm
nodePackages.pnpm
yarn
# db related
dbeaver
mycli
pgcli
];
programs = {
tmux = {
enable = true;
clock24 = true;
keyMode = "vi";
extraConfig = "mouse on";
};
bat = {
enable = true;
config = {
pager = "less -FR";
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=";
});
};
};
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
ssh.enable = true;
aria2.enable = true;
skim = {
enable = true;
enableZshIntegration = true;
defaultCommand = "rg --files --hidden";
changeDirWidgetOptions = [
"--preview 'exa --icons --git --color always -T -L 3 {} | head -200'"
"--exact"
];
};
};
services = {
syncthing.enable = true;
# auto mount usb drives
udiskie.enable = true;
};
}

14
home/programs/default.nix Normal file
View File

@@ -0,0 +1,14 @@
{
config,
pkgs,
...
}: {
imports = [
./browsers.nix
./common.nix
./git.nix
./media.nix
./vscode.nix
./xdg.nix
];
}

13
home/programs/git.nix Normal file
View File

@@ -0,0 +1,13 @@
{
pkgs,
...
}: {
home.packages = [pkgs.gh];
programs.git = {
enable = true;
userName = "Ryan Yin";
userEmail = "xiaoyin_c@qq.com";
};
}

33
home/programs/media.nix Normal file
View File

@@ -0,0 +1,33 @@
{
pkgs,
config,
...
}:
# media - control and enjoy audio/video
{
# imports = [
# ];
home.packages = with pkgs; [
# audio control
pavucontrol
playerctl
pulsemixer
# images
imv
];
programs = {
mpv = {
enable = true;
defaultProfiles = ["gpu-hq"];
scripts = [pkgs.mpvScripts.mpris];
};
obs-studio.enable = true;
};
services = {
playerctld.enable = true;
};
}

119
home/programs/vscode.nix Normal file
View File

@@ -0,0 +1,119 @@
{
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
];
};
}

47
home/programs/xdg.nix Normal file
View File

@@ -0,0 +1,47 @@
{config, ...}: let
browser = ["firefox.desktop"];
# XDG MIME types
associations = {
"application/x-extension-htm" = browser;
"application/x-extension-html" = browser;
"application/x-extension-shtml" = browser;
"application/x-extension-xht" = browser;
"application/x-extension-xhtml" = browser;
"application/xhtml+xml" = browser;
"text/html" = browser;
"x-scheme-handler/about" = browser;
"x-scheme-handler/chrome" = ["chromium-browser.desktop"];
"x-scheme-handler/ftp" = browser;
"x-scheme-handler/http" = browser;
"x-scheme-handler/https" = browser;
"x-scheme-handler/unknown" = browser;
"audio/*" = ["mpv.desktop"];
"video/*" = ["mpv.dekstop"];
"image/*" = ["imv.desktop"];
"application/json" = browser;
"application/pdf" = ["org.pwmt.zathura.desktop.desktop"];
"x-scheme-handler/discord" = ["discordcanary.desktop"];
"x-scheme-handler/spotify" = ["spotify.desktop"];
"x-scheme-handler/tg" = ["telegramdesktop.desktop"];
};
in {
xdg = {
enable = true;
cacheHome = config.home.homeDirectory + "/.local/cache";
mimeApps = {
enable = true;
defaultApplications = associations;
};
userDirs = {
enable = true;
createDirectories = true;
extraConfig = {
XDG_SCREENSHOTS_DIR = "${config.xdg.userDirs.pictures}/Screenshots";
};
};
};
}

View File

@@ -0,0 +1,34 @@
/*******************************************************
* ROFI Arc Dark colors for EndeavourOS
* Maintainer: joekamprad <joekamprad@endeavouros.com>
*******************************************************/
* {
selected-normal-foreground: rgba ( 249, 249, 249, 100 % );
foreground: rgba ( 196, 203, 212, 100 % );
normal-foreground: @foreground;
alternate-normal-background: rgba ( 64, 69, 82, 59 % );
red: rgba ( 220, 50, 47, 100 % );
selected-urgent-foreground: rgba ( 249, 249, 249, 100 % );
blue: rgba ( 38, 139, 210, 100 % );
urgent-foreground: rgba ( 204, 102, 102, 100 % );
alternate-urgent-background: rgba ( 75, 81, 96, 90 % );
active-foreground: rgba ( 101, 172, 255, 100 % );
lightbg: rgba ( 238, 232, 213, 100 % );
selected-active-foreground: rgba ( 249, 249, 249, 100 % );
alternate-active-background: rgba ( 75, 81, 96, 89 % );
background: rgba ( 45, 48, 59, 95 % );
alternate-normal-foreground: @foreground;
normal-background: @background;
lightfg: rgba ( 88, 104, 117, 100 % );
selected-normal-background: rgba ( 64, 132, 214, 100 % );
border-color: rgba ( 124, 131, 137, 100 % );
spacing: 2;
separatorcolor: rgba ( 29, 31, 33, 100 % );
urgent-background: rgba ( 29, 31, 33, 17 % );
selected-urgent-background: rgba ( 165, 66, 66, 100 % );
alternate-urgent-foreground: @urgent-foreground;
background-color: rgba ( 0, 0, 0, 0 % );
alternate-active-foreground: @active-foreground;
active-background: rgba ( 29, 31, 33, 17 % );
selected-active-background: rgba ( 68, 145, 237, 100 % );
}

View File

@@ -0,0 +1,34 @@
/*******************************************************
* ROFI Arch Dark Transparent colors for EndeavourOS
* Maintainer: joekamprad <joekamprad@endeavouros.com>
*******************************************************/
* {
selected-normal-foreground: rgba ( 255, 147, 5, 100 % );
foreground: rgba ( 196, 203, 212, 100 % );
normal-foreground: @foreground;
alternate-normal-background: rgba ( 45, 48, 59, 1 % );
red: rgba ( 220, 50, 47, 100 % );
selected-urgent-foreground: rgba ( 249, 249, 249, 100 % );
blue: rgba ( 38, 139, 210, 100 % );
urgent-foreground: rgba ( 204, 102, 102, 100 % );
alternate-urgent-background: rgba ( 75, 81, 96, 90 % );
active-foreground: rgba ( 101, 172, 255, 100 % );
lightbg: rgba ( 238, 232, 213, 100 % );
selected-active-foreground: rgba ( 249, 249, 249, 100 % );
alternate-active-background: rgba ( 45, 48, 59, 88 % );
background: rgba ( 45, 48, 59, 88 % );
alternate-normal-foreground: @foreground;
normal-background: rgba ( 45, 48, 59, 1 % );
lightfg: rgba ( 88, 104, 117, 100 % );
selected-normal-background: rgba ( 24, 26, 32, 100 % );
border-color: rgba ( 124, 131, 137, 100 % );
spacing: 2;
separatorcolor: rgba ( 45, 48, 59, 1 % );
urgent-background: rgba ( 45, 48, 59, 15 % );
selected-urgent-background: rgba ( 165, 66, 66, 100 % );
alternate-urgent-foreground: @urgent-foreground;
background-color: rgba ( 0, 0, 0, 0 % );
alternate-active-foreground: @active-foreground;
active-background: rgba ( 29, 31, 33, 17 % );
selected-active-background: rgba ( 26, 28, 35, 100 % );
}

View File

@@ -0,0 +1,121 @@
/*******************************************************
* ROFI configs i3 powermenu for EndeavourOS
* Maintainer: joekamprad <joekamprad@endeavouros.com>
*******************************************************/
configuration {
font: "Noto Sans Regular 10";
show-icons: false;
icon-theme: "Qogir";
scroll-method: 0;
disable-history: false;
fullscreen: false;
hide-scrollbar: true;
sidebar-mode: false;
}
@import "~/.config/rofi/arc_dark_colors.rasi"
window {
background-color: @background;
border: 0;
padding: 10;
transparency: "real";
width: 170px;
location: east;
/*y-offset: 18;*/
/*x-offset: 850;*/
}
listview {
lines: 4;
columns: 1;
}
element {
border: 0;
padding: 1px;
}
element-text {
background-color: inherit;
text-color: inherit;
}
element.normal.normal {
background-color: @normal-background;
text-color: @normal-foreground;
}
element.normal.urgent {
background-color: @urgent-background;
text-color: @urgent-foreground;
}
element.normal.active {
background-color: @active-background;
text-color: @active-foreground;
}
element.selected.normal {
background-color: @selected-normal-background;
text-color: @selected-normal-foreground;
}
element.selected.urgent {
background-color: @selected-urgent-background;
text-color: @selected-urgent-foreground;
}
element.selected.active {
background-color: @selected-active-background;
text-color: @selected-active-foreground;
}
element.alternate.normal {
background-color: @alternate-normal-background;
text-color: @alternate-normal-foreground;
}
element.alternate.urgent {
background-color: @alternate-urgent-background;
text-color: @alternate-urgent-foreground;
}
element.alternate.active {
background-color: @alternate-active-background;
text-color: @alternate-active-foreground;
}
scrollbar {
width: 4px;
border: 0;
handle-color: @normal-foreground;
handle-width: 8px;
padding: 0;
}
mode-switcher {
border: 2px 0px 0px;
border-color: @separatorcolor;
}
button {
spacing: 0;
text-color: @normal-foreground;
}
button.selected {
background-color: @selected-normal-background;
text-color: @selected-normal-foreground;
}
inputbar {
spacing: 0;
text-color: @normal-foreground;
padding: 1px;
}
case-indicator {
spacing: 0;
text-color: @normal-foreground;
}
entry {
spacing: 0;
text-color: @normal-foreground;
}
prompt {
spacing: 0;
text-color: @normal-foreground;
}
inputbar {
children: [ prompt,textbox-prompt-colon,entry,case-indicator ];
}
textbox-prompt-colon {
expand: false;
str: "Set Power Profile:";
margin: 0px 0.3em 0em 0em;
text-color: @normal-foreground;
}

View File

@@ -0,0 +1,124 @@
/*******************************************************
* ROFI configs i3 powermenu for EndeavourOS
* Maintainer: joekamprad <joekamprad@endeavouros.com>
*******************************************************/
configuration {
font: "Noto Sans Regular 10";
show-icons: false;
icon-theme: "Qogir";
scroll-method: 0;
disable-history: false;
sidebar-mode: false;
}
@import "~/.config/rofi/arc_dark_transparent_colors.rasi"
window {
background-color: @background;
border: 0;
padding: 10;
transparency: "real";
width: 120px;
location: east;
/*y-offset: 18;*/
/*x-offset: 850;*/
}
listview {
lines: 7;
columns: 1;
scrollbar: false;
}
element {
border: 0;
padding: 1px;
}
element-text {
background-color: inherit;
text-color: inherit;
}
element.normal.normal {
background-color: @normal-background;
text-color: @normal-foreground;
}
element.normal.urgent {
background-color: @urgent-background;
text-color: @urgent-foreground;
}
element.normal.active {
background-color: @active-background;
text-color: @active-foreground;
}
element.selected.normal {
background-color: @selected-normal-background;
text-color: @selected-normal-foreground;
}
element.selected.urgent {
background-color: @selected-urgent-background;
text-color: @selected-urgent-foreground;
}
element.selected.active {
background-color: @selected-active-background;
text-color: @selected-active-foreground;
}
element.alternate.normal {
background-color: @alternate-normal-background;
text-color: @alternate-normal-foreground;
}
element.alternate.urgent {
background-color: @alternate-urgent-background;
text-color: @alternate-urgent-foreground;
}
element.alternate.active {
background-color: @alternate-active-background;
text-color: @alternate-active-foreground;
}
scrollbar {
width: 4px;
border: 0;
handle-color: @normal-foreground;
handle-width: 8px;
padding: 0;
}
mode-switcher {
border: 2px 0px 0px;
border-color: @separatorcolor;
}
button {
spacing: 0;
text-color: @normal-foreground;
}
button.selected {
background-color: @selected-normal-background;
text-color: @selected-normal-foreground;
}
inputbar {
spacing: 0;
text-color: @normal-foreground;
padding: 1px;
}
case-indicator {
spacing: 0;
text-color: @normal-foreground;
}
entry {
spacing: 0;
text-color: @normal-foreground;
}
prompt {
spacing: 0;
text-color: @normal-foreground;
}
inputbar {
children: [ prompt,textbox-prompt-colon,entry,case-indicator ];
}
textbox-prompt-colon {
expand: false;
str: ":";
margin: 0px 0.3em 0em 0em;
text-color: @normal-foreground;
}
/*removes the text input line*/
mainbox {
children: [listview];
}

View File

@@ -0,0 +1,135 @@
/*******************************************************
* ROFI configs i3 Apps menu for EndeavourOS
* Maintainer: joekamprad <joekamprad@endeavouros.com>
*******************************************************/
configuration {
font: "Noto Sans Regular 10";
show-icons: true;
icon-theme: "Qogir";
display-drun: "Apps";
drun-display-format: "{name}";
scroll-method: 0;
disable-history: false;
sidebar-mode: false;
}
@import "~/.config/rofi/arc_dark_transparent_colors.rasi"
window {
background-color: @background;
border: 0;
padding: 30;
}
listview {
lines: 10;
columns: 3;
}
mainbox {
border: 0;
padding: 0;
}
message {
border: 2px 0px 0px;
border-color: @separatorcolor;
padding: 1px;
}
textbox {
text-color: @foreground;
}
listview {
fixed-height: 0;
border: 8px 0px 0px;
border-color: @separatorcolor;
spacing: 8px;
scrollbar: false;
padding: 2px 0px 0px;
}
element {
border: 0;
padding: 1px;
}
element-text {
background-color: inherit;
text-color: inherit;
}
element.normal.normal {
background-color: @normal-background;
text-color: @normal-foreground;
}
element.normal.urgent {
background-color: @urgent-background;
text-color: @urgent-foreground;
}
element.normal.active {
background-color: @active-background;
text-color: @active-foreground;
}
element.selected.normal {
background-color: @selected-normal-background;
text-color: @selected-normal-foreground;
}
element.selected.urgent {
background-color: @selected-urgent-background;
text-color: @selected-urgent-foreground;
}
element.selected.active {
background-color: @selected-active-background;
text-color: @selected-active-foreground;
}
element.alternate.normal {
background-color: @alternate-normal-background;
text-color: @alternate-normal-foreground;
}
element.alternate.urgent {
background-color: @alternate-urgent-background;
text-color: @alternate-urgent-foreground;
}
element.alternate.active {
background-color: @alternate-active-background;
text-color: @alternate-active-foreground;
}
scrollbar {
width: 4px;
border: 0;
handle-color: @normal-foreground;
handle-width: 8px;
padding: 0;
}
mode-switcher {
border: 2px 0px 0px;
border-color: @separatorcolor;
}
button {
spacing: 0;
text-color: @normal-foreground;
}
button.selected {
background-color: @selected-normal-background;
text-color: @selected-normal-foreground;
}
inputbar {
spacing: 0;
text-color: @normal-foreground;
padding: 1px;
}
case-indicator {
spacing: 0;
text-color: @normal-foreground;
}
entry {
spacing: 0;
text-color: @normal-foreground;
}
prompt {
spacing: 0;
text-color: @normal-foreground;
}
inputbar {
children: [ prompt,textbox-prompt-colon,entry,case-indicator ];
}
textbox-prompt-colon {
expand: false;
str: ":";
margin: 0px 0.3em 0em 0em;
text-color: @normal-foreground;
}

View File

@@ -0,0 +1,137 @@
/*******************************************************
* ROFI configs i3 keyhint-menu for EndeavourOS
* Maintainer: joekamprad <joekamprad@endeavouros.com>
*******************************************************/
configuration {
font: "Noto Sans Regular 10";
show-icons: false;
icon-theme: "Qogir";
display-drun: "KeyHint";
drun-display-format: "{name}";
scroll-method: 0;
disable-history: false;
fullscreen: false;
hide-scrollbar: true;
sidebar-mode: false;
}
@import "~/.config/rofi/arc_dark_transparent_colors.rasi"
window {
background-color: @background;
border: 0;
padding: 30;
}
listview {
lines: 10;
columns: 1;
}
mainbox {
border: 0;
padding: 0;
}
message {
border: 2px 0px 0px;
border-color: @separatorcolor;
padding: 1px;
}
textbox {
text-color: @foreground;
}
listview {
fixed-height: 0;
border: 8px 0px 0px;
border-color: @separatorcolor;
spacing: 8px;
scrollbar: false;
padding: 2px 0px 0px;
}
element {
border: 0;
padding: 1px;
}
element-text {
background-color: inherit;
text-color: inherit;
}
element.normal.normal {
background-color: @normal-background;
text-color: @normal-foreground;
}
element.normal.urgent {
background-color: @urgent-background;
text-color: @urgent-foreground;
}
element.normal.active {
background-color: @active-background;
text-color: @active-foreground;
}
element.selected.normal {
background-color: @selected-normal-background;
text-color: @selected-normal-foreground;
}
element.selected.urgent {
background-color: @selected-urgent-background;
text-color: @selected-urgent-foreground;
}
element.selected.active {
background-color: @selected-active-background;
text-color: @selected-active-foreground;
}
element.alternate.normal {
background-color: @alternate-normal-background;
text-color: @alternate-normal-foreground;
}
element.alternate.urgent {
background-color: @alternate-urgent-background;
text-color: @alternate-urgent-foreground;
}
element.alternate.active {
background-color: @alternate-active-background;
text-color: @alternate-active-foreground;
}
scrollbar {
width: 4px;
border: 0;
handle-color: @normal-foreground;
handle-width: 8px;
padding: 0;
}
mode-switcher {
border: 2px 0px 0px;
border-color: @separatorcolor;
}
button {
spacing: 0;
text-color: @normal-foreground;
}
button.selected {
background-color: @selected-normal-background;
text-color: @selected-normal-foreground;
}
inputbar {
spacing: 0;
text-color: @normal-foreground;
padding: 1px;
}
case-indicator {
spacing: 0;
text-color: @normal-foreground;
}
entry {
spacing: 0;
text-color: @normal-foreground;
}
prompt {
spacing: 0;
text-color: @normal-foreground;
}
inputbar {
children: [ prompt,textbox-prompt-colon,entry,case-indicator ];
}
textbox-prompt-colon {
expand: false;
str: ":";
margin: 0px 0.3em 0em 0em;
text-color: @normal-foreground;
}

18
home/rofi/default.nix Normal file
View File

@@ -0,0 +1,18 @@
{
pkgs,
config,
...
}: {
# 基于 https://github.com/endeavouros-team/endeavouros-i3wm-setup
# 直接从当前文件夹中读取配置文件作为配置内容
home.file.".config/rofi" = {
source = ./configs;
# copy the scripts directory recursively
recursive = true;
};
# 直接以 text 的方式,在 nix 配置文件中硬编码文件内容
# home.file.".xxx".text = ''
# xxx
# '';
}

18
home/shell/common.nix Normal file
View File

@@ -0,0 +1,18 @@
{
pkgs,
...
}:
# nix tooling
{
home.packages = with pkgs; [
alejandra
deadnix
statix
];
programs.direnv = {
enable = true;
nix-direnv.enable = true;
enableZshIntegration = true;
};
}

35
home/shell/default.nix Normal file
View File

@@ -0,0 +1,35 @@
{config, ...}: let
d = config.xdg.dataHome;
c = config.xdg.configHome;
cache = config.xdg.cacheHome;
in {
imports = [
./nushell
./common.nix
./starship.nix
./terminals.nix
];
# add environment variables
home.sessionVariables = {
# clean up ~
LESSHISTFILE = cache + "/less/history";
LESSKEY = c + "/less/lesskey";
WINEPREFIX = d + "/wine";
XAUTHORITY = "$XDG_RUNTIME_DIR/Xauthority";
# set default applications
EDITOR = "vim";
BROWSER = "firefox";
TERMINAL = "alacritty";
# enable scrolling in git diff
DELTA_PAGER = "less -R";
MANPAGER = "sh -c 'col -bx | bat -l man -p'";
};
home.shellAliases = {
k = "kubectl";
};
}

View File

View File

@@ -0,0 +1,7 @@
{
programs.nushell = {
enable = true;
configFile.source = ./config.nu;
envFile.source = ./env.nu;
};
}

36
home/shell/nushell/env.nu Normal file
View File

@@ -0,0 +1,36 @@
# 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

13
home/shell/starship.nix Normal file
View File

@@ -0,0 +1,13 @@
{config, ...}: {
home.sessionVariables.STARSHIP_CACHE = "${config.xdg.cacheHome}/starship";
programs.starship = {
enable = true;
settings = {
character = {
success_symbol = "[](bold green)";
error_symbol = "[](bold red)";
};
};
};
}

29
home/shell/terminals.nix Normal file
View File

@@ -0,0 +1,29 @@
{ pkgs, ... }:
# terminals
let
font = "JetBrainsMono Nerd Font";
in
{
programs.alacritty = {
enable = true;
settings = {
window.opacity = 0.95;
window.dynamic_padding = true;
window.padding = {
x = 5;
y = 5;
};
scrolling.history = 10000;
font = {
normal.family = font;
bold.family = font;
italic.family = font;
size = 11;
};
};
};
}

10
hosts/default.nix Normal file
View File

@@ -0,0 +1,10 @@
{
...
}: {
imports =
[
./nixos-test
../modules/system.nix
../modules/i3.nix
];
}

View File

@@ -0,0 +1,49 @@
# 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
];
# Bootloader.
boot.loader = {
# efi = {
# canTouchEfiVariables = true;
# efiSysMountPoint = "/boot/efi"; # ← use the same mount point here.
# };
grub = {
enable = true;
device = "/dev/sda"; # "nodev"
efiSupport = false;
useOSProber = true;
#efiInstallAsRemovable = true; # in case canTouchEfiVariables doesn't work for your system
};
};
networking.hostName = "nixos-test"; # 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";
# 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 = "22.11"; # Did you read the comment?
}

View File

@@ -0,0 +1,32 @@
# 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 + "/profiles/qemu-guest.nix")
];
boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "virtio_pci" "virtio_scsi" "sd_mod" "sr_mod" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];
fileSystems."/" =
{ device = "/dev/disk/by-uuid/b779eb19-e43d-4f07-a91f-eb08bd8e1202";
fsType = "ext4";
};
swapDevices = [ ];
# 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.ens18.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

55
modules/i3.nix Normal file
View File

@@ -0,0 +1,55 @@
{pkgs, ...}:
{
# i3 related options
environment.pathsToLink = [ "/libexec" ]; # links /libexec from derivations to /run/current-system/sw
services.xserver = {
enable = true;
desktopManager = {
xterm.enable = false;
};
displayManager = {
defaultSession = "none+i3";
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
];
};
# Configure keymap in X11
layout = "us";
xkbVariant = "";
};
# thunar file manager(part of xfce) related options
programs.thunar.plugins = with pkgs.xfce; [
thunar-archive-plugin
thunar-volman
];
services.gvfs.enable = true; # Mount, trash, and other functionalities
services.tumbler.enable = true; # Thumbnail support for images
}

130
modules/system.nix Normal file
View File

@@ -0,0 +1,130 @@
{ config, pkgs, ... }:
{
# Set your time zone.
time.timeZone = "Asia/Shanghai";
# Select internationalisation properties.
i18n.defaultLocale = "en_US.UTF-8";
i18n.extraLocaleSettings = {
LC_ADDRESS = "zh_CN.UTF-8";
LC_IDENTIFICATION = "zh_CN.UTF-8";
LC_MEASUREMENT = "zh_CN.UTF-8";
LC_MONETARY = "zh_CN.UTF-8";
LC_NAME = "zh_CN.UTF-8";
LC_NUMERIC = "zh_CN.UTF-8";
LC_PAPER = "zh_CN.UTF-8";
LC_TELEPHONE = "zh_CN.UTF-8";
LC_TIME = "zh_CN.UTF-8";
};
# Enable CUPS to print documents.
services.printing.enable = true;
fonts = {
fonts = with pkgs; [
# icon fonts
material-design-icons
# normal fonts
noto-fonts
noto-fonts-cjk
noto-fonts-emoji
# nerdfonts
(nerdfonts.override { fonts = [ "FiraCode" "JetBrainsMono" ]; })
];
# use fonts specified by user rather than default ones
enableDefaultFonts = 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" ];
};
};
programs.dconf.enable = true;
# networking.firewall.allowedTCPPorts = [ ... ];
# networking.firewall.allowedUDPPorts = [ ... ];
# Or disable the firewall altogether.
networking.firewall.enable = false;
# Enable the OpenSSH daemon.
services.openssh = {
enable = true;
settings = {
X11Forwarding = true;
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; [
vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
wget
curl
git
sysstat
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
];
# Enable sound with pipewire.
sound.enable = true;
hardware.pulseaudio.enable = false;
services.power-profiles-daemon = {
enable = true;
};
security.polkit.enable = true;
services = {
dbus.packages = [ pkgs.gcr ];
geoclue2.enable = true;
pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
# If you want to use JACK applications, uncomment this
jack.enable = true;
# use the example session manager (no others are packaged yet so this is enabled by default,
# no need to redefine it in your config for now)
#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"
];
};
}

BIN
wallpaper.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 KiB