【问题标题】:How to pass nixpkgs.config.allowUnfree to local nixpkgs repository如何将 nixpkgs.config.allowUnfree 传递到本地 nixpkgs 存储库
【发布时间】:2018-04-18 17:54:25
【问题描述】:

我想使用来自local nixpkgs repository 的 hubstaff 包,

let
  # pass config so that packages use correct allowUnfree for example
  nixpkgs-local = import /home/bjorn/projects/nixpkgs { inherit config; };
in

rec {
  config.allowUnfree = true;

  config.packageOverrides = old: {

    # packages from local nixpkgs
    inherit (nixpkgs-local) safeeyes hubstaff;
....

但是它的 unfree 包,所以抛出 unfree 包错误

$ sudo nixos-rebuild dry-build
building the system configuration...
error: Package ‘hubstaff-1.3.1-ff75f26’ in /home/bjorn/projects/nixpkgs/pkgs/applications/misc/hubstaff/default.nix:60 has an unfree license (‘unfree’), refusing to evaluate.

据我所知,我需要通过nixpkgs.config.allowUnfree = true,但上面的import /home/bjorn/projects/nixpkgs { inherit config; }; 不起作用


附言

我遇到的另一个问题是我试图查看我在 config.nixpkgs.allowUnfree here 中传递的值

{ config, pkgs, lib, ... }:

let r = {
  imports = [
    ./hardware-configuration.nix
    ./hardware-configuration-override.nix
    ./hardware-programs.nix
    /home/bjorn/projects/nixpkgs/nixos/modules/services/misc/safeeyes.nix
  ];

  ....
};

in
builtins.seq (lib.debug.showVal config.nixpkgs.allowUnfree) r

但我得到infinite recursion error,也许有人知道如何做到这一点?

【问题讨论】:

    标签: nix nixos


    【解决方案1】:

    回答你的第二个“P.S.”问题,以下是原因和建议。

    发生无限递归是因为模块系统需要评估每个模块的“根”和一些属性,如imports,以便构建代表config 的根的术语。

    通过调用seq,您正在评估config 的属性,此时config 本身仍在被评估。

    从技术上讲,您可以通过将 seq 调用添加到属性而不是围绕整个模块来解决此问题。这样,可以在不评估您的 seq 调用的情况下评估 config

    查看您的配置可能更简单的方法是将其导入nix repl

    nix-repl> c = import <nixpkgs/nixos> { configuration = ./nixos/root/default.nix; /* or the file usually called configuration.nix */ }
    
    nix-repl> c.config.nixpkgs.config.allowUnfree
    true
    

    您可以在迭代时使用:r 命令重新加载所有文件。 Nix 喜欢缓存它们,因为它的实现是面向批处理的。

    【讨论】:

      【解决方案2】:

      Tnx 到 tilpner

      我传递了错误的配置

      即, 这是import /home/bjorn/projects/nixpkgs 期待的配置

      nix-repl> c = import <nixpkgs/nixos> {}
      
      nix-repl> c.config.nixpkgs
      { config = { ... }; overlays = [ ... ]; pkgs = { ... }; system = "x86_64-linux"; }
      

      这就是我所传递的

      nix-repl> c.config
      { _module = { ... }; assertions = [ ... ]; boot = { ... }; config = { ... }; containers = { ... }; dysnomia = { ... }; ec2 = { ... }; environment = { ... }; fileSystems = { ... }; fonts = { ... }; gnu = false; hardware = { ... }; i18n = { ... }; ids = { ... }; jobs = «error: The option `jobs' is used but not defined.»; kde = { ... }; krb5 = { ... }; lib = { ... }; meta = { ... }; nesting = { ... }; networking = { ... }; nix = { ... }; nixpkgs = { ... }; passthru = «error: The option `passthru' is used but not defined.»; power = { ... }; powerManagement = { ... }; programs = { ... }; security = { ... }; services = { ... }; sound = { ... }; swapDevices = [ ... ]; system = {
      

      它是传递给 /etc/nixos/configuration.nix 的那个

      修复:

      { config, pkgs }:
      
      let
        # pass config so that packages use correct allowUnfree for example
        unfreeConfig = config.nixpkgs.config // {
          allowUnfree = true;
        };
        nixpkgs-local = import /home/bjorn/projects/nixpkgs { config = unfreeConfig; };
      in
      

      【讨论】:

        猜你喜欢
        • 2011-05-01
        • 1970-01-01
        • 2023-03-09
        • 1970-01-01
        • 2018-03-11
        • 2011-07-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多