points by tom_alexander 1 day ago | 0 comments
> Ask nixpkgs a question in a loop. Interrogate and explore nixpkgs in a REPL
nix repl --expr 'builtins.getFlake "github:NixOS/nixpkgs/nixos-unstable"'
nix-repl> builtins.filter (name: lib.licenses."${name}" ? spdxId && lib.strings.hasPrefix "GPL" lib.licenses."${name}".spdxId) (builtins.attrNames lib.licenses)
[
"gpl1Only"
"gpl1Plus"
"gpl2"
"gpl2Only"
"gpl2Plus"
"gpl3"
"gpl3Only"
"gpl3Plus"
][–] OskarS 16 hours ago
[–] alexandrutocar 19 hours ago
Exactly my thoughts. You can even go as far as `nix eval .#<attr> --json --apply <expr>` to transform whatever your flake outputs list into your desired format and then presenting it as JSON. Then you can consume the JSON and process it with a language of your choice. Or you can extend the standard library with your own primitives, types and tricks and do whatever you want to do in Nix. The switch to other language is worth only if processing that you are doing becomes too slow or too clunky in Nix - both are subjective, so I personally do the processing in Nix and export it only if I want AI in the loop e.g. giving my packages and services as context to siff through changelogs of flake updates to make summaries with information relevant to my systems.
[–] tensegrist 18 hours ago
in my over a decade of using nix i have never really managed to get into using the repl because every time i have it's been … weird in some way or another
[–] skavi 23 hours ago
aren’t there also nix lsps
[–] tom_alexander 20 hours ago
Yep! Personally I use nixd but there are multiple nix lsps. There are definitely places where nixd stops helping due to nix being a dynamically-typed language. For example, when writing functions it doesn't know what the types of any of the parameters are because they could be literally anything. That being said, the example from the screenshot of typing `pkgs.neo` and getting a list of completions for package names absolutely works with nixd.
What's weird is Farid absolutely knows about both nixd and `nix repl` but he didn't mention either of them or compare, instead making it sound like nix doesn't have a repl or a language server.
You're correct in that the article is wrong in saying you can't use a nix repl this way, but I took the broader point of it to be "Nix-the-language gets in the way of the Nix-the-model". Which is something that I personally agree with 100% and I think the article illustrates beautifully.