[Nix-dev] Nix as a dotfiles manager

Roger Qiu roger.qiu at polycademy.com
Mon Dec 1 11:52:10 CET 2014


What if Nix could have a lens functionality? Check out http://augeas.net/

Then you could use lenses to manipulate the dot files or any config file
from Nix.
On 01/12/2014 9:28 PM, "Sergey Mironov" <grrwlf at gmail.com> wrote:

> Hi. I've adopted the following compromise solution:
> 1) Add the file include/templatecfg.nix with the following contents
> { config, pkgs, ... } :
>
> {
>   environment.etc."template_XResources".source = ../cfg/Xresources;
>   environment.etc."template_vimrc".source = ../cfg/vimrc;
>   environment.etc."template_ssh_config".source = ../cfg/ssh_config;
>
>   /* note, it should be possible to define inplace config here like
> following:
>     environment.etc."template_ssh_config".source = textFile "dotbla" ''
>       [dotbla config contents]
>     '';
>   */
> }
>
> 2) put template configs mentioned there in the ../cfg folder
>
> 3) For every machine, add
>
>   require = [
>     ...
>     ./include/templatecfg.nix
>     ...];
>
> Now, every time I want to update my $HOME/.dotfiles I copy them from
> /etc/template_* files. From the other side, sometimes I want to commit
> my changed .dotfiles back into Nix repository. In this case I copy
> them from $HOME to the $HOME/proj/mynixcfg/..../cfg/
>
> Here is the whole thing: https://github.com/grwlf/nixcfg/tree/master/src
>
> Regards,
> Sergey
>
> 2014-12-01 2:50 GMT+04:00 Nicolas Pierron <nicolas.b.pierron at gmail.com>:
> > 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/
> > _______________________________________________
> > nix-dev mailing list
> > nix-dev at lists.science.uu.nl
> > http://lists.science.uu.nl/mailman/listinfo/nix-dev
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uu.nl/pipermail/nix-dev/attachments/20141201/1900ea4f/attachment.html 


More information about the nix-dev mailing list