mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2025-06-21 20:41:25 +02:00
feat: replace Makefile with Justfile
This commit is contained in:
parent
092881ecac
commit
825c3efdbe
@ -1,14 +1,14 @@
|
||||
# Simplifying NixOS-Related Commands
|
||||
|
||||
To simplify NixOS-related commands, I utilize a Makefile, which proves to be very convenient.
|
||||
To simplify NixOS-related commands, I utilize [just](https://github.com/casey/just), which proves to be very convenient.
|
||||
|
||||
Alternatively, you can also use similar tools like [just](https://github.com/casey/just) and [cargo-make](https://github.com/sagiegurari/cargo-make) for this purpose. Here, I will provide my approach as a reference.
|
||||
Alternatively, you can also use similar tools like Makefile or [cargo-make](https://github.com/sagiegurari/cargo-make) for this purpose. Here, I will provide my approach as a reference.
|
||||
|
||||
Below is an example of how my Makefile looks:
|
||||
Below is an example of how my Justfile looks:
|
||||
|
||||
> **NOTE**: The target names in the Makefile should not conflict with any file or directory names in the current directory. Otherwise, the targets will not execute.
|
||||
```justfile
|
||||
# just is a command runner, Justfile is very similar to Makefile, but simpler.
|
||||
|
||||
```makefile
|
||||
############################################################################
|
||||
#
|
||||
# Nix commands related to the local machine
|
||||
@ -36,7 +36,7 @@ gc:
|
||||
|
||||
############################################################################
|
||||
#
|
||||
# Idols: Commands related to my remote distributed building cluster
|
||||
# Idols, Commands related to my remote distributed building cluster
|
||||
#
|
||||
############################################################################
|
||||
|
||||
@ -55,11 +55,18 @@ ruby: add-idols-ssh-key
|
||||
ruby-debug: add-idols-ssh-key
|
||||
nixos-rebuild --flake .#ruby --target-host ruby --build-host ruby switch --use-remote-sudo --show-trace --verbose
|
||||
|
||||
idols: aqua ruby
|
||||
kana: add-idols-ssh-key
|
||||
nixos-rebuild --flake .#kana --target-host kana --build-host kana switch --use-remote-sudo
|
||||
|
||||
idols-debug: aqua-debug ruby-debug
|
||||
kana-debug: add-idols-ssh-key
|
||||
nixos-rebuild --flake .#kana --target-host kana --build-host kana switch --use-remote-sudo --show-trace --verbose
|
||||
|
||||
idols: aqua ruby kana
|
||||
|
||||
idols-debug: aqua-debug ruby-debug kana-debug
|
||||
```
|
||||
|
||||
By Save the above Makefile to the root directory of your Nix flake. Then, I can use `make deploy` to deploy the configuration to my local machine, and `make idols` to deploy the configuration to all my remote servers.
|
||||
|
||||
This approach simplifies the execution of NixOS commands by abstracting them behind target names in the Makefile, providing a more user-friendly and convenient experience.
|
||||
By Save this `Justfile` to the root directory of your Nix flake. Then, I can use `just deploy` to deploy the configuration to my local machine, and `just idols` to deploy the configuration to all my remote servers.
|
||||
|
||||
This approach simplifies the execution of NixOS commands by abstracting them behind target names in the Justfile, providing a more user-friendly and convenient experience.
|
||||
|
@ -1,15 +1,15 @@
|
||||
# 使用 Makefile 简化 NixOS 相关命令
|
||||
|
||||
> 注意: Makefile 的 target 名称不能与当前目录下的文件或者目录重名,否则 target 将不会被执行!
|
||||
# 使用 Justfile 简化 NixOS 相关命令
|
||||
|
||||
在使用 NixOS 的过程中,我们会经常使用 `nixos-rebuild` 命令,经常需要输入一大堆参数,比较繁琐。
|
||||
|
||||
所以我使用 Makefile 来管理我的 flake 配置相关的命令,简化使用。
|
||||
你也可以使用其他类似的工具来干这个活(比如说 [just](https://github.com/casey/just) 跟 [cargo-make](https://github.com/sagiegurari/cargo-make)),这里我仅介绍下我的用法以供参考。
|
||||
我使用了 [just](https://github.com/casey/just) 来管理我的 flake 配置相关的命令,简化使用。
|
||||
你也可以使用其他类似的工具来干这个活(比如说 Makefile 或 [cargo-make](https://github.com/sagiegurari/cargo-make)),这里我仅介绍下我的用法以供参考。
|
||||
|
||||
我的 Makefile 大概内容截取如下:
|
||||
我的 Justfile 大概内容截取如下(最新版本见 [ryan4yin/nix-config/Justfile](https://github.com/ryan4yin/nix-config/blob/main/Justfile)):
|
||||
|
||||
```justfile
|
||||
# just is a command runner, Justfile is very similar to Makefile, but simpler.
|
||||
|
||||
```makefile
|
||||
############################################################################
|
||||
#
|
||||
# Nix commands related to the local machine
|
||||
@ -67,5 +67,5 @@ idols: aqua ruby kana
|
||||
idols-debug: aqua-debug ruby-debug kana-debug
|
||||
```
|
||||
|
||||
将上述 Makefile 放到 NixOS 配置的根目录下,然后我们就可以使用 `make` 命令来执行相关的命令了。
|
||||
比如说我这里 `make deploy` 就是部署 NixOS 配置到本地主机,`make idols` 就是部署到我的远程主机集群。
|
||||
将上述 `Justfile` 文件存放到 NixOS 配置的根目录下,然后我们就可以使用 `just` 命令来执行相关的命令了。
|
||||
比如说我这里 `just deploy` 就是部署 NixOS 配置到本地主机,`just idols` 就是部署到我的远程主机集群。
|
||||
|
Loading…
x
Reference in New Issue
Block a user