Live data from Hacker News

Nix journey part 0: Learning and reference materials

tinkering.xyz

71–79 of 79 posts

Re: Nix journey part 0: Learning and reference materials

#71

I've always heard about nix operating systems. So when asked if I preferred an nix environment for development or windows, it was an easy answer. Now there is nixOS and a programming language called nix. I know this annoys me more than it should do, but it also keeps me away from the nix language and nixOS because I think the name is such a obvious stupid decision, that I'm worried what else stupid decisions they mad…

I know people use various heuristics for quality assessment, but using the name is new to me and makes me even more anxious about naming things.

Re: Nix journey part 0: Learning and reference materials

#72
post #64
post #29

Earlier quoted context omitted.

The language is in a weird place. The language itself is okay, but you're often trying to use the language to compute a result that meets an interface that is never defined. There is very poor ability to reason about the 'types'/shapes of arguments or the semantics of what outputs should conform to. It seems to require either 1) deep knowledge about the orchestration of the evaluation of the key files you interact wi…

This ^ When I write Rust I understand exactly what structs I’m creating due to the typesystem + the excellent documentation. In Nix I’m always lost. What struct should my flake function return? What arguments can it take? Etc.

As we make flakes stable, this will improve as the docs can prioritize this information, and tooling can focus on making this more clear. On a much longer horizon, future Nix language (eg: Nickel) improvements provide a gradual typing system. On a short-term, I'm trying to provide some opinionation and a framework to describe this (https://floxdev.com/docs/custom-packages/) . The challenge is to provide enough simplicity, but not so much that one loses the very benefits we are trying to achieve.

Re: Nix journey part 0: Learning and reference materials

#73
post #64

Earlier quoted context omitted.

This ^ When I write Rust I understand exactly what structs I’m creating due to the typesystem + the excellent documentation. In Nix I’m always lost. What struct should my flake function return? What arguments can it take? Etc.

As we make flakes stable, this will improve as the docs can prioritize this information, and tooling can focus on making this more clear. On a much longer horizon, future Nix language (eg: Nickel) improvements provide a gradual typing system. On a short-term, I'm trying to provide some opinionation and a framework to describe this ( https://floxdev.com/docs/custom-packages/ ) . The challenge is to provide enough simp…

Why does it need to be gradually typed?

If there was the equivalent to Rust doc generation that said

`fn configuration(config: Config, pkgs: Packages) -> Configuration`

"Implement this function in `/etc/nixos/configuration.nix"

And then I could click into each type and see what it's supposed to be, etc. Now, there would be some differences because Rust can't have arbitrary record types but you can imagine either forcing packages to define their inputs or just take the idea of rust doc here as a visual example. But being able to progressively drill down the types - and have the types checked by the language runtime! - would massively improve Nix's ease of use and discoverability.

Re: Nix journey part 0: Learning and reference materials

#74
post #49

Earlier quoted context omitted.

Are you using flakes? AFAIK `command-not-found` does not work with them. See https://github.com/NixOS/nixpkgs/issues/171054 and https://discourse.nixos.org/t/why-isnt-there-an-official-bui... `nix-index` is a flake-compatible alternative: https://github.com/bennofs/nix-index

I am using flakes, and now I know why `command-not-found` doesn't work, thank you.

You can make it work again! It's a one-liner in configuration.nix. Solutions and alternatives were covered in detail in a recent Discourse thread: https://discourse.nixos.org/t/which-package-provides-ifconfi...

Re: Nix journey part 0: Learning and reference materials

#75
post #73

Earlier quoted context omitted.

As we make flakes stable, this will improve as the docs can prioritize this information, and tooling can focus on making this more clear. On a much longer horizon, future Nix language (eg: Nickel) improvements provide a gradual typing system. On a short-term, I'm trying to provide some opinionation and a framework to describe this ( https://floxdev.com/docs/custom-packages/ ) . The challenge is to provide enough simp…

Why does it need to be gradually typed? If there was the equivalent to Rust doc generation that said `fn configuration(config: Config, pkgs: Packages) -> Configuration` "Implement this function in `/etc/nixos/configuration.nix" And then I could click into each type and see what it's supposed to be, etc. Now, there would be some differences because Rust can't have arbitrary record types but you can imagine either forc…

> Why does it need to be gradually typed?

Because one of the things that's nice about using Nix as a consumer of Nix libraries is that for simple use cases, your code can be so simple that it truly resembles a plain configuration file.

By implementing a gradual type system, Nickel allows producers of Nickel libraries to enrich their code with helpful type annotations without making all of the code consuming those libraries verbose or cumbersome.

> being able to progressively drill down the types - and have the types checked by the language runtime! - would massively improve Nix's ease of use and discoverability.

That definitely seems to be the goal.

If you wanna get a feel for how Nickel looks today, you should try translating the exercises from the old Tour of Nix¹ on the new Nickel Playground²! The lead dev is very friendly and receives feedback warmly.

1: https://nixcloud.io/tour/?id=1

2: https://nickel-lang.org/playground

Re: Nix journey part 0: Learning and reference materials

#76
post #8

So, I don't quite grok nix. Am I supposed to use it instead of Ansible and Terraform? Where does it fit exactly?

Without having properly tried it either, my general impression is that the pitch goes a bit like this: If you love Haskell and wants to make everything that has to so with packages on your system more like Haskell, Nix's got your back.

Playing with Nix did increase my interest in functional programming, which was very new to me when I started using Nix.

But I've never gotten around to learning Haskell, and I don't think Nix is just for FP people.

Re: Nix journey part 0: Learning and reference materials

#77
post #75
post #73

Earlier quoted context omitted.

Why does it need to be gradually typed? If there was the equivalent to Rust doc generation that said `fn configuration(config: Config, pkgs: Packages) -> Configuration` "Implement this function in `/etc/nixos/configuration.nix" And then I could click into each type and see what it's supposed to be, etc. Now, there would be some differences because Rust can't have arbitrary record types but you can imagine either forc…

> Why does it need to be gradually typed? Because one of the things that's nice about using Nix as a consumer of Nix libraries is that for simple use cases, your code can be so simple that it truly resembles a plain configuration file. By implementing a gradual type system, Nickel allows producers of Nickel libraries to enrich their code with helpful type annotations without making all of the code consuming those lib…

> By implementing a gradual type system, Nickel allows producers of Nickel libraries to enrich their code with helpful type annotations without making all of the code consuming those libraries verbose or cumbersome.

Those seem like different things and also on the wrong axis. The presence of types in a language does not require manually annotating everything. In fact, on the contrary, strongly typed systems have better type inference allowing fewer annotations, particularly for consumers of APIs that are typed.

Re: Nix journey part 0: Learning and reference materials

#78
post #77
post #75

Earlier quoted context omitted.

> Why does it need to be gradually typed? Because one of the things that's nice about using Nix as a consumer of Nix libraries is that for simple use cases, your code can be so simple that it truly resembles a plain configuration file. By implementing a gradual type system, Nickel allows producers of Nickel libraries to enrich their code with helpful type annotations without making all of the code consuming those lib…

> By implementing a gradual type system, Nickel allows producers of Nickel libraries to enrich their code with helpful type annotations without making all of the code consuming those libraries verbose or cumbersome. Those seem like different things and also on the wrong axis. The presence of types in a language does not require manually annotating everything. In fact, on the contrary, strongly typed systems have bett…

> In fact, on the contrary, strongly typed systems have better type inference allowing fewer annotations, particularly for consumers of APIs that are typed.

The number of type annotations required for configuration code can't be less than zero, which is what I'd expect with Nickel.

My impression of how verbose a totally statically typed system might be for this is mostly based on what I've seen of Dhall and heard about it, which may not be fair, idk.

But the idea is that Nickel can be used for configuration code that any sysadmin would be used to writing because it might as well be JSON or YAML. This is what motivates the library/configuration distinction:

> Nickel also aims at being as interoperable with JSON as possible, and dealing with JSON values in a typed manner may be painful. For all these reasons, being untyped1 in configuration code is appealing.

> But this is not true of all code. Library code is written to be reused many times in many different settings. Although specialised in configuration, Nickel is a proper programming language, and one of its value propositions is precisely to provide abstractions to avoid repeating yourself. For reusable code, static typing sounds like the natural choice, bringing in all the usual benefits.

https://www.tweag.io/blog/2021-03-18-nickel-gradual-typing/

The Nickel docs currently cite other reasons as the main motivation for choosing gradual typing:

> For pure configuration code, consisting predominantly of data, static typing is perhaps less useful than in other kinds of application. Firstly, a configuration is a terminating program run once on fixed inputs, so basic type errors will show up at runtime. Secondly, for data validation, static types are too rigid. For example, statically checking that an expression will always evaluate to a valid port number requires very advanced machinery. On the other hand, checking this property at runtime is trivial.

https://nickel-lang.org/user-manual/correctness

Re: Nix journey part 0: Learning and reference materials

#79

Earlier quoted context omitted.

And vice versa. It's tricky to know what the binary will actually be named. I have had to look directly in the /nix/store enough times that I lost count.

I will say this is not a nix specific problem and also not trivially solvable by policy because of packages that contain multiple binaries as produced by the upstream developer (e.g. grep/fgrep/egrep, pacman/makepkg/pacman-key, , go/gofmt, ffmpeg/ffprobe, qemu has about a billion, etc.).

It would be trivial to print the contents of the nix store that package uses.

It would be pretty straightforward to show only what ends up in the path.

Post reply on HN