Download config files to home dir?

hi, i am trying nixos, and its a bit rough. i tried chatgpt, but it doesnt work well.

So my question is, how do you download a text file and put it in your $HOME/.config files?

I have set up home manager (i think).

This the relevant part of my configuration.nix

{ config, pkgs, ... }:
let  home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/master.tar.gz";
in 
{
    

  imports = [
    (import "${home-manager}/nixos")
      ./hardware-configuration.nix
  ];
 
  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.polyface = {
    isNormalUser = true;
    description = "polyface";
    extraGroups = [ "networkmanager" "wheel" ];
    packages = with pkgs; [
      kdePackages.kate
    #  thunderbird
    ];
 
  };

  home-manager.users.polyface = { pkgs, ... }: {
       programs.zsh.enable = true;
home = {
    stateVersion = "24.11";
    username = "polyface";
    homeDirectory = "/home/polyface";
    packages = with pkgs; [
     ];
     file.".config/oh-my-posh/catppuccin_mocha.omp.json".source =
      pkgs.callPackage ./external.nix {};

 };
};

and external.nix:

{ stdenv, fetchurl }:

stdenv.mkDerivation {
  name = "catppuccin_mocha_omp_json";
  src = fetchurl {
    url = "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/refs/heads/main/themes/catppuccin_mocha.omp.json";
    sha256 = "1jhhd4l3qklrz0s6ph91nm9b797kif6la9snbvnmdcx1p9vzw35y";
  };

  installPhase = ''
    mkdir -p $out/.config/oh-my-posh
    cp $src $out/.config/oh-my-posh/catppuccin_mocha.omp.json
  '';

  meta = {
    description = "Catppuccin Mocha theme for Oh My Posh";
  };
}

But i get this error every time i wanna rebuild switch:
Running phase: unpackPhase
unpacking source archive /nix/store/650fj7hrjyd2g26h10iln4467a9547yy-catppuccin_mocha.omp.json
do not know how to unpack source archive /nix/store/650fj7hrjyd2g26h10iln4467a9547yy-catppuccin_mocha.omp.json

So how ca i download it and put it in the .config/oh-my-posh?

No need to make a separate package, just use fetchurl directly:

file.".config/oh-my-posh/catppuccin_mocha.omp.json".source = pkgs.fetchurl {
  url = "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/refs/heads/main/themes/catppuccin_mocha.omp.json";
  sha256 = "1jhhd4l3qklrz0s6ph91nm9b797kif6la9snbvnmdcx1p9vzw35y";
};

xdg.configFile might be nicer than home.file though, and home-manager has built-in support for oh-my-posh, which might be better depending on how you structure your zsh config.

1 Like

Ah, hum, also, don’t do that, your home-manager will silently update every 2 hours or so with this config. Add it to your channels instead, follow the docs: Home Manager Manual

I have never used oh-my-posh, but it looks like Home Manager has an option you could use instead of downloading the theme. So you could probably just set something like this:

programs.oh-my-posh = {
  enable = true;
  useTheme = "catppuccin_mocha";
};

Also, for future reference, the error you were getting was because nix stdenv.mkDerivation was expecting src to be some kind of archive file (e.g. .zip, .tar.gz, etc.) rather than a text file.

Edit: Correction, it was stdenv.mkDerivation that was expecting an archive, not nix itself, as pointed out below by @TLATER.

Also, this is a very helpful resource for finding Home Manager options: https://home-manager-options.extranix.com/

Specifically, stdenv.mkDerivation expects the input source to be an archive by default, and will try to extract it as part of the build. nix itself doesn’t really care, it’s the default build script in nixpkgs that’s throwing this error.

You could also set dontUnpack = true to skip the unpack phase if you wanted to do this, but there’s no reason to add another derivation on top if all you want to do is download a single file.

1 Like

i tried to follow this but i kep getting homemanager so this was the only solution i found online

Please don’t, you might as well not be using nix if you do stuff like this. We should really deprecate using the built-in fetchers without hashes.

Can you tell us what went wrong? I’m happy to help, this should not be hard to fix.

yea it works better than downloading the file, thanks