Fetch data online with nix builtins

Hi, this is my first post, Nix OS is really amazing!
I’m wondering if Nix has builtin functions to fetch some data online (Like curl!), I want to change the host file with networking.extraHosts, but the change is really, really long. Updating the hosts file everytime there’s an update is kind of infuriating.
Is there any way to achieve something like :

networking.extraHosts = builtins.fetchSomeData {
    url = "https://raw.githubusercontent.com/someuser/somerepo/master/hosts"

Yes, there is builtins.fetchurl, which you can either use in “impure” mode by just providing a string representing an URL or in pure mode which takes an attribute set instead which requires url and sha256 attributes.

Though as you are downloading from github, you could also use pkgs.fetchFromGitHub, though it comes with a “pure” mode only and requires you to specify owner, repo, revision (commits SHA1, a tag or a branch even) and sha256 (which is the sha over the downloaded content of the commit, therefore using a branch for rev is inconvinient).

1 Like

Thank you! It works!