1

I want to get a path, which leads to nixos /etc location (any one of /run/current-system/etc or /nix/store/hashhere-etc-1.0). I use this path to configure pppd connect script, some kind of the following,

  environment.etc."huawei" =
    { text = ''
        /dev/ttyUSB0
        38400
        lock
        crtscts
        nodetach
        noipdefault
        # Below here what I've struggled
        connect ${pkgs.etc}/${environment.etc."huawei-script".target}
      '';
      mode = "0777";
      target = "ppp/peers/huawei"; };

I have tried to write ${pkgs.etc} or ${system.build.etc} or even ${environment.etc} resulting errors.

The directory structure is actually relative, but I think it's safer to use absolute path.

    /nix/store/...etc.../ppp/peers
    |- huawei
    |- huawei.d
       |- huawei.sh
       |- huawei.chat 
Abdillah
  • 982
  • 11
  • 28
  • 1
    btw, you don't have to specify `target`. You can embed it into name, like this: `environment.etc."ppp/peers/huawei".text = "...";`. Implementation - https://github.com/NixOS/nixpkgs/blob/release-16.09/nixos/modules/system/etc/etc.nix#L114 – danbst Dec 12 '16 at 09:30

3 Answers3

3

You can refer to path to file in /nix/store/...etc... like this:

{ config, pkgs, lib, ... }:

{
  environment.etc."test".text = "helo";
  environment.etc."test2".text = "${config.environment.etc."test".source.outPath}";
}

Now I have in /etc/test2:

$ cat /etc/test2
/nix/store/1igc2rf011jmrr3cprsgbdp3hhm5d4l0-etc-test
danbst
  • 3,363
  • 18
  • 38
  • Unfortunately, in my case, it doesn't have source. But thanks! – Abdillah Dec 11 '16 at 04:07
  • have you tried that out? `source` attribute is created implicitly when you set `text` (https://github.com/NixOS/nixpkgs/blob/release-16.09/nixos/modules/system/etc/etc.nix#L115). – danbst Dec 12 '16 at 09:27
  • ah, I've fixed the code example. The culprit was to refernce via `config` attribute – danbst Dec 13 '16 at 20:11
2

If I understand correctly your problem is you simply need to pass the string value of the target attribute to the huawei.text connect directive. As per the description for the target attribute the value is a path relative to /etc so you should be able to either:

  1. Make the value of the connect directive the string literal connect /etc/ppp/peers/huawei or
  2. make the etc.huaweiattribute set a recursive one so that the attributes can refer to each other then do

    environment.etc.huawei = rec {
        target = "ppp/peers/huawei";
        text = ''...
                 # Below here what I've struggled
                 connect ${target}
        '';
    };
    
brocking
  • 821
  • 6
  • 9
  • The main problem is actually where the correct path of `etc` (since in NixOS, `etc` folder is not below the root). How do I get those path to absolutely locate my script (which is in `etc`). – Abdillah Dec 07 '16 at 13:28
  • @Abdillah why do you think `etc` isn't under root? I tried `ls -la /` and `etc` is there. It isn't even a symlink. – danbst Dec 10 '16 at 11:24
  • @danbst Oh no... Yes you're right! It seems I overthink it :( – Abdillah Dec 10 '16 at 13:03
  • Thanks @nickbh , your #1 suggestion is thus correct. – Abdillah Dec 11 '16 at 04:09
0

Sorry, I was overlook a fact where NixOS actually map any files in /nix/store/...etc../ into the /etc itself.

So, to refer to a file, it is better to use /etc directly.

connect /etc/${environment.etc."huawei-script".target}
Abdillah
  • 982
  • 11
  • 28