gchristensen changed the topic of #nixos-chat to: NixOS but much less topical || https://logs.nix.samueldr.com/nixos-chat
<Drakonis> 4.18 came out, soon we'll have 4.19 then the infamous 4.20
lassulus_ has joined #nixos-chat
lassulus has quit [Ping timeout: 272 seconds]
lassulus_ is now known as lassulus
tertle||eltret has joined #nixos-chat
Lisanna has quit [Remote host closed the connection]
Drakonis has quit [Remote host closed the connection]
jD91mZM2 has joined #nixos-chat
<jD91mZM2> Ugh, implementing comments into rust-nix seems to just raise so many questions
<jD91mZM2> What if you do something like `/* hello */ { /* world */}`? Only the leading comments will currently be counted
<jD91mZM2> And if I do somehow implement both leading/trailing, what would a comment inbetween two things count as? Trailing to the former or leading to the later?
<jD91mZM2> At least stuff like `3 + /* comment */ 2` will work. This is due to 2 being its own node in the AST
<ekleog> rust-nix?
* ekleog interested
<jD91mZM2> I'm writing a Nix parser in Rust: https://gitlab.com/jD91mZM2/rust-nix
<ekleog> oh, looks fun :D
<jD91mZM2> I'm having more and more difficulty seeing how useful it could be though
<ekleog> you may have a look at https://github.com/haskell-nix/hnix/issues/57 :)
<{^_^}> hnix#57 (by Profpatsch, 1 year ago, open): Comment constructor
<jD91mZM2> Optimally it could be a formatting tool... but... it's hard to preserve all the information
<ekleog> for the formatting tool, I've started writing one with hnix, missing precisely the comments, the rest is pretty much OK :°
<jD91mZM2> Ooo, cool!
<ekleog> to me, it could be useful to start a rewrite of nix in rust, for more security (after all, nix is suid and allows non-root people to execute stuff, so having a strong type system may help in having at least a bit of security, and not losing performance is important)
<ekleog> not saying I'd ever have time for it, but it's been lurking in the back of my head 😇
<jD91mZM2> Yeah that would be great
<ekleog> all that to say: I do think it'll end up being useful if it's well-written, even though I can't tell yet in which way :)
<jD91mZM2> > if it's well-written
<{^_^}> error: syntax error, unexpected ')', expecting THEN, at (string):167:1
<jD91mZM2> You're talking to the wrong person
<jD91mZM2> I'm not known for making things clean, sadly :P
<ekleog> (btw, I see you wrote your parser from scratch, did you consider looking at the `nom` crate? it should make things much easier, that's basically the father project of synom, used in rustc :))
<ekleog> (synom being basically nom with streaming handling removed for performance, as it only needs to deal with files whose complete contents are known straight-away)
<jD91mZM2> Yeah other's have said I should probably use a library like that too. Honestly, the main reason I'm writing one from scratch is so I can feel good about myself lol
<ekleog> (but it's not stable and there are no plans to stabilize it afaik :/)
<ekleog> 'k ^^
<jD91mZM2> Too late to change now I guess
<ekleog> as you want, I'll let you determine whether you think it's sunk cost fallacy or not, don't know how much work you put in there yet :)
<ekleog> (just saying if you end up rewriting it later it'll be worse, so that's a choice you have to make ^^)
<jD91mZM2> WIP comment support pushed
<jD91mZM2> TODO: Lists, everything functions, if..then..else, inherit
<jD91mZM2> Since Nix functions are like haskell, where you can have incomplete functions, would something like FnCall(FnCall(Var("test"), Value(1)), Value(2)) make sense for (test 1 2)?
obadz- has joined #nixos-chat
obadz has quit [Ping timeout: 240 seconds]
obadz- is now known as obadz
<ekleog> that's the way hnix does it, and I can't think of anything better :)
<sphalerite> ekleog: nix isn't suid..?
<sphalerite> jD91mZM2: yes that would make sense. Although in the functional world I think people usually call it "applying" a function, not "calling" it
<MichaelRaskin> Nix daemon on-wire protocol has to accept input from semi-trusted counterparties, Nix evaluation is normally done with the same privileges as the invoking user has
<jD91mZM2> sphalerite: Ah, good point
<ekleog> sphalerite: good point, it is a daemon running as root, I went a bit fast in my “allows controlled elevation of privileges” reasoning :)
<andi-> rust-nix sounds great!
* andi- grabs a coffe and reads backlog
<jD91mZM2> :D
<MichaelRaskin> I would say that your reasoning does apply to the daemon protocol; also, a sandboxing via namespaces gets better, people might become more likely to run in sandbox unvetted stuff from the net while evaluating it under the normal unrestricted account
<ekleog> MichaelRaskin: indeed :) also, I'm not sure a project to do exclusively nix-daemon in rust would really work out: it'd bring in less motivation, even though it'd likely be less work
<MichaelRaskin> You don't want to reimplement nix-daemon
<MichaelRaskin> You want to implement nix-daemon-proxy
<ekleog> (also, another argument I have in mind for rust-nix is, if we tell the Rust community “Hey, here is a feature-complete package manager with all the package you need… written in Rust!”, it may bring in significant attention and publicity)
<MichaelRaskin> There are many build-policy things that would be nice to have, that would be nice to have in a separation-of-concerns style
<ekleog> hmm, what do you mean by build-policy things?
<LnL> why I think rewriting nix would be a bad idea like some people have suggested, having alternative implementations around is probably a good thing
<LnL> while*
<andi-> what woudl that proxy do exactly? Talking to an already running nix-daemon? Filtering the derivations?
<MichaelRaskin> If you are building with 4 jobs and you will eventually need Chromium and you can start building it, start building it
<MichaelRaskin> The proxy would accept the build requests, reject the malformed ones, and own the connections to the actual daemon doing the builds
<ekleog> LnL: oh, yeah, by “rewriting” I'm not trying to imply that c++-nix should be dropped, sorry if that was unclear :)
<LnL> I was talking about other discussions
<MichaelRaskin> That would also solve the A->C B->C problem (queue A, B; C starts building because of A; cancel A; C is cancelled, then restarted because of B)
tertle||eltret has quit [Quit: Connection closed for inactivity]
__Sander__ has joined #nixos-chat
__Sander__ has quit [Ping timeout: 256 seconds]
__Sander__ has joined #nixos-chat
__monty__ has joined #nixos-chat
<joepie91> Error: Encountered instance of an unknown type with hash undefined
<joepie91> and just when I thought I had my deserializer working...
<joepie91> <.<
<andi-> undefined smells like javascript ;)
Lisanna_ has joined #nixos-chat
<joepie91> andi-: it is, indeed, javascript
<joepie91> anyway, it's working now :D
<joepie91> tests passing and all
<andi-> while still showing the error? :P
<joepie91> haha, nah
<andi-> (that would be another JS smell)
<joepie91> eh
<jD91mZM2> Congratz!
<joepie91> you have to be doing some pretty stupid things to have an error showing and *still* have incorrect behaviour
<joepie91> :P
<joepie91> things such as 'logging and swallowing errors'...
<joepie91> andi-: jD91mZM2: here's the tests I just made work: https://gist.github.com/joepie91/895fa72883d604e0da68591fbe807dd6
<joepie91> next step: add lots of edge cases until it breaks :P
MichaelRaskin has quit [Quit: MichaelRaskin]
<jD91mZM2> Uhh, so I did something, and now 12 tests fail
<jD91mZM2> I think I messed something up
<jD91mZM2> Ah yes, accidentally parsing twice at one location due to me not deleting the original code after rewriting it
<joepie91> heh
lopsided98 has quit [Ping timeout: 240 seconds]
lopsided98 has joined #nixos-chat
Drakonis has joined #nixos-chat
<jD91mZM2> rust-nix just got basic lambda support! The TODO is getting smaller :D
<jD91mZM2> It can now parse `(x: y: x + y) 2 5`
<gchristensen> pretty fun, jD91mZM2
<jD91mZM2> If I'm not mistaken, I'm just missing argument patterns, if..then..else and inherit
<gchristensen> how about `with`?
<jD91mZM2> That and let..in exists
<infinisil> jD91mZM2: And you probably forgot the super special let syntax as well
<jD91mZM2> Oof, what's that?
<infinisil> > let { body = 10; }
<{^_^}> 10
<jD91mZM2> > let { a = 1; b = 2; }
<{^_^}> attribute 'body' missing, at undefined position
<infinisil> (do not ask me why that exists, because I have no idea)
<jD91mZM2> umm
<jD91mZM2> Ouch
<jD91mZM2> You can see all implemented things in https://gitlab.com/jD91mZM2/rust-nix/blob/master/tests/
<jD91mZM2> And no, these aren't the only tests, don't worry. Those are just the integration tests
<infinisil> > let { body = x; x = 10; }
<{^_^}> 10
<infinisil> Oh you know what, this syntax isn't too useless
<infinisil> It's useful when you have it in a file and you want to assign some variables but also provide a result
<infinisil> > (rec { body = x; x = 10; }).body
<{^_^}> 10
<infinisil> Would be the equivalent, but more ugly
<jD91mZM2> > let x = 10; in x
<{^_^}> 10
<infinisil> > let x = { body = 10; } in let x
<{^_^}> error: syntax error, unexpected IN, expecting ';', at (string):166:24
<infinisil> > let x = { body = 10; }; in let x
<{^_^}> error: syntax error, unexpected ')', expecting '.' or '=', at (string):167:1
<infinisil> Oh well
<sphalerite> I think let { body = …; } predates let ... in
<jD91mZM2> Would it be fine to share AST representation for let {body} and let..in?
<infinisil> jD91mZM2: You could just desugar let {body} to the rec I mentioned earlier
<jD91mZM2> ... or just desugar it to let..in?
<jD91mZM2> > let x = 10; in x
<{^_^}> 10
<infinisil> Oh, hmm..
<infinisil> Yeah probably
<infinisil> > let { x = body; body = x; }
<{^_^}> infinite recursion encountered, at (string):166:11
<jD91mZM2> Oh, good point
<infinisil> > let x = body; body = x; in body
<{^_^}> infinite recursion encountered, at (string):166:9
<infinisil> Should work
<jD91mZM2> Cool, thanks!
<infinisil> Also, be sure to implement this correctly (it's not in the parser, but I thought I'd show it):
<infinisil> > (1.0 * 1) * 1
<{^_^}> value is a float while an integer was expected, at (string):166:1
<infinisil> (!)
<jD91mZM2> Yeah my thing does distinguish floats and ints, so any implementation can correctly handle that :)
<jD91mZM2> Oh, maybe I can't desugar it. I'd need a span for the inserted `body` thing
<jD91mZM2> (I preserve span information)
<jD91mZM2> Welp, samueldr will just be happy, now his formatters can preserve the legacy syntax too :P
<jD91mZM2> I just remembered `true` and `false` exist lol
<jD91mZM2> (Unrelated, just forgot that in my parser)
<infinisil> jD91mZM2: Got null, assert, abort, throw?
<jD91mZM2> infinisil: Haven't got null. Do assert/abort/throw require any special syntax?
<infinisil> assert does, abort and throw can be ordinary functions
<jD91mZM2> Where can I find docs on assert?
<infinisil> nix manual probably
<infinisil> > assert false 10;
<{^_^}> error: syntax error, unexpected ')', at (string):167:1
<infinisil> > assert false; 10
<{^_^}> assertion failed at (string):166:1
<infinisil> > assert true; 10
<{^_^}> 10
<jD91mZM2> Ah, found it
<jD91mZM2> (and thanks for all the help btw :D)
<infinisil> :)
<infinisil> jD91mZM2: Oh and btw, nix has a suite of tests for the language: https://github.com/NixOS/nix/tree/master/tests/lang
<jD91mZM2> Those require evaluation, right?
<infinisil> yeah I think so
<jD91mZM2> Also I need ==, != and ! when I implement if..then
<infinisil> but you can run the parser over all those files
<infinisil> Oh and of course you can run it over all of nixpkgs nix files (well almost all, some don't actually parse)
<jD91mZM2> Wait what
<jD91mZM2> Don't all nixpkgs file parse??
<infinisil> Yup!
<infinisil> There are some nix template files in there..
<jD91mZM2> I was planning on using nixpkgs as the ultimate test since there are so incredibly many different people who have each pushed stuff with their own style and so on
<infinisil> Just need to compare the exit status of nix-instantiate --parse with your parser for every file
<jD91mZM2> Good idea, thanks!
<jD91mZM2> Would recursively importing <nixpkgs> also be a way of testing all safe files? That was my plan
<jD91mZM2> I mean, nothing that doesn't compile should be imported anywhere, right?
<samueldr> and later on, whatever you output from your AST, verify that it matches 1:1 with the file and parsed AST matches (with the command found out the other day)
<jD91mZM2> It won't do that currently, some comments can be in really unfortunate places
<jD91mZM2> Like, in the middle of a freaking AST node
<jD91mZM2> > let x = 3 /* how should this comment be saved? it belongs to the semicolon */ ; in x
<{^_^}> 3
<infinisil> Maybe make the result of a file parse be (Ast, Comments)
<jD91mZM2> Hmmm
<samueldr> a/**/-b is fun btw
<jD91mZM2> Is that a path?
<samueldr> that's a -b
<jD91mZM2> Oh
<samueldr> comments as per the current parsing are the same as whitespace
<jD91mZM2> OH, I didn't even notice that was a comment
<samueldr> :)
<jD91mZM2> I thought that was either a path or "a divided by powered by divided by minus b"
<gchristensen> samueldr: I hate that :P
<jD91mZM2> Let's use comments as indention
<samueldr> hey now, that's only things you realize once you try building a parser
<jD91mZM2> {/**/a = 3;/**/b = 2;}
<infinisil> > ---1
<{^_^}> -1
<infinisil> jD91mZM2: Got that? ^^
<jD91mZM2> Yep
<jD91mZM2> It's the one that makes the most sense out of all these tbh
<samueldr> > let a = a: a; in a/**/1
<{^_^}> 1
<samueldr> :D
<samueldr> comments ~== whitespace as far as the parser is concerned
<jD91mZM2> That's good
<jD91mZM2> but hard when formatting
<samueldr> yep
<jD91mZM2> Honestly, IMO it'd be ok a formatter to reorder some comments after tokenizing
<jD91mZM2> If it's in the middle of an expression and can't be represented in the tree
<joepie91> "comments and whitespace are the same thing" is almost the default approach in writing a parser if you don't particularly care about comments :P
<samueldr> ^ meshes in with the reading I made
<jD91mZM2> joepie91: Not in the most popular LOLCODE parser :(
<jD91mZM2> You can get "OBTW is not an identifier"
<joepie91> ... okay, you win, I have no response to that :)
<gchristensen> todo: make a whitespace and comment preserving nix parser
<jD91mZM2> gchristensen: rust-nix doesn't preserve whitespace, but it preserves span information so you could recreate it
<samueldr> gchristensen: just this once, don't do it in bash :)
<gchristensen> Nix only has one valid character for indentation, so spans are fine
<jD91mZM2> Not all comments are preserved in the AST though, like if they are in the middle of an expression
<jD91mZM2> gchristensen: Not spans as in "4x space", more spans like "this token starts at (0, 1) and goes to (0, 15)"
<samueldr> gchristensen: that's a dangerously inflammatory comment there :)
<jD91mZM2> I plan on making an example interactively let's you select an AST node and it'll highlight the corresponding code in the original source
<gchristensen> samueldr: it is canonically true: https://github.com/NixOS/nixpkgs/blob/master/.editorconfig#L16-L19
<jD91mZM2> s/example/example that
<samueldr> ni nixpkgs!
<samueldr> in*
<gchristensen> yeah, the first 1.5M lines wins there I think :P
<samueldr> as long as the parser accepts tabs it's still valid :D
<sphalerite> infinisil: could we get {^_^}'s issue/PR expansion in #nixos-aarch64 too maybe please? :D
<gchristensen> you should see some of the insane indentation style I've seen at private corporate repos
<samueldr> or lack of style? amirite?
<gchristensen> no there is definitely ... style ... but it is like the 1970's of indentation
<infinisil> sphalerite: Ah right
<infinisil> I'll just turn it on for all channels {^_^} receives messages from
<gchristensen> samueldr: I posit that using bash inside of Nix is just fine because it creates a nice impermeable barrier containing the badness
<gchristensen> oops raining, brb
<samueldr> impermeable, ain't it?
<samueldr> I was thinking about implementing the parsing in bash :)
<jD91mZM2> Stuff I've noticed when making a parser: 1. Paths are annoying because you need lookahead. 2. Patterns are annoying because you need lookahead.
<infinisil> Don't you need lookahead for most grammars anyways?
<jD91mZM2> You only need to be able to peek like one element most of the time
__Sander__ has quit [Quit: Konversation terminated!]
<gchristensen> that woul dput it in to a specific class of grammar, which I think most langs try to be
<sphalerite> is that what LL(1) is?
<gchristensen> think so
<simpson> In fact, LL(k) for any fixed k of lookahead is equivalent to LL(1), via a space-time tradeoff.
Drakonis has quit [Remote host closed the connection]
<pie__> awesome i didnt know there were integration tests like that https://grahamc.com/blog/an-epyc-nixos-build-farm
<gchristensen> you didn't? oh man I should write up some posts just about stuff about how AMAZING they are
<pie__> gchristensen, you should :D
<pie__> on one hand im not surprised, on the other hand, AWESOME
<gchristensen> reading through the bittorrent test, it easily broke my assumption about what it was doing.
<gchristensen> several times*
<pie__> what language are those tests in?
<manveru> perl
<pie__> oh >.>
<gchristensen> I usually try to not answer that question
<manveru> :D
<pie__> "Oh."
<gchristensen> because who cares, you only write 10 lines of it
<manveru> it's helpful if you wanna do something more complicated
<gchristensen> yea
<gchristensen> but I worry people hear "perl" and decide it is just "ugly legacy cruft" and not an insanely valuable piece of code which works well
<manveru> yeah
<manveru> it's not like you couldn't replace that part either
<gchristensen> yeah but also why bother
<clever> gchristensen: ive memorized a decent amount of the ghc source, yet i can still forget how to define a data record, lol
Ericson2314 has joined #nixos-chat
Ericson2314 has quit [Read error: Connection reset by peer]
Ericson2314 has joined #nixos-chat
<gchristensen> ha
<gchristensen> I'm just trying to backport a patch and found it too confusing, and have sort of given up
<gchristensen> I think I'll let a coworker deal with it
<jD91mZM2> gchristensen: You work with Nix?
<jD91mZM2> How does that give profit?
<gchristensen> there are many companies who value what Nix does
<gchristensen> and I work as a contractor for some of them
<jD91mZM2> Yes but how do they get money?
<jD91mZM2> Or do they get money for somewhere else and donate?
<gchristensen> they have normal businesses, exchanging goods and services for money
<jD91mZM2> Ah
<gchristensen> there is no donation about this process, they are just hiring me as a Nix-knowning person. the company I do a lot of work through has about 4-5 people working there full time being contracted out on Nix projects.
<jD91mZM2> Sounds awesome!
<gchristensen> two years ago I made my goal get hired to do Nix-related things full time, and it worked :)
elvishjerricco_ has joined #nixos-chat
<jD91mZM2> Oof my code is getting real hairy
<jD91mZM2> So many nested match statements
jcrben has quit [*.net *.split]
dtz[m] has quit [*.net *.split]
andi- has quit [*.net *.split]
elvishjerricco has quit [*.net *.split]
hodapp has quit [*.net *.split]
elvishjerricco_ is now known as elvishjerricco
jcrben has joined #nixos-chat
<gchristensen> today is officially Yak Shave Day
<sphalerite> Damn I forgot to shave mine
andi- has joined #nixos-chat
<LnL> same, the feature I've been working on the past few days ended up being a huge rabbit hole that made me distrust half of the codebase
<jD91mZM2> PHEW! Finally done with pattern matching in rust-nix
<jD91mZM2> Code is not optimal, but I am honestly not sure how to improve it
<jD91mZM2> (Pattern matching being { a, b ? "wat", c, ... }: thing)
MichaelRaskin has joined #nixos-chat
jD91mZM2 has quit [Quit: WeeChat 2.0]
Lisanna_ has quit [Quit: Lisanna_]
lopsided98 has quit [Quit: Disconnected]
lopsided98 has joined #nixos-chat
Lisanna has joined #nixos-chat
__monty__ has quit [Quit: leaving]
<pie__> isnt every day yak shave day
<pie__> what am i doing with my life :p
kisik21 has joined #nixos-chat
tertle||eltret has joined #nixos-chat