Installing a Specific Version of Consul on NixOS
If you're looking to install a newer version of Consul on NixOS than the one provided by your current version, you can achieve this in a declarative manner. In this example, we will upgrade from the default version 0.5.2 to 0.7.0 using the unstable Nix package repository.
Step-by-Step Guide
Modify Your Configuration: Start by editing your
/etc/nixos/configuration.nixfile to override the default Consul package. You can use the attributes from the unstable version as a reference. Here’s how you can set it up:nixpkgs.config.packageOverrides = pkgs: rec { consul = pkgs.lib.overrideDerivation pkgs.consul (attrs: rec { version = "0.7.0"; name = "consul-${version}"; rev = "v${version}"; goPackagePath = "github.com/hashicorp/consul"; src = pkgs.fetchFromGitHub { owner = "hashicorp"; repo = "consul"; inherit rev; sha256 = "04h5y5vixjh9np9lsrk02ypbqwcq855h7l1jlnl1vmfq3sfqjds7"; }; # Maintain backward compatibility with consul.ui passthru.ui = pkgs.consul-ui; }); }; environment.systemPackages = with pkgs; [ vim which telnet consul-ui consul-alerts consul-template consul ];Rebuild Your NixOS Configuration: After saving your changes, run the following command to apply the new configuration:
nixos-rebuild switchTroubleshooting: If you encounter an error like this:
error: cannot coerce a set to a string, at /etc/nixos/configuration.nix:19:7This typically indicates a type mismatch in your configuration. In this case, check the line where you define
nameto ensure it is correctly formatted.
Conclusion
This method allows you to declaratively manage your NixOS packages while still using the stable release. If you have any further questions or need assistance, feel free to reach out to the community for support.