[Nix-dev] How to create dirs needed by a module before it runs?

Wout Mertens wout.mertens at gmail.com
Fri Jan 23 20:03:27 CET 2015


What do you mean with "only get installed at the end"?

Also, networking.hostName should work, the whole config gets evaluated "at
once". There's no "running" in Nix, only side-effects of evaluation.

Wout.

On Fri Jan 23 2015 at 7:45:38 PM Jeff Johnson <jefdaj at gmail.com> wrote:

> Hi all! I'm trying to set up tarsnap on nixos. This is my tarsnap.nix so
> far:
>
>     config:
>
>     let
>       keySrc   = ../rawpriv/tarsnap;
>       cacheDir = "/var/cache/tarsnap";
>
>       rcSrc = builtins.toFile "tarsnaprc" ''
>         aggressive-networking # TODO is this a good idea?
>         humanize-numbers
>       '';
>
>       script = homeDir:
>         let
>           keyDst = "${homeDir}/tarsnap.key";
>           rcDst  = "${homeDir}/.tarsnaprc";
>         in ''
>           echo "installing ${keyDst}"  ; install -m400
> ${keySrc}/`hostname`.key ${keyDst}
>           echo "installing ${rcDst}"   ; ln -fs ${rcSrc} ${rcDst}
>           echo "installing ${cacheDir}"; mkdir -p ${cacheDir}
>         '';
>
>     in {
>       system.activationScripts = { tarsnap = script "/root"; };
>       services.tarsnap = {
>         inherit config;
>         enable   = true;
>         keyfile  = keyDst;
>         cachedir = cacheDir;
>       };
>     }
>
> It works except that the keyfile and cachedir only get installed at
> the end, so nix complains that they don't exist unless I create them
> manually first. Is there a way to make the script run earlier? And
> another possibly-related question: is there a way to find out the
> hostname? I can't just do `networking.hostName` because that's set in
> the top-level config after this module runs. Do I just pass it as an
> argument? Thanks
> Jeff
> _______________________________________________
> 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/20150123/a42034f1/attachment.html 


More information about the nix-dev mailing list