3 ms·
I was afraid of Nix before I adopted it based on what I've read. Now that I've taken the leap, there is no going back. Other operating systems are crude dinosau
by colordrops 5y ago
I was afraid of Nix before I adopted it based on what I've read. Now that I've taken the leap, there is no going back. Other operating systems are crude dinosaurs in comparison. Once you get past the learning curve and the initial setup (which can be steep), your system will be far more stable and easy to maintain than anything out there. Declarative OS builds are the future, whether it's Nix or something else.
- pkulak 5y agoOkay, sorry to hijack, but I keep trying it, and keep getting stuck. Most recently, how do I install a Rust binary from Github? They have a releases page, or I can just do a cargo build. Either way, I would just drop the resulting binary in /usr/bin and it's done. With Nix... I'm totally stumped. Do I have to package it myself somehow?
- assbuttbuttass 5y agoYes, you will have to package it if it's not already in nixpkgs. The good news is once you learn how, it's basically trivial with crate2nix[0], which can autogenerate nix derivations from rust crates [0] https://github.com/kolloch/crate2nix https://github.com/kolloch/crate2nix
- lilyball 5y agoYou can also use naersk¹ if you want to avoid a two-step process. It's especially convenient when using nix flakes. ¹https://github.com/nix-community/naersk https://github.com/nix-community/naersk
- JamesSwift 5y agoIf you just want to take a precompiled binary and install it, you just have to write a derivation wrapper around the binary which will declare the expected hash and take care of e.g. unzipping and moving to $out/bin. Here is a more involved example of downloading a release and then extracting the binary from a .pkg file: https://gist.github.com/J-Swift/364a8b158bf0b603f6e784e454ca6e53 https://gist.github.com/J-Swift/364a8b158bf0b603f6e784e454ca... Here is a more simplified example: https://gist.github.com/mitchellh/c47e3333bb78f57836ba2aa8064ad993#file-hashicorp-generic-nix-L32-L47 https://gist.github.com/mitchellh/c47e3333bb78f57836ba2aa806... EDIT: to get the sha, unfortunately you have to perform some esoteric command line incantations: https://github.com/NixOS/nix/issues/1880#issuecomment-366615204 https://github.com/NixOS/nix/issues/1880#issuecomment-366615... and https://gist.github.com/boxofrox/d8a3080fbb03f84b7d7a31e102b35f09 https://gist.github.com/boxofrox/d8a3080fbb03f84b7d7a31e102b...
- codingkoi 5y agoOnce I discovered `lib.fakeSha256`, I just put that in the derivation, try to build it and then use the error message to find the correct hash to put into it. Probably not the fastest way to do it, but it's easier for me to remember.
- JamesSwift 5y agoyeah that seems way easier, thanks for the tip!
- chriswarbo 5y ago> Either way, I would just drop the resulting binary in /usr/bin and it's done. With Nix... I'm totally stumped. If you don't care about Nixpkgs conventions ("build phases", etc.) then you can use `runCommand` to run arbitrary bash code. It's a function which takes three arguments: a name for the output, a key/value mapping for the environment variables (plus a few some special names), and a string of bash code (usually written between ''two single quotes''). with import <nixpkgs> {}; runCommand "my-favourite-program" # A name for the output { # A key/value mapping of env vars myVar = "myValue"; # The 'buildInputs' name is special: for each element 'x', the directory '${x}/bin' # will be appended to the PATH env var buildInputs = [ jq gcc ]; } '' # This is a multi-line string containing arbitrary bash code. # The output path will be provided via the env var $out so we # just need to create a file or folder with that path mkdir -p "$out/bin" echo "$myVar" > "$out/bin/my-executable" chmod +x "$out/bin/my-executable" '' One complication is that (by default) the script will be run in a sandbox, with no network access. We should fetch anything it depends on up-front, using e.g. fetchurl, fetchGit, etc. Here's a more realistic example: with import <nixpkgs> {}; runCommand "foo" { release = fetchurl { url = "http://example.com/foo/foo-1.0.zip"; hash = "sha256-iqZDwWkQA9XMTICEMCt5xDlmfmiIwzpeE3HJLbgbDXs="; }; buildInputs = [ unzip ]; } '' unzip "$release" mkdir -p "$out/bin" mv foo-1.0/binary "$out/bin/foo" ''
- lijogdfljk 5y agoI actually hate Nix.. and i agree, i'm never going back. I use it on my desktop (Linux), my Macbooks, and i want it on my Windows machine (not that it's going to happen hah). The thing that Nix, for me, currently fails at is introspection. Every function is a black box and i have no clue what's in it. I have to go dig up files on github to see what it even accepts. It's as if everything is obtuse. A "simple" LSP/Type system would do wonders for understanding what the function is, what it does, and the inputs/outputs. .. also i have some difficulty understanding functional "mutation" patterns like how overloads are implemented. But i hope that'll make sense eventually. NOTE: i also think Flakes are absolutely necessary for Nix. Nix is way less valuable to me without Flakes.
- skoskie 5y agoGuess I know what I’m learning this weekend. Anyone have tutorials they want to share?
- mikepurvis 5y agoI'm about a year into Nix and consider myself a moderate in some areas but something of an expert (by necessity) in others. I think the ideal pattern is to attack it bottom-up and top-down at the same time. Bottom up, you want to learn the fundamentals of how the Nix language works, and how the basic primitives it offers can be used to build up package definitions, a package manager, and ultimately an entire OS. For this, the Nix Pills are invaluable: https://nixos.org/guides/nix-pills/ https://nixos.org/guides/nix-pills/ Top down, you need goals for some specific things you want to accomplish in the system. For me, this was automated packaging for hundreds of source repos internal to my company, but that's a bit of a crazy case— for a normal person, I'd expect this could be something like "I want to run a webserver with some static assets" or "I want to define and launch a container declaratively", or maybe "I want a reproducible environment to do Python development in, where the reproducibility isn't just tagged versions in a requirements/pyproject file, but also includes the full underlay of everything I'm depending on from the base system. Whatever the goal is here, you're inevitably going to find your way to override-related tasks, like "okay, I want to upgrade this package" or "I want to add patches to this package" or "I want to change the settings on one of my dependencies", and that's where the extraordinary power of Nix really starts to sink in, when you realise how much can be accomplished with so little, and you try to imagine what accomplishing that under a conventional apt- or dnf-type system would look like.