Nixos

如何在 Nix 表達式中引用另一個使用者的屬性?

  • November 27, 2019

我想將 root 設置為另一個使用者的 GID 和 UID startGidstartUid如果不對它們進行硬編碼,我怎麼能做到這一點**?**我嘗試了以下幾種變體:

 users.users = {
   root = {
     subGidRanges = [
       {
         count = 1;
         startGid = users.users.username.group;
       }
     ];
     subUidRanges = [
       {
         count = 1;
         startUid = config.ids.uids.username;
       }
     ];
   };
   username = {
     isNormalUser = true;
   };
 };

這似乎有效:

 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’ 不是“有符號整數”類型。

引用自:https://unix.stackexchange.com/questions/554327