137 points · by Reventlov · 3y ago · 106 comments
Trying to learn /how to use/ nix was awful. I found lots of guides, almost always incomplete, and oftentimes directly contradicting each other. It took me weeks to get a working build and much of that time was anything but fun.
I like the outcome, and I’m glad I took the time now, but it was a slog that I don’t think I could really recommend to any of my peers.
It’s too bad guix went full hardcore FOSS and refuses to support macs, because they seem to have better docs and using a language that I can use outside of my package manager makes a lot more sense to me.
Within the span of a afternoon and a bit a reading I went from zero, to a script that lets me setup an entire dev systems with just a few commands in a vm, and or even on hardware.
If anything the Nix documentation is just as good as every other thing out there. What is different is there are more than one way to do many things in Nix. This to me I think is the core of complaints. Its a language, and thus the language has may expressions that result in the same outcome.
The second bit I think people struggle with is it is functional. If you look at Nix complaints they appear to nearly be identical to that of Haskell.
First it's a distribution and a package manager, and the guidance regarding these is sub-par. Especially with what there is of documentation being split between the old and new UIs, then being told about flakes but that they're experimental so it's not clear whether you should or should not use them.
I just went to the nix website, clicked "first steps with nix" and I get https://nixos.org/guides/ad-hoc-developer-environments.html
Is that useful? I'm sure to somebody who already knows what they want out of nix it is, but the first thing I'm told is that shell environments exist and are useful to "use the tool without having to install the software.". Ok, but what if I want to install the software? Then there's listing of what's essentially a magical invocation out of nowhere:
$ nix-shell -p 'python38.withPackages (packages: [ packages.django ])'
I can understand that (or at least reach what I assume is an understanding), but there's no real explanation to give me knowledge to expand upon, if anything the explanations are worse than useless:> We create an ad hoc environment with $PYTHONPATH set and python available, along with the django package.
thank you very much, that confirms I'd about interpreted the line correctly, but you've not told me what `withPackages` is or where `packages.django` comes out of so I'm not really helped.
And apparently the next step is "declarative and reproducible developer environments", or possibly "towards reproducibility: pinning Nixpkgs"? Or even better, "To quickly setup a Nix project read through Getting started Nix template", I have no clue what a nix project is or why I'd want one.
There's not just a step missing here, there's an entire floor, possibly building. It's like the nix community saw how git is taught and went "we can do worse".
Nope, it's a language, and thinking of it as those things, even more so firstly is probably part of the struggle.
It's a language that you use to get your computer to do specific things. In this case, it might be a "package manager" and in the other case it could be a "distribution".
When you write go or rust to print "hello world" to the terminal you don't go around and call these things "printers", or "hello worlders".
It's a language, just like rust, go, php, bash, ed, awk, and brainfuck. Your first example even shows you using the language why proclaiming ahah! shell thing, or package manger! -> `'python38.withPackages (packages: [ packages.django ])'` is using this language to instruct the computer to do something. If you don't want to take the time to learn the language and understand its outputs, and want to just think "this is a package manager" then you are going to get lost.
Why would you go to https://nixos.org/learn.html, click on an introductory example titled "Ad-hoc developer environments" and complain that it doesn't explain how to permanently install software?
> but there's no real explanation to give me knowledge to expand upon
Again, you're pointing to a page containing TLDR examples. That's not the right place for an in-depth explanation.
> There's not just a step missing here, there's an entire floor, possibly building. It's like the nix community saw how git is taught and went "we can do worse".
No surprise because you missed the entire manual.
I would never recommend nixos to anyone. The concept is awesome, but the execution is terrible.
One document tells you to flakes, another tells you that it’s experimental and should be avoided.
One document tells you that you should use Darwin modules and home manager, and then completely omits the fact that the linked home manager scripts don’t work with Darwin by design leading to “why the fuck isn’t this file they tell me should be auto generated not being created”.
Because the official docs don’t seem to cover real world use cases, you end up relying on a labyrinth of out of date and conflicting user contributed tutorials and it is very frustrating.
Once you know what to do nix is simple enough, but learning what to do is outright painful; if you don’t believe me look to the other replies to my comment.
> How do I create a nix package that clones eMacs from GitHub and builds it from source?
{ pkgs ? import <nixpkgs> {}, fetchFromGitHub }:
let
emacsSrc = fetchFromGitHub {
owner = "emacs-mirror";
repo = "emacs";
rev = "master";
sha256 = "0xabcd1234";
};
in pkgs.stdenv.mkDerivation { name = "emacs";
version = "27.1";
src = emacsSrc;
buildInputs = [ pkgs.autoconf pkgs.make ];
configurePhase = ''
autoconf
./configure --prefix=$out
'';
buildPhase = "make";
installPhase = "make install";
}What surprises me is that people tout RPM/Chef as easier replacements to Nix/NixOS. The assumption about those being "replacements" of each other is questionable because they address different needs. What's even more questionable is the part about RPM or Chef being easy. I have dealt with those two for years as part of my day job, and they're both far from easy. I still have troubles with them to this day. Documentation is far more lacking than Nix, and it's not because things are obvious. If you encounter any trouble, you almost always have to dive into the source code. Navigating the source code of RPM or Chef is a nightmare because the code is scattered across countless different repositories and it's impossible to guess where to look for to begin with. Choice of programming languages doen't help here too. Chef is written in Ruby, which has a tendency of making code ungreppable due to its metaprogramming features. RPM has its own macro syntax which works similar to the C preprocessor. It's very terse and full of gotchas. Navigating around Nix code is much, much easier in comparison. Everything you need is in a single repo, https://github.com/NixOS/nixpkgs, and written in a JSON-like language.
Many people also claim that Nix is hard because it requires a functional programming background. That too doesn't match my experience. Nix expressions are basically JSON with functions. Learning the syntax is a non-issue if you know JSON and some common programming language constructs like conditionals, functions, map, filter and reduce. The only functional programming exposure I had prior to Nix was LISP, in a university classroom. Yet I didn't experience problems learning the syntax. The hard part is learning how to actually utilize the language. The documentation and some grepping around of the Nixpkgs codebase helped a lot with this.
At some point, I might try again, using NonGuix ( https://gitlab.com/nonguix/nonguix ), but right now I'm not using Guix SD. Instead, I try to use Guix on small projects (like building websites using pelican), without going full Guix.
What I'm most impressed with Guix is the time machine and Software Heritage integration, but it still needs a lot of improvement for developers, for example allowing to specify environment variables in manifest.scm files.
Just use setenv in the manifest:
(setenv "MAMA" "MIA") (specifications->manifest (list "hello"))
Then `guix shell -m this-file.scm` enters a shell session where "hello" exists and the env var MAMA is set to "MIA".
Any idea if nonguix will allow an install on macOS? I really want a system like this that I can use on my work MacBook and remote Linux servers.
There is already .envrc or .dir-locals.el? And manifest is just - well - manifest. By definition it has to be 'plain'. I mean, there are already a million ways to load env vars so why'd you want guix to do that too and from manifest.scm of all places?
To me, that's not ok from an user experience point of view.
This is either a misunderstanding or misrepresentation of the issue. We don't refuse to support Macs. Consider this:
- the value of Guix is in building up a package graph all the way from the very bottom (a tiny binary seed without parallel in other distros); this uses glibc. - glibc doesn't support Darwin - the only way to build software on a mac is to sign an EULA and use proprietary software (Xcode and the SDK).
It's easier to build software for Windows than for a Mac. If it was about "full hardcore FOSS" (what a weirdly judgmental term!) then we wouldn't support building for WSL or cross-compilation to mingw64, but we do.
Personally, I have no interest in working my ass off to get a subpar implementation of the package graph grafted on top of a huge binary blob (Xcode and the SDK) just to elevate a highly restrictive proprietary platform.
Until Apple commissions this kind of work it is still preferable to just use Guix in a virtualized GNU system.
This is the attitude I’m referring to when I say “hardcore FOSS”. You can choose to see it as a judgement if you want, but I view it as an implementation detail precluding my use of Guix.
“It’s hard and it’s not worth my time” is totally fine, I don’t expect projects to cater to my needs; but it’s worth calling out that it really seems like your chief complaint is that Apple is not FOSS (aka: proprietary).
I think the problem is that nix is just hard to learn. It's really different from most package managers, but people expect to look at a few examples and just pick it up intuitively. It's a whole different paradigm, with a custom programming language that also has a different paradigm. (Though Haskell folks eat it right up... no surprise there.)
It's gonna take time and effort to learn it, and there's just no way around it.
If it does, it's really well hidden. Because the nix manual certainly is not that.
> I think the problem is that nix is just hard to learn.
No, the problem is that nix offers no guidance or real help along that path. You go to https://nixos.org/learn.html and you've got essentially nothing helpful beyond the installation (which is easy enough). And it gets really bad when you get there from https://nixos.org/explore.html with no prior knowledge.
> Though Haskell folks eat it right up... no surprise there.
They're used to having to power through absent documentation?
> Archlinux is 78% reproducible on amd64 packages
> Debian is 95.7% reproducible on amd64 packages
This references the "fuzzing" infrastructure hosted by the Reproducible Builds project, and doesn't show "true" reproduction of binaries. It's designed to help us figure out where impurites occur in builds.
Proper package reproduction is much better in Arch because we don't have to care about all differences that can occur since our build systems are mostly static.
The true number hover around 86%-90%, which is better than the CI system.
https://reproducible.archlinux.org/
The main issues here is regressions in compilers, build tooling and leaky abstractions that needs to be found and patched. An example is how i spent a month tracking down a gcc bug that caused cgo builds to be unreproducible.
I think the "fuzzing" approach is actually the correct one. The fact that build systems are static does not improve reproducibility on its own, as the idea is that the packages could be built on different systems and result in the same binaries. If I built some Arch PKGBUILDs from the official community repo, I should still get the same binary, despite the fact that my machine has a different setup from the Arch project's own infra.
That's not the only way. It's definitely the easiest option, but you can also create a temporary fhs environment https://github.com/ElvishJerricco/nixpkgs/commit/05742c15d5a...
That kind of re-emphasizes to me that regardless of the value Nix might offer me, I'm not and probably won't ever be the audience for it, because if it assumes I know that well enough to recognize it by acronym then it's going to assume I know a lot more than that. I can look forward to a few months of Googling and tangents just to get a grip on its fundamentals.
More generally, it seems that the nix documentation (including the reference docs) suffer from not having been developed systematically to introduce things in dependency order.
1) Abysmal contributor experience
2) Lack of typing in nix language and very limited debugging capabilities
3) Lack of interface concept in nix language
4) Lack of any markings on dependency graph edge
5) (3) and (4) makes impossible to have anything alike to gentoo's slots. Nix might be the only right way of doing slotting but it's effectively incapable of that.
Scale of the repo and massive numbero of new PRs makes it easy for PRs to get lost and not reviewed, if you're having trouble with that you want to ask for help either on the PRs awaiting review thread on the nixos discourse or the matrix dev channel.
Nix flow: your patch is not done according to our guidelines, so fuck off. Still not. Still not. Read the guidelines. Still not, read the guidelines. You have to squash commits manually, we won't enable autosquashing because someone important doesn't like them. Nope, your time isn't valuable because there are too many of you and just one nix.
It's like they enjoy spending time to tell occasional contributors, who can't memorize all nix rituals, "fuck off" instead of spending that time to do the necessary finishing touches.
So, critical issues/vulnerabilities remain unpatched, some formulas are outdated by 5 years, because the relevant maintainer says the old package works for him but new one breaks something on his machine and offers to investigate his issue on your own by a single log line. Of course completely ignoring all _your_ issues which are fixed in an upstream patch made one year ago.
I know people who decided not to make a single contribution to nixpkgs until the things change because of that shitshow and I joined that movement. It's really easier to have a personal private fork of nixpkgs and make all the changes there instead of dealing with the upstream and that's what I would strongly recommend to any nix newcomer.
I agree that if the maintainers are compensated for their time, patches would be a lot more efficient in these scenarios to clean up the loose ends.
This ... seems entirely reasonable, though?
As you point out, having to do extra work on behalf of others isn't desirable.
-- If a pull request is made and the maintainer(s) don't like it, the options are "reject it", "maintainer puts in extra work to accept it", "pull request author puts in extra work to get it accepted".
With as many open PRs to nixpkgs as there are, it seems reasonable to ask that pull requests are as streamlined as possible.
That this isn't a great experience for new (or infrequent) contributors is unfortunate; although, "contributing" was raised as a pain point in the last community survey. https://discourse.nixos.org/t/2022-nix-survey-results/18983
> maintainer says the old package works for him
We’re all just volunteers, who are doing this in our free time. Usually this works well enough for most packages, but you are always free to submit the fix yourself on nixpkgs ;). At least compared to other distros, that workflow simpler.
And, I love NixOS. It's really special and very different than the other Linux I've used for 20 years.
I have been curious to try Guix at some point. Does anyone know if there is a good comparison write-up?
Also, can anyone speculate why the community has had such a hard time documenting this incredible technology? There are great posts like this from Xe: https://xeiaso.net/ but not generally getting started guides that are up to date. Why is this so hard to do? I mean, I'm not doing it because I personally feel like everything I do to get something working on Nix is a quasi-hack and not the standard and most up-to-date way to do it, so I'm hesitant to share. But, surely there are experts that like to write. Is this a problem with a simple technology solution (choose a better documentation tool)?
> it's intuitive
The naming is very odd (e.g. why "sets" for dicts / records), and then it manages to make the language incompatible with itself by having attribute sets for values and a completely different syntax for attribute set parameters, no doubt because the language was ambiguous due to the lack of function prefix (also makes curried functions awkward).
Like, there's nothing hard to it, but the entire language feels awkward for no reason. Like "?" meaning "default value" in parameters but "has attribute" for navigation (where "or" is "default value").
> I realize the nix language seems confusing to many, but to fp programmers, it's intuitive and there's not a whole lot to say about it.
XSLT is also a functional language. That doesn't make it not-awful.
It's not sets... It's attrsets, and the naming of the construct doesn't matter. I'm not sure I called them anything until I looked it up just now.
As for syntax... I'm not sure what you're referring to. Pattern syntax and construction syntax are different in every functional language I know.
> XSLT is also a functional language. That doesn't make it not-awful.
You're thinking of XQuery I think
Nix broadly borrows exactly everything from the lambda calculus, with no change in terminology. It introduces records, which is kind of necessary for any serious programming. It adopts standard conventions for records (curly braces and an equal sign). The only 'surprising' bit of syntax is the lambda construct, but this is such a minor thing it's almost silly to complain about it. I honestly don't understand what is surprising about the nix language.
Nixpkgs... sure I can see that, and I actually agree that types would be nice. Or at least interfaces. But the nix language as a whole is pretty straightforward.
Different people use nix for different things, perhaps a bit differently (e.g. whether they use flakes, home-manager, what channels do they follow). Each language has their own way of building packages, and different 'framework' in nix to build for them (usually about how to pull the dependencies in a reproducible way). And there are things that readers are expected to know such as basic shell scripts, paths, etc.
There is usually a nix way, but I don't wanna build a custom nix script every time I want to test something out.
However I found that using distrobox solves this problem for me quite well. It's a way to easily create and enter another distro from the terminal while it inherits everything else from the host.
So whenever I want to try a random python project I just do it there and don't care about making a mess, while my host system is clean.
I'm sure there are better ways to do these things, but I can't seem to find answers that don't seem to involve a lot of work.
https://nixos.org/manual/nixpkgs/stable/#sec-fhs-environment...
Where is a proper Flake documentation? Where is a proper $newNixFeatureInVogueNow?
The second pain point is: Nix might sound nice to read and write as a language for Haskellers, but most people actually aren't haskellers...
The third is essentially the fists, more specified: target. If the target is desktop, or server, or HPC, or development docs should be shaped per target. Actually NixOS is designed mostly with dev desktops and infra target, but docs are not even for new devs, more something added aside just because it's part of the duty provide them in some form...
That one actually exists in the right place. (Assuming you meant the flake file)
https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3...
That's why my third point is separated from the first: what's the target? The above example is what I see as a classic GNU/Linux nerdy/a bit navigated user path to NixOS for a personal usage as a desktop and for a home-lab-alike infra. For such target there is no good docs at all.
For some niche, like HPC for Guix, again there is nothing "targeted". Similarly for all NixOS use cases I can imaging.
That's why I conclude that docs was produced as a separate stuff "we need to have, not nice to made, not really useful" instead of the base to create newcomers paths to NixOS and also drive future design decisions because writing targeted docs in natural language is the best way to spot very high level logical design issues very hard to get up front discussing between devs and quickly produced code.
I think this is also a plus point, for Guix and Nix, how easy you can check the parent file dependencies, which are the same language as the configuration you're creating, and are easy to understand
The main disadvantage of doing this is that you lose the binary cache and will need to rebuild your system from scratch. This will eventually be solved (content-addressable packages), but that needs reproducibility guarantees that current compilers don’t provide.
Now I may be a total outlier here but it seems to me that while getting the fundamental concepts right is a good thing, having powerful means of combining them becomes more important in the long run.
Does that not speak in Guix' favour?
I'm loving it now though, I have 3 computers running it and a flake that I push to github. I can push changes to my flake and have all my systems reflect the changed with a quick nixos-rebuild. Also being able to roll back is invaluable.
I reformatted one of my systems the other day and it only took about an hour to have my whole system in the exact same state it was before with all my tooling and files.
Do you have resources you would recommend on that front?
Having to go to forums over and over and hope a kind stranger will take pity doesn't seem scalable.
With nix flakes, all the Nix sources you use must be checked into source control, and impurities like environment variables can't be used (by default).
A small example :
```
[remy@typhoon:~/Blog]$ cat flake.nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; };
outputs = { self, nixpkgs }:
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
{
devShell.x86_64-linux =
with pkgs;
pkgs.mkShell {
buildInputs = [
python3Packages.pelican
python3Packages.markdown
];
};
};
}[remy@typhoon:~/Blog]$ export HELLO="WORLD"
[remy@typhoon:~/Blog]$ nix develop
warning: Git tree '/home/remy/Blog' is dirty
[remy@typhoon:~/Blog]$ echo $HELLO
WORLD
```
And, because flakes are not stable, you need to enable them with e.g. `--experimental-features 'nix-command flakes'`. And by default, you can still access outside binaries, like let's say ls ! Which is why, to have real hermetic builds, in Guix for example, it's advised to run in containers and so on.
`nix build .#somePackage` is pure by default, as is `nix flake check`
I believe `nix shell` also inherits environment by default for the same reason. People expect to be able to run the packages they installed system wide after entering a shell.
In a `nix develop` shell? Ah, sure. -- I don't think the new nix commands have the same functionality that `nix-shell --pure` had.
But, in nix expressions used, in order to use environment variables (or to fetch from URLs without using a known sha256), the `--impure` flag needs to be passed.