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

Jeff Johnson jefdaj at gmail.com
Fri Jan 23 19:45:28 CET 2015

Hi all! I'm trying to set up tarsnap on nixos. This is my tarsnap.nix so far:


      keySrc   = ../rawpriv/tarsnap;
      cacheDir = "/var/cache/tarsnap";

      rcSrc = builtins.toFile "tarsnaprc" ''
        aggressive-networking # TODO is this a good idea?

      script = homeDir:
          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

More information about the nix-dev mailing list