如何忽略导入中丢失的文件?

问题描述 投票:0回答:1

我的 nix 配置中有这个:

imports = [
    # Include the results of the hardware scan.
    ./hardware-configuration.nix
    /home/dev/user.nix
];

当我现在执行 nixos-install 时,它告诉我 user.nix 不存在(这是真的,因为文件是稍后提供的)。

有没有办法仅在该文件存在时导入该文件或忽略该错误?

nix
1个回答
0
投票

您可以使用

?
运算符。

Nix
imports = [
    # Include the results of the hardware scan.
    ./hardware-configuration.nix
    /home/dev/user.nix ? {}
];
© www.soinside.com 2019 - 2024. All rights reserved.