Skip to content

Commit

Permalink
refactor: nixos-with-flakes-enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan4yin committed Feb 15, 2024
1 parent 8c923ec commit 635d9b5
Show file tree
Hide file tree
Showing 18 changed files with 679 additions and 330 deletions.
10 changes: 5 additions & 5 deletions docs/best-practices/remote-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ In your system's `flake.nix`, add a new outputs named `colmena`. A simple exampl
};
};
# Host name = "nixos-test"
"nixos-test" = { name, nodes, ... }: {
# Host name = "my-nixos"
"my-nixos" = { name, nodes, ... }: {
# Parameters related to remote deployment
deployment.targetHost = "192.168.5.42"; # Remote host's IP address
deployment.targetUser = "root"; # Remote host's username
Expand Down Expand Up @@ -103,14 +103,14 @@ For more advanced usage, refer to colmena's official documentation at <https://c

Using `nixos-rebuild` for remote deployment has the advantage of being similar to deploying to a local host. It only requires a few additional parameters to specify the remote host's IP address, username, and other details.

For instance, to deploy the configuration defined in the `nixosConfigurations.nixos-test` of your flake to a remote host, use the following command:
For instance, to deploy the configuration defined in the `nixosConfigurations.my-nixos` of your flake to a remote host, use the following command:

```bash
nixos-rebuild switch --flake .#nixos-text \
--target-host root@192.168.4.1 --build-host localhost --verbose
```

The above command will build and deploy the configuration of `nixos-test` to a server with IP `192.168.4.1`. The system build process will occur locally.
The above command will build and deploy the configuration of `my-nixos` to a server with IP `192.168.4.1`. The system build process will occur locally.

If you prefer to build the configuration on the remote host, replace `--build-host localhost` with `--build-host root@192.168.4.1`.

Expand All @@ -133,7 +133,7 @@ Host aquamarine
With this setup, you can use host aliases for deployment:

```bash
nixos-rebuild switch --flake .#nixos-test --target-host root@aquamarine --build-host root@aquamarine --verbose
nixos-rebuild switch --flake .#my-nixos --target-host root@aquamarine --build-host root@aquamarine --verbose
```

This offers a more convenient way to deploy using the defined host aliases.
2 changes: 1 addition & 1 deletion docs/nixos-with-flakes/add-custom-cache-servers.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ sudo nixos-rebuild switch --option substituers "https://nix-community.cachix.org

Choose one of the above three methods for configuration and deployment. After a successful deployment, all subsequent packages will preferentially search for caches from domestic mirror sources.

> If your system hostname is not `nixos-test`, you need to modify the name of `nixosConfigurations` in `flake.nix` or use `--flake /etc/nixos#nixos-test` to specify the configuration name.
> If your system hostname is not `my-nixos`, you need to modify the name of `nixosConfigurations` in `flake.nix` or use `--flake /etc/nixos#my-nixos` to specify the configuration name.
### The `extra-` Prefix for Nix Options Parameters

Expand Down
4 changes: 2 additions & 2 deletions docs/nixos-with-flakes/downgrade-or-upgrade-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Here's an example of how you can add multiple nixpkgs inputs, each using a diffe
...
}: {
nixosConfigurations = {
nixos-test = nixpkgs.lib.nixosSystem rec {
my-nixos = nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux";
# The `specialArgs` parameter passes the
Expand All @@ -51,7 +51,7 @@ Here's an example of how you can add multiple nixpkgs inputs, each using a diffe
};
modules = [
./hosts/nixos-test
./hosts/my-nixos
# Omit other configurations...
];
Expand Down
10 changes: 5 additions & 5 deletions docs/nixos-with-flakes/modularize-the-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ A more complicated example, [ryan4yin/nix-config/i3-kickstarter](https://github.
│ ├── msi-rtx4090 # My main machine's configuration
│ │ ├── default.nix # This is the old configuration.nix, but most of the content has been split out to modules.
│ │ └── hardware-configuration.nix # hardware & disk related configuration, autogenerated by nixos
│ └── nixos-test # my test machine's configuration
│ └── my-nixos # my test machine's configuration
│ ├── default.nix
│ └── hardware-configuration.nix
├── modules # some common NixOS modules that can be reused
Expand Down Expand Up @@ -218,7 +218,7 @@ To test the usage of `lib.mkBefore` and `lib.mkAfter`, let's create a simple Fla
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
outputs = {nixpkgs, ...}: {
nixosConfigurations = {
"nixos-test" = nixpkgs.lib.nixosSystem {
"my-nixos" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
Expand Down Expand Up @@ -262,7 +262,7 @@ The flake above contains the usage of `lib.mkBefore` and `lib.mkAfter` on multil

```bash
# Example 1: multiline string merging
echo $(nix eval .#nixosConfigurations.nixos-test.config.programs.bash.shellInit)
echo $(nix eval .#nixosConfigurations.my-nixos.config.programs.bash.shellInit)
trace: warning: system.stateVersion is not set, defaulting to 23.11. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersio
n.
"echo 'insert before default'
Expand All @@ -279,13 +279,13 @@ echo 'insert after default'
"
# example 2: single-line string merging
echo $(nix eval .#nixosConfigurations.nixos-test.config.programs.zsh.shellInit)
echo $(nix eval .#nixosConfigurations.my-nixos.config.programs.zsh.shellInit)
"echo 'insert before default';
echo 'this is default';
echo 'insert after default';"
# Example 3: list merging
› nix eval .#nixosConfigurations.nixos-test.config.nix.settings.substituters
› nix eval .#nixosConfigurations.my-nixos.config.nix.settings.substituters
[ "https://nix-community.cachix.org" "https://nix-community.cachix.org" "https://cache.nixos.org/" "https://ryan4yin.cachix.org" ]
```
Expand Down

0 comments on commit 635d9b5

Please sign in to comment.