this post was submitted on 02 Dec 2024
21 points (100.0% liked)

Nix / NixOS

1834 readers
10 users here now

Main links

Videos

founded 2 years ago
MODERATORS
 

Recently got started with Nix and Home-Manager. I thought Advent Of Code would be a good way to get more comfortable with the Nix language.

I don't think I ever made it beyond Day 6 though, even in my most comfortable language (Python) so no idea where this will strand.

I am learning a lot about Nix though!

Have you used the Nix language outside of configuration? Let's share and discuss!

top 17 comments
sorted by: hot top controversial new old
[–] kintrix@linux.community 3 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

I definitely am: https://git.sr.ht/~kintrix/aoc2024

(The README is wrong, just copied it over from last year)

[–] F04118F@feddit.nl 2 points 3 weeks ago

Love the structure of your code. Exposing a part1 and part2 result from the same source file is a great idea

[–] monty33@lemmy.ml 3 points 3 weeks ago (1 children)

What's an advent of code? Interested if it will help me learn more!

[–] kintrix@linux.community 6 points 3 weeks ago

https://adventofcode.com/

An advent calendar of coding puzzles. Dec 1-25 you get a new puzzle every day

[–] gavin@fosstodon.org 2 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

@F04118F

If I can make the time, I will. But I know @ellyse is doing it. 🎅 👩‍💻
She did one last night live on stream.

https://ohai.social/@ellyse/113482901348671949

[–] ellyse@ohai.social 1 points 3 weeks ago (2 children)

@gavin @F04118F yup! thats a link to a 2019 AoC, but here's my video for day 1 this year https://www.youtube.com/live/P_3rUzAN0vw?si=W0qxiwKeDHVN_2aQ
the code is here: https://github.com/ellyxir/advent_of_code/tree/main/2024/nix/day01

i looked at your solution, good work!

[–] Atemu@lemmy.ml 2 points 3 weeks ago (1 children)

That looks very lispy, is that intentional?

[–] F04118F@feddit.nl 1 points 3 weeks ago (1 children)

Yes, Nix is a pure functional programming language, like Lisp.

The reason for its existence is to allow for reproducible and repeatable builds of packages and configuration. This is the basis for nixpkgs, NixOS and Home Manager.

[–] Atemu@lemmy.ml 2 points 2 weeks ago* (last edited 2 weeks ago)

Oh, I know; I have commit access to Nixpkgs ;)

I was just commenting on the way they've styled their Nix code here.

[–] F04118F@feddit.nl 1 points 3 weeks ago* (last edited 3 weeks ago) (2 children)

Your code looks awesome, I'm definitely going to steal some ideas from that, especially the lib.pipe really cleans up a lot of unnecessary bindings I did.

Doing a with import ./utils.nix is also a lot cleaner than nesting let statements.

[–] kintrix@linux.community 3 points 3 weeks ago* (last edited 3 weeks ago)

You can also use the pipe operators; but they are still experimental features.

foo (bar (baz x)) = x |> baz |> bar |> foo = foo <| bar <| baz <| x

[–] ellyse@ohai.social 1 points 3 weeks ago (1 children)

@F04118F which I promptly did away with because I couldn’t be arsed today lol

[–] F04118F@feddit.nl 1 points 3 weeks ago (1 children)

Nix regex sucks. Is there any package with a reasonable regex matchAll?

[–] ellyse@ohai.social 1 points 3 weeks ago (1 children)

@F04118F if it’s for todays advent of code, I used split and it worked fine. See my live steam on YouTube or my GitHub .

[–] F04118F@feddit.nl 1 points 3 weeks ago (1 children)

Somehow I completely missed that split can do match groups.. Oopsie! I did it in Python today but I did make a completely functional (and way too complicated) algorithm.

Tap for spoilerThe way you handle the do and dont is much cleaner

.

[–] ellyse@ohai.social 1 points 3 weeks ago (1 children)

@F04118F if i had known about match i probably would have gotten stuck also lol but luckily i used split once before and remembered it :) i made an issue in your github, hope thats ok, just to mention this in case you didnt see it on fedi!

[–] F04118F@feddit.nl 1 points 3 weeks ago

Yeah I was planning on changing the salty README and referencing your comment, thanks for putting the reminder there!