![如何在Nix表达式中引用其他用户的属性?](https://linux22.com/image/164636/%E5%A6%82%E4%BD%95%E5%9C%A8Nix%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%B8%AD%E5%BC%95%E7%94%A8%E5%85%B6%E4%BB%96%E7%94%A8%E6%88%B7%E7%9A%84%E5%B1%9E%E6%80%A7%EF%BC%9F.png)
我想将 root 的startGid
和设置startUid
为另一个用户的 GID 和 UID。我怎样才能做到这一点无需对它们进行硬编码?我尝试了以下几种变体:
users.users = {
root = {
subGidRanges = [
{
count = 1;
startGid = users.users.username.group;
}
];
subUidRanges = [
{
count = 1;
startUid = config.ids.uids.username;
}
];
};
username = {
isNormalUser = true;
};
};
答案1
这似乎有效:
users.users = {
root = {
subGidRanges = [
{
count = 1;
startGid = config.ids.gids."${config.users.users.username.group}";
}
];
subUidRanges = [
{
count = 1;
startUid = config.users.users.username.uid;
}
];
};
username = {
isNormalUser = true;
uid = 1000;
};
};
奇怪的是,config.users.users.username.group
即使我没有明确设置它,似乎也解决得很好,但我仍然必须设置config.users.users.username.uid
来解决这个问题:
错误:选项值
users.users.root.subUidRanges.[definition 2-entry 1].startUid' in
/etc/nixos/common.nix' 不是“有符号整数”类型。