NixOS:使用不同渠道安装非免费软件包

air*_*ris 2 nixos nix

我正在使用默认的 nixos 17.09 频道,并且想要unfree从不稳定频道安装软件包。

在这种情况下,我使用(import <nixos-unstable> {}).vscode 安装 vscode,但收到必须设置的错误...allowUnfree = true; 似乎该设置仅适用于默认通道。如何allowFree = true;在不稳定的频道上也进行设置?

air*_*ris 5

我找到了一个解决方案(https://github.com/NixOS/nixpkgs/issues/25880#issuecomment-322855573)。

它为具有相同配置的不稳定通道创建一个别名。

nixpkgs.config = 
{
    # Allow proprietary packages
    allowUnfree = true;

    # Create an alias for the unstable channel
    packageOverrides = pkgs: 
    {
        unstable = import <nixos-unstable> 
            { 
                # pass the nixpkgs config to the unstable alias
                # to ensure `allowUnfree = true;` is propagated:
                config = config.nixpkgs.config; 
            };
    };
};
Run Code Online (Sandbox Code Playgroud)

然后你就可以使用它unstable.vscode来代替(import <nixos-unstable> {}).vscode.