[Nix-dev] nix modules: Unsetting attrsOf options?

Tomasz Czyż tomasz.czyz at gmail.com
Wed Sep 7 12:25:45 CEST 2016


filterAttrs is going through all of them I think, but try removeAttrs (or
something similar).

I'm not sure, but probably you want to remove those before importing (or
rather before evaluation), right?

so probably you need to do something like

module = import ./my-module;
module` = removeAttrs.....

imports = [ module` ];

but I've not tried this, just my guess.

2016-09-07 11:12 GMT+01:00 Rickard Nilsson <rickard.nilsson at telia.com>:

> On 09/07/2016 11:54 AM, 4levels wrote:
>
>> Hi Rickard,
>>
>> All I can think of currently is that you could create a new config
>> variable using filterAttrs to keep only the information you need.
>> Not sure if this solves your question though as I'm not aware if you can
>> use another variable in your scenario.
>>
>
> Using filterAttrs like this would introduce an infinite recursion, I think:
>
> config = {
>   myattrs = filterAttrs (k: _: k != "a") config.myattrs;
> }
>
> But maybe that wasn't what you had in mind.
>
> For the issue that spurred this question I have now added an "enable"
> option for the attributes, see: https://github.com/NixOS/nixpk
> gs/pull/18391
>
> However, that is not a general solution to this problem, so any further
> hints are welcome.
>
>   / Rickard
>
>
> Kind regards,
>>
>> Erik
>>
>> On Wed, Sep 7, 2016 at 12:35 AM Rickard Nilsson
>> <rickard.nilsson at telia.com <mailto:rickard.nilsson at telia.com>> wrote:
>>
>>     Is it possible to unset an attrsOf option? Say I import a module that
>>     looks like this:
>>
>>     options = {
>>        myattrs = mkOption {
>>          type = types.attrsOf ...
>>          default = {};
>>        };
>>     }
>>
>>     config = {
>>        myattrs = {
>>          a = ...
>>          b = ...
>>        };
>>     };
>>
>>     And then I want to remove the "a" attribute in the importing config:
>>
>>     config = {
>>        myattrs.a = mkForce ...
>>     }
>>
>>     Is that possible in any way?
>>
>>
>>        / Rickard
>>     _______________________________________________
>>     nix-dev mailing list
>>     nix-dev at lists.science.uu.nl <mailto:nix-dev at lists.science.uu.nl>
>>     http://lists.science.uu.nl/mailman/listinfo/nix-dev
>>
>>
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>



-- 
Tomasz Czyż
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160907/4e6735c9/attachment-0001.html>


More information about the nix-dev mailing list