How do we refer to etc package from NixOS configuration?

前提是你 提交于 2019-12-11 07:13:11

问题


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 

回答1:


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}
        '';
    };
    



回答2:


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



回答3:


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}


来源:https://stackoverflow.com/questions/41007258/how-do-we-refer-to-etc-package-from-nixos-configuration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!