aider: Update hostname configuration to use variables from `flake.nix` in `nixos/configuration.nix`.

# Aider chat conversation:

USER: I'm a bit concerned about setting the hostname in `nixos/configuration.nix` , as I want to use the same basic configuration for all of my devices

ASSISTANT: I understand your concern. You can use a variable for the hostname in `nixos/configuration.nix` and pass it in from the `flake.nix` file when defining the `nixosConfigurations`. This way, you can have the same default `nixos/configuration.nix` for every system and just change the hostname for each system in the `flake.nix` file.

Here are the *SEARCH/REPLACE* blocks:

flake.nix
```nix
<<<<<<< SEARCH
athame = nixpkgs.lib.nixosSystem {
  specialArgs = {inherit inputs outputs;};
=======
athame = nixpkgs.lib.nixosSystem {
  specialArgs = {inherit inputs outputs; hostname = "athame";};
>>>>>>> REPLACE
```

flake.nix
```nix
<<<<<<< SEARCH
metatron = nixpkgs.lib.nixosSystem {
  specialArgs = {inherit inputs outputs;};
=======
metatron = nixpkgs.lib.nixosSystem {
  specialArgs = {inherit inputs outputs; hostname = "metatron";};
>>>>>>> REPLACE
```

nixos/configuration.nix
```nix
<<<<<<< SEARCH
networking.hostName = "your-hostname";
=======
networking.hostName = inputs.hostname;
>>>>>>> REPLACE
```

This will replace the hardcoded hostname in `nixos/configuration.nix` with a reference to the hostname defined in the `flake.nix` file.
This commit is contained in:
Alex Davies 2024-04-24 09:53:39 -03:00
parent b96451f536
commit edcc5edac4
2 changed files with 3 additions and 3 deletions

View File

@ -61,7 +61,7 @@
nixosConfigurations = {
#Personal laptop, thinkpad t490
athame = nixpkgs.lib.nixosSystem {
specialArgs = {inherit inputs outputs;};
specialArgs = {inherit inputs outputs; hostname = "athame";};
modules = [
# > Our main nixos configuration file <
./nixos/kde-desktop.nix
@ -70,7 +70,7 @@
};
#Work laptop, dell g15. Nvidia gpu
metatron = nixpkgs.lib.nixosSystem {
specialArgs = {inherit inputs outputs;};
specialArgs = {inherit inputs outputs; hostname = "metatron";};
modules = [
# > Our main nixos configuration file <
./nixos/kde-desktop.nix

View File

@ -74,7 +74,7 @@
# FIXME: Add the rest of your current configuration
# TODO: Set your hostname
networking.hostName = "your-hostname";
networking.hostName = inputs.hostname;
# TODO: This is just an example, be sure to use whatever bootloader you prefer
boot.loader.systemd-boot.enable = true;