Skip to content

Commit

Permalink
nixos/nix: add option to preface remote machines with a comment
Browse files Browse the repository at this point in the history
I recently ran into an issue where I wasn't able to use the DNS hostname of a
machine inside the /etc/nix/machines file. Nothing to do with NixOS or Nix
itself, just a weird networking setup I was in. This meant I had to use the
plain IPv4 and IPv6 addresses of those machines in these files.

I still like to have some reference to what these machines are, so I've always
put a comment above the remote machine line with the DNS name of the machine,
and then use the hostName option for the IP address.

This adds the nix.buildMachines.*.comment option. Allows us to do the following.

    {
      nix.buildMachines = [
        {
          protocol = "ssh-ng";
          sshUser = "nixbld";
          hostName = "192.168.0.222";
          comment = "Some very powerful machine in Belgium";
        }
      ];
    }

Which would result in the following /etc/nix/machines entry.

    # Some very powerful machine in Belgium
    ssh-ng://[email protected] - - 1 1 - - -
  • Loading branch information
bryanhonof committed Jan 16, 2025
1 parent 0bda27c commit 9ca8622
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion nixos/modules/config/nix-remote-build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let

buildMachinesText = concatMapStrings (
machine:
(concatStringsSep " " (
((optionalString (machine.comment != null) "# ${machine.comment}\n") + concatStringsSep " " (
[
"${optionalString (machine.protocol != null) "${machine.protocol}://"}${
optionalString (machine.sshUser != null) "${machine.sshUser}@"
Expand Down Expand Up @@ -201,6 +201,15 @@ in
If null, SSH will use its regular known-hosts file when connecting.
'';
};
comment = mkOption {
type = types.nullOr types.str;
default = null;
example = "This is a powerful builder located in Belgium";
description = ''
A comment to describe the builder. Could be useful for noting the full
DNS name of a machine, and using an IP address as hostName.
'';
};
};
}
);
Expand Down

0 comments on commit 9ca8622

Please sign in to comment.