7 ms·
I really want to try NixOS but the Nix language is just so damn weird... Why didn't they use a syntax people wouldn't have to actually read a tutorial to learn.
by IshKebab 7y ago
I really want to try NixOS but the Nix language is just so damn weird... Why didn't they use a syntax people wouldn't have to actually read a tutorial to learn. E.g. C-style or Python-style? This article has a whole paragraph explaining `with`, but it wouldn't have needed any explanation if they called it `using` or `import`.
Same for the script parameters. I have absolutely no idea what this does
{ pkgs ? import <nixpkgs> { } }:
Why not:
function main(pkgs: Package = nixpkgs) {
}
Or something like that.
My second issue is that the files clearly aren't machine-editable. There's no sensible way to make a GUI that can edit your hostname if the hostname is defined in some Turing complete functional program.
But it definitely beats the design of any other package manager.
- therein 7y ago> My second issue is that the files clearly aren't machine-editable. There's no sensible way to make a GUI that can edit your hostname if the hostname is defined in some Turing complete functional program. I don't disagree with the overall argument you are making however on this point alone, they aren't meant to be machine-editable. They are functions, they take arguments. So you can make your module or system configuration or whatever, have unassigned variables and then have your function take them as parameters. Your GUI can invoke this function with arguments from the user input.
- lambdaba 7y agoI had a similar feeling for the language and I can assure you you do get used to it, and that it's probably not the syntax that's making it difficult but understanding the programming model. As for not being machine-editable, the nix language has a module system and it's easy to format a file with something that's whatever shape you want and have that machine-editable. Or use any other format and fromJSON etc. functions.
- arianvanp 7y agoWould be more like function main(pkgs: Map String Package = (import(sys.path("nixpkgs"))({}))){ } I'm not sure if it's better at this point...
- xena 7y agoExcept not everything in nixpkgs is a package! It's closer to a standard library that just happens to include a lot of packages.
- danieldk 7y agoIn fact, a derivation is not even a type. AFAIK it is only informally defined as an attribute set with an attribute type with the value derivation: https://github.com/NixOS/nixpkgs/blob/2cd8c35c1fdfdb773df7ec1dbe1aa7e1bc33f13d/lib/attrsets.nix#L305 https://github.com/NixOS/nixpkgs/blob/2cd8c35c1fdfdb773df7ec... I am pretty sure that instantiating a derivation probably requires more attributes. But in the end they are just attribute sets (which is one of the types in Nix besides strings, lists, etc.).
- otabdeveloper4 7y agoThe Nix language is much, much simpler than anything C-like or Python-like. It's basically just JSON with some support for variables and recursion. It being so simple is why the whole system works.
- xena 7y agoI'd argue that Nix is turing-incomplete. I've also been working on some tools that use Nix AST parsers to replace details like version numbers and hashes of git repos inside of existing .nix files. No fruit yet, but I'm still in the early planning phase.
- danieldk 7y agoI'd argue that Nix is turing-incomplete. What do you mean by this? Nix is a Turing-complete language.
- xena 7y agoNix itself prevents a lot of generalized recursion and side effects. If I recall turing-completeness in functional languages requires generalized recursion in ways Nix doesn't allow.
- mbrock 7y agoNix does allow general recursion, no? I haven’t seen any limitations that would prevent it from Turing completeness.
- danieldk 7y agoI really want to try NixOS but the Nix language is just so damn weird... It's not really weird when you know a functional language like Haskell or OCaml. My experience was actually the opposite: being a functional language, Nix's syntax was so simple that it took me only a few minutes to grasp most of it. But if you don't have some FP experience under your belt, both the syntax and commonly-used concepts are strange (e.g. fixed points). For me the learning curve was knowing what extra functions/functionality is provided by nixpkgs, which lacks quite a lot of documentation and discoverability. I found out about a lot of handy functions and techniques while reading derivations. I should have kept track of the issues while I was learning Nix/nixpkgs. But at that point I was still determining "do I want this?"
- k__ 7y agoGuix also uses a functional language and it was much easier to grasp for me.
- eeh 7y ago> My second issue is that the files clearly aren't machine-editable. There's no sensible way to make a GUI that can edit your hostname if the hostname is defined in some Turing complete functional program. For the times I need to do this, I define the values in a JSON file, which can be parsed by Nix's builtins.fromJSON into a Nix datatype.
- xena 7y agoDo you have a more detailed example of this?
- elbear 7y agoI assume they're talking about the same process you can use to pin nixpkgs. Have a nixpkgs.json with contents like these { "url": "https://github.com/nixos/nixpkgs-channels.git", "rev": "ea553d8c67c6a718448da50826ff5b6916dc9c59", "date": "2020-02-02T15:39:15+01:00", "sha256": "0g9smv36sk42rfyzi8wyq2wl11c5l0qaldij1zjdj60s57cl3wgj", "fetchSubmodules": false } Then, in nixpkgs.nix have let bootstrap = import <nixpkgs> { }; nixpkgs-pin = builtins.fromJSON (builtins.readFile ./nixpkgs.json); nixpkgs = bootstrap.fetchFromGitHub { owner = "NixOS"; repo = "nixpkgs"; inherit (nixpkgs-pin) rev sha256; }; in import nixpkgs
- eeh 7y agoAs an example, I have a program for regularly backing up directories to cloud storage (with deduplication, encryption, key management, etc. it's just a wrapper around Restic), which it does regularly via cron. I manage this in NixOS: different machines backup different directories, with different keys. This program has a CLI mode for setting up keys and buckets, which I run locally, and it writes to backup-metadata.json . So my workflow for adding a new directory to my system is: 1. Run CLI tool to create a new bucket, new API key with access to the bucket (with just the permissions it needs), and new encryption key. This writes to my backup-metadata.json file locally. 2. write some NixOS along the lines of: let metadata = (builtins.fromJSON "../backup-metadata.json").git; in { backup = { git = { path = "/var/lib/git-repositories"; frequency = "hourly"; bucket = metadata.bucket; key = metadata.key; apiKey = metadata.apiKey; }; }; } 3. Hit deploy. This starts the backups, and some monitoring to check the cloud storage is being regularly written to. The implementation of "backup" is private, but reuses parts of upstream NixOS (systemd.timer, Prometheus, ...)
- joepie91_ 7y ago> My second issue is that the files clearly aren't machine-editable. There's no sensible way to make a GUI that can edit your hostname if the hostname is defined in some Turing complete functional program. But you also don't need to! NixOS has a module system, with override/priority mechanics; so your GUI tool could just generate its own Nix file with its own settings, totally ignoring the system-wide settings, and then all you need to do is apply that generated configuration file in your imports; the module priority system does the rest.