问题
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:
- Make the value of the connect directive the string literal
connect /etc/ppp/peers/huawei
or make the
etc.huawei
attribute set a recursive one so that the attributes can refer to each other then doenvironment.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