[Nix-dev] Nix as a dotfiles manager

Nicolas Pierron nicolas.b.pierron at gmail.com
Sun Nov 30 23:50:43 CET 2014


Hi,

On Sun, Nov 30, 2014 at 9:29 PM, Arseniy Seroka <ars.seroka at gmail.com> wrote:
> Hello!
> I want to do smth like
> `if networking.name = "foo"
>     then writeFile "/home/user/.dorfile"
>     else if networking.name = "bar" then ...`.

What do you mean by networking.name, are you referring to the NixOS option?

> But it turnes out that I have no idea how to do it.
> So the questions are: is it a good idea to use nix as a dotfiles manager?

I do not yet know.  I know I have been doing so without Nix for a
while, and as this was a requested feature, I started making NixUP [1]
(see the corresponding pull request)

> And what is a best way to do it?

If you are under NixOS, then you should use the activation script to
copy it to the home directory of the user.  Nix is deliberately not
capable of writing out-side the Nix store, but we can create & execute
scripts which are sym-linking the files of the Nix store.

> I thought smth like: now we are making pkgs and making symlinks to their
> executable to ls `~/.nix-profile/bin/`.
> Maybe there is a way for some derivation set the "output path" as a `~/` and
> do smth like (write it in a ~/.nixpkgs/config.nix):

No, the ~/ is replaced while building the derivations, such as we do
not pollute user environment, and such that builds can be reproduced
when multiple users are requesting the same derivation.

> `configs = buildConfigEnv "~/" [
>     { name = ".zshrc"; contents = ''#zshrc config''
>   }
> ]`
> If it is possible, please give me some hints or smth and I will try to
> implement it (if it is a good idea).

The cleanest approach is what is done in NixOS for environment.etc,
and identically for user.resourceFiles in NixUP.

> This way, IMO, we would provide a good mechanism for a dotfiles managing at
> several machines.


[1] https://github.com/NixOS/nixpkgs/pull/4594

-- 
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron - http://nbp.name/


More information about the nix-dev mailing list