mirror of
https://github.com/ryan4yin/nixos-and-flakes-book
synced 2024-11-23 12:43:08 +00:00
feat: minor updates
This commit is contained in:
parent
68ec34e9fe
commit
31015cfb43
14 changed files with 28 additions and 37 deletions
|
@ -19,8 +19,8 @@ Once you are comfortable with Flakes, you can explore more advanced techniques a
|
||||||
|
|
||||||
There are many other valuable community projects worth exploring. Here are a few examples:
|
There are many other valuable community projects worth exploring. Here are a few examples:
|
||||||
|
|
||||||
- [nixpak](https://github.com/nixpak/nixpak)
|
- [nixpak](https://github.com/nixpak/nixpak): A tool to sandbox all sorts of Nix-packaged applications, including graphical ones.
|
||||||
- [nix-output-monitor](https://github.com/maralorn/nix-output-monitor)
|
- [nix-output-monitor](https://github.com/maralorn/nix-output-monitor): Beautifully displays the build progress of Nix packages, with additional information such as build time and build log.
|
||||||
- [agenix](https://github.com/ryantm/agenix): A tool for secrets management.
|
- [agenix](https://github.com/ryantm/agenix): A tool for secrets management.
|
||||||
- [colmena](https://github.com/zhaofengli/colmena): Tools for NixOS deployment.
|
- [colmena](https://github.com/zhaofengli/colmena): Tools for NixOS deployment.
|
||||||
- [nixos-generators](https://github.com/nix-community/nixos-generators): A tool to generate ISO/qcow2/... from NixOS configurations.
|
- [nixos-generators](https://github.com/nix-community/nixos-generators): A tool to generate ISO/qcow2/... from NixOS configurations.
|
||||||
|
@ -28,3 +28,5 @@ There are many other valuable community projects worth exploring. Here are a few
|
||||||
- [impermanence](https://github.com/nix-community/impermanence): Helps make NixOS stateless and improves system reproducibility.
|
- [impermanence](https://github.com/nix-community/impermanence): Helps make NixOS stateless and improves system reproducibility.
|
||||||
|
|
||||||
These projects offer additional functionality and tools that can enhance your NixOS experience.
|
These projects offer additional functionality and tools that can enhance your NixOS experience.
|
||||||
|
|
||||||
|
For more information, see the [awesome-nix](https://github.com/nix-community/).
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
Since NixOS does not strictly adhere to the Filesystem Hierarchy Standard (FHS), binaries downloaded from the internet may not work directly on NixOS. However, there are various methods available to make them function properly.
|
Since NixOS does not strictly adhere to the Filesystem Hierarchy Standard (FHS), binaries downloaded from the internet may not work directly on NixOS. However, there are various methods available to make them function properly.
|
||||||
|
|
||||||
For a comprehensive guide that presents ten different approaches to run downloaded binaries on NixOS, I recommend reading the article [Different methods to run a non-nixos executable on Nixos](https://unix.stackexchange.com/questions/522822/different-methods-to-run-a-non-nixos-executable-on-nixos).
|
For a comprehensive guide that presents ten different approaches to run downloaded binaries on NixOS, I recommend reading the article [Different methods to run a non-nixos executable on Nixos](https://unix.stackexchange.com/questions/522822/different-methods-to-run-a-non-nixos-executable-on-nixos) and take a look at [nix-alien](https://github.com/thiagokokada/nix-alien).
|
||||||
|
|
||||||
Among these methods, I personally prefer creating an FHS environment to run the binary, as it proves to be both convenient and easy to use. To set up such an environment, you can add the following code to one of your Nix modules:
|
Among these methods, I personally prefer creating an FHS environment to run the binary, as it proves to be both convenient and easy to use. To set up such an environment, you can add the following code to one of your Nix modules:
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
# Simplifying NixOS-Related Commands
|
# Simplifying NixOS-Related Commands
|
||||||
|
|
||||||
To simplify NixOS-related commands, I utilize a Makefile, 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.
|
To simplify NixOS-related commands, I utilize a Makefile, 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.
|
||||||
|
|
||||||
Below is an example of how my Makefile looks:
|
Below is an example of how my Makefile 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.
|
||||||
|
|
||||||
```makefile
|
```makefile
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
#
|
#
|
||||||
# Nix commands related to the local machine
|
# Nix commands related to the local machine
|
||||||
|
@ -57,17 +55,11 @@ ruby: add-idols-ssh-key
|
||||||
ruby-debug: 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
|
nixos-rebuild --flake .#ruby --target-host ruby --build-host ruby switch --use-remote-sudo --show-trace --verbose
|
||||||
|
|
||||||
kana: add-idols-ssh-key
|
idols: aqua ruby
|
||||||
nixos-rebuild --flake .#kana --target-host kana --build-host kana switch --use-remote-sudo
|
|
||||||
|
|
||||||
kana-debug: add-idols-ssh-key
|
idols-debug: aqua-debug ruby-debug
|
||||||
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
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Save the above Makefile to the root directory of your Nix flake. Then, you can use `make deploy` to deploy the configuration to your local machine and `make aqua` to deploy the configuration to all your remote servers.
|
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.
|
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.
|
|
@ -78,9 +78,7 @@ Currently, there is no official documentation for distributed building. However,
|
||||||
];
|
];
|
||||||
# Optional: Useful when the builder has a faster internet connection than yours.
|
# Optional: Useful when the builder has a faster internet connection than yours.
|
||||||
nix.extraOptions = ''
|
nix.extraOptions = ''
|
||||||
builders-use-sub
|
builders-use-substitutes = true
|
||||||
|
|
||||||
stitutes = true
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Define the host aliases for remote builders.
|
# Define the host aliases for remote builders.
|
||||||
|
|
|
@ -261,7 +261,7 @@ hello: command not found
|
||||||
Hello, world!
|
Hello, world!
|
||||||
```
|
```
|
||||||
|
|
||||||
`nix run` is used to create an environment containing the specified installable and run the installable in it:
|
`nix run` is used to create an environment containing the specified installable and run the installable in it(without install it to the system):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# hello not exists
|
# hello not exists
|
||||||
|
@ -277,9 +277,9 @@ Because `nix run` will directly run the Nix package as an installable, the Nix p
|
||||||
|
|
||||||
According to the description of `nix run --help`, `nix run` will execute `<out>/bin/<name>`, where `<out>` is the root directory of a Derivation, and `<name>` is selected in the following order:
|
According to the description of `nix run --help`, `nix run` will execute `<out>/bin/<name>`, where `<out>` is the root directory of a Derivation, and `<name>` is selected in the following order:
|
||||||
|
|
||||||
- The meta.mainProgram attribute of the derivation.
|
- The `meta.mainProgram` attribute of the derivation.
|
||||||
- The pname attribute of the derivation.
|
- The `pname` attribute of the derivation.
|
||||||
- The name part of the value of the name attribute of the derivation.
|
- The `name` part of the value of the name attribute of the derivation.
|
||||||
|
|
||||||
For instance, if name is set to `hello-1.10`, nix run will run $out/bin/hello.
|
For instance, if name is set to `hello-1.10`, nix run will run $out/bin/hello.
|
||||||
|
|
||||||
|
|
|
@ -112,4 +112,5 @@ To solve this problem, I add a `fhs` environment to install the `ncurses` packag
|
||||||
|
|
||||||
## References
|
## References
|
||||||
|
|
||||||
|
- [Linux kernel - NixOS Wiki](https://nixos.wiki/wiki/Linux_kernel)
|
||||||
- https://github.com/jordanisaacs/kernel-module-flake
|
- https://github.com/jordanisaacs/kernel-module-flake
|
||||||
|
|
|
@ -227,9 +227,7 @@ To customize the cache source, we must add the related configuration in `flake.n
|
||||||
"https://cache.nixos.org/"
|
"https://cache.nixos.org/"
|
||||||
];
|
];
|
||||||
|
|
||||||
extra-sub
|
extra-substituters = [
|
||||||
|
|
||||||
stituters = [
|
|
||||||
# Nix community's cache server
|
# Nix community's cache server
|
||||||
"https://nix-community.cachix.org"
|
"https://nix-community.cachix.org"
|
||||||
];
|
];
|
||||||
|
|
|
@ -84,7 +84,7 @@ According to the official [Home Manager Manual](https://nix-community.github.io/
|
||||||
|
|
||||||
# nix related
|
# nix related
|
||||||
#
|
#
|
||||||
# it provides the command `nom` works just like `nix
|
# it provides the command `nom` works just like `nix`
|
||||||
# with more details log output
|
# with more details log output
|
||||||
nix-output-monitor
|
nix-output-monitor
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,8 @@ The `inputs` in `flake.nix` is an attribute set, used to specify the dependencie
|
||||||
|
|
||||||
# To use a subdirectory of a repo, pass `dir=xxx`
|
# To use a subdirectory of a repo, pass `dir=xxx`
|
||||||
nixpkgs.url = "github:foo/bar?dir=shu";
|
nixpkgs.url = "github:foo/bar?dir=shu";
|
||||||
}
|
};
|
||||||
|
|
||||||
|
outputs = { self, ... }@inputs: { ... };
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -62,6 +62,4 @@ Here's an example excerpt from the NixOS Wiki that demonstrates the structure of
|
||||||
templates.default = { path = "<store-path>"; description = ""; };
|
templates.default = { path = "<store-path>"; description = ""; };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -32,7 +32,6 @@ nix build "nixpkgs#bat"
|
||||||
# build a local flake is the same as nix develop, skip it
|
# build a local flake is the same as nix develop, skip it
|
||||||
```
|
```
|
||||||
|
|
||||||
[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.
|
We will introduce more details about `nix develop`, `nix shell` and `nix run` in the next chapter.
|
||||||
|
|
||||||
[New Nix Commands]: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html
|
[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
|
|
||||||
|
|
|
@ -265,7 +265,7 @@ hello: command not found
|
||||||
Hello, world!
|
Hello, world!
|
||||||
```
|
```
|
||||||
|
|
||||||
`nix run` 则是创建一个含有指定 Nix 包的环境,并在该环境中直接运行该 Nix 包:
|
`nix run` 则是创建一个含有指定 Nix 包的环境,并在该环境中直接运行该 Nix 包(临时运行该程序,不将它安装到系统环境中):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# hello 不存在
|
# hello 不存在
|
||||||
|
|
|
@ -113,4 +113,5 @@
|
||||||
|
|
||||||
## References
|
## References
|
||||||
|
|
||||||
|
- [Linux kernel - NixOS Wiki](https://nixos.wiki/wiki/Linux_kernel)
|
||||||
- https://github.com/jordanisaacs/kernel-module-flake
|
- https://github.com/jordanisaacs/kernel-module-flake
|
||||||
|
|
|
@ -84,7 +84,7 @@
|
||||||
|
|
||||||
# nix related
|
# nix related
|
||||||
#
|
#
|
||||||
# it provides the command `nom` works just like `nix
|
# it provides the command `nom` works just like `nix`
|
||||||
# with more details log output
|
# with more details log output
|
||||||
nix-output-monitor
|
nix-output-monitor
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue