!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

48 Members
15 Servers

Load older messages


SenderMessageTime
19 Apr 2024
@hexa:lossy.networkhexa * thanks!18:50:41
22 Apr 2024
@djacu:matrix.orgdjacu

Is there a way I can circumvent the The option <option> is used but not defined error? I am playing around with a silly idea of nix modules to html. You can see the code for the <a> tag module here: https://github.com/djacu/nix2html/blob/main/a.nix

Two attributes I've implemented so far are download and href. If you run the run.sh script, you get an output that should look like this "<a download=new-filename href=#top></a>". But I don't want a user to have to set the download or href attributes every time.

Trying to think of a good solution but coming up empty. Any ideas?

06:19:34
@infinidoge:matrix.orgInfinidogeYou probably want either the anything option type, or to define your own types08:29:40
@nbp:mozilla.orgnbpWhy using submodules if you have only a single instance of each attribute?10:28:26
@nbp:mozilla.orgnbpYou can declare options to be unused: https://github.com/NixOS/nixpkgs/blob/8e54038847aa80ee2b1ffa9e313b0ab918f1903c/lib/options.nix#L228-L244 But I do not think this answer your problem. One example of usage of it is from this PR: https://github.com/NixOS/nixpkgs/pull/152785/files10:36:38
@nbp:mozilla.orgnbp Maybe you can use the type nullOr and have a default value of null. 10:37:54
@nbp:mozilla.orgnbp mkDefault should be delayed, like mkIf, so mapAttrs (name: mkDefault) should be replaceable by mkDefault.
https://github.com/NixOS/nixpkgs/blob/master/lib/modules.nix#L882
12:24:56
@infinisil:matrix.orginfinisil nbp Nah that's not the same. The former will merge attrs with the default priority, while the latter will override it completely 12:27:38
@djacu:matrix.orgdjacu

nbp: The reason for using submodules is because html attributes can be used in different html elements. So I want a reusable piece of code. The other reason is that I can define how html attributes are called in a standard way using the _out option I defined so everything rolls up nicely using the same logic. No custom logical needed for each html element.

I think I got something working using nullOr with the options inside the html attribute modules. So thanks everyone for your ideas.

15:45:13
@djacu:matrix.orgdjacu

Related but different question. I had trouble accessing the isDefined attribute of a submodule option.

For example, I define an option foo whos type is submodule, and with that I define options bar and baz.

At the top level, I can access options.foo.isDefined, but I cannot access options.foo.bar.isDefined. I tried digging around in the options attrset but I couldn't find it. Are the options of a "child" submodule option available to the "parent"?

15:49:55
@nbp:mozilla.orgnbp isDefined should not be used most of the time, as this is kind of an internal aspect, and it can only be used within the module itself.
Adding an options argument attribute to the submodule would let you query the option tree of the submodule.
16:06:40
@djacu:matrix.orgdjacu
In reply to @nbp:mozilla.org
isDefined should not be used most of the time, as this is kind of an internal aspect, and it can only be used within the module itself.
Adding an options argument attribute to the submodule would let you query the option tree of the submodule.
Yeah that's how I was doing it; defining the option argument in the submodule.
16:07:56
@nbp:mozilla.orgnbpThere is no way to get the option declaration out of a submodule, at least not without changing the submodule type.16:09:35
23 Apr 2024
@djacu:matrix.orgdjacu

Alright I've done something extremely silly and cursed.

https://github.com/djacu/nix2html
nix2html using nixos modules

also featuring the new attrTag type
:D
https://github.com/djacu/nix2html/blob/main/modules/elementChildren.nix

It's barely got any html elements or attributes so far so don't expect the world.

05:15:23
@infinidoge:matrix.orgInfinidogeFinally, we can subsume the entire internet into pure Nix05:16:01
@nbp:mozilla.orgnbp djacu: Ok, I am going to be pedantic :P
listOf is not modular, thus someone who might want to extend an existing "page" would have to completely replace the template describe in one of the imported modules.
At first I will suggest using the DOM names such as firstChild, nextSibling to describe to tree of DOM elements.
09:47:16
@nbp:mozilla.orgnbp Also, one might want to use shortcuts, such as in JS with getElementById("id"), we could imagine an types.attrsOf types.submodule dom.element; where the attribute name corresponds to the id, and where the definitions are forwarded to every submodule as long as the id attribtue is equal. 09:49:30
@nbp:mozilla.orgnbp This would add tons of mkIf … but only the one with the matching identifier would be extended with the module system. 09:50:34
@nbp:mozilla.orgnbp * djacu: Ok, I am going to be pedantic :P
listOf is not modular, thus someone who might want to extend an existing "page" would have to completely replace the template describe in one of the imported modules.
At first I will suggest using the DOM names such as firstChild, nextSibling to describe the tree of DOM elements.
10:48:37
@djacu:matrix.orgdjacu nice try nbp
you almost got me thinking seriously about about my meme project ;P
13:38:06
24 Apr 2024
@shalokshalom:kde.orgShalokShalom joined the room.14:38:14
@redblueflame:matrix.orgredblueflame joined the room.14:40:57
@ktemkin:katesiria.org[K]ate Temkin joined the room.15:13:08
@ckie:ckie.devckie (they/them) joined the room.16:07:44
@ckie:ckie.devckie (they/them) djacu: your nix2html reminds me of my html.nix which takes a different approach 16:09:46
@ckie:ckie.devckie (they/them)it oculd be changed to output config values!16:10:04
@djacu:matrix.orgdjacuwoah this is neat!16:13:41
@nbp:mozilla.orgnbpThe functor idea is indeed really neat, and someday someone would figure a way to make an HTML template tool based on Nix.16:35:04
@nbp:mozilla.orgnbpI myself tried it without being convinced by my own monster :P16:35:05
@infinidoge:matrix.orgInfinidogeThe functor idea is a really neat use of them16:38:39

Show newer messages


Back to Room ListRoom Version: 10