[HN Gopher] About using Nix in my development workflow
___________________________________________________________________
About using Nix in my development workflow
Author : Arubis
Score : 60 points
Date : 2022-07-20 17:42 UTC (5 hours ago)
(HTM) web link (ejpcmac.net)
(TXT) w3m dump (ejpcmac.net)
| lijogdfljk wrote:
| As an aisde, i love Nix, but i hate the lack of types. It's such
| a chore to figure out what fields are on a value, is the value a
| func, what are the docs for that func, etc.
|
| I have high hopes for Nickel[1]
|
| [1]: https://www.tweag.io/blog/2022-03-11-nickel-first-release/
| servilio wrote:
| It DOES have types, doesn't have type declarations, though.
| remexre wrote:
| It doesn't have useful types for a lot of low-level
| abstractions; take, for example, all the stuff hanging off of
| stdenv -- if I'm trying to get nixpkgs up and running for a
| new C compiler that's neither GCC nor Clang, for example,
| it'd be really nice to know what all attributes need to be
| set for that. Instead, this ends up being a multi-day
| exploration through the nixpkgs source, where it turns out
| that (undocumentedly) the compiler must be named either gcc
| or clang...
| arrow7000 wrote:
| So like JavaScript
| flurie wrote:
| I know Eelco hasn't been heavily involved in Nickel, but I have
| to wonder what his departure from Tweag[1] means for it. A lot
| of bleeding-edge Nix adherents are starting to adopt CUE[2][3].
|
| [1] https://discourse.nixos.org/t/tweag-nix-dev-update-33/20048
|
| [2] https://cuelang.org/
|
| [3] https://github.com/input-output-hk/bitte
| Cedricgc wrote:
| Interested in hearing more about CUE+Nix
|
| Considering the tight integration between Nix language v.
| Nixpkgs v. Nix program I mostly see CUE usable to generate
| data files but would eventually need to be consumed in a .nix
| config at some point
| mschwaig wrote:
| Theoretically languages other than Nix can be used to
| generate derivations and from that point forward to the
| finished build result everything should work the same way.
|
| There is already some experimental setup for Nix to call
| Nickel for producing derivations using a function call
| importFromNcl. A more language-agnostic FDI (foreign
| derivation interface?) would be really exciting.
|
| When writing Nix code it can often feel quite opaque what's
| going wrong, so writing actual package descriptions in a
| more constrained language like CUE, at least to me, feels
| like it might help. Better tooling in Nix and the kind of
| validation that Nickel proposes also look like good bets.
| I'm glad there is more than one horse in the race to
| improve the ecosystem.
|
| I have been wondering for some time what would be required
| to define a package set just like nixpkgs in CUE (since
| it's not lazy and not touring complete). I only have very
| vague thoughts on that, so I would love reading about it
| from someone who knows more about how nixpkgs works or
| someone actually trying it.
| flurie wrote:
| You're basically right. I'm not 100% sold on this idea, but
| I think it's a possibility. Most of what I'm seeing right
| now is CUE facing outward, e.g., to generate typed things
| from within nix. This[1] is a good example of that. Given
| how flexible CUE is, and given how similar nix is to HCL, I
| think it's possible to have CUE emit nix and provide some
| basic typing that way.
|
| [1] https://github.com/jmgilman/nix-cue
| flurie wrote:
| The big thing this is going to miss between 2018 and now is that
| flakes have greatly increased presence.
|
| The small things are:
|
| - nix-direnv[1] is much more powerful and stable, with or without
| flakes
|
| - devshell[2] exists and is reasonably mature for those who want
| to give this to a team without teaching them (most) nix
|
| Still, apart from those, this is still a good intro.
|
| [1] https://github.com/nix-community/nix-direnv
|
| [2] https://github.com/numtide/devshell
| zamalek wrote:
| Using these with home-manager is also really simple. You simply
| enable nix-direnv[0], and then `use flake` in your envrc[1].
| Finally, set up your flake.nix with a dev shell[2] (I'm
| definitely going to take a look at numtide's devshell).
|
| You'll also need flakes and the nix command enabled first [3]
| (add that line to `/etc/nix/nix.conf` if you aren't using
| nixos).
|
| Why use flakes? Mostly because it has a lockfile: there's a
| really good chance that "works on my machine" is "works on my
| team's machines." Flakes are also much cleaner than vanilla
| Nix.
|
| [0]:
| https://gitlab.com/jcdickinson/nix/-/blob/main/home/general....
| [1]: https://gitlab.com/jcdickinson/nix/-/blob/main/.envrc#L3
| [2]:
| https://gitlab.com/jcdickinson/nix/-/blob/main/flake.nix#L65
| [3]:
| https://gitlab.com/jcdickinson/nix/-/blob/70844981d5cd63c839...
| JamesSwift wrote:
| Yeah, I checked the date after seeing a lack of flakes and sure
| enough: 2018.
|
| If you are new to nix I 100% recommend starting with flakes. It
| simplifies so much for a newbie, e.g. no management of NIX_PATH
| and simple upgrades (`sudo nix upgrade-nix`). It also enables
| essentially single-line machine bootstrap on a new box even if
| you use home-manager.
| flurie wrote:
| Do you know of any basic nix tutorials that skip the non-
| flake world? I'm not sure that they exist, but I think they
| could be really helpful. A lot of confusion when adopting
| flakes seems to come from the fact that the terrible UX of
| the old nix commands doesn't map cleanly to the (not perfect
| but visibly improved) new commands.
|
| Why learn this... nix-env -iA nixpkgs.hello
|
| ...when you can learn this instead? nix
| profile install nixpkgs#hello
| JamesSwift wrote:
| I have no idea, I have been with nix for long enough that I
| hadn't sought anything like that out. I should note that
| flakes are still technically experimental (i.e. opt-in),
| and theres still some community drama around not wanting to
| go with flakes mainly by longtime nix users.
|
| Also note that the "modernized" `nix` CLI interface is
| experimental/opt-in as well vs the out-of-the-box "legacy"
| commands (e.g. nix-env). So yeah, its a bit of an odd time
| in nix land as they transition but I don't see any
| indication that you would be poorly served or burned by
| moving to both nix command and flakes now.
| SkyMarshal wrote:
| For anyone interested in learning Nix Flakes:
|
| https://www.reddit.com/r/NixOS/comments/v2xpjm/big_list_of_f.
| ..
| transfire wrote:
| Oh, how I miss Gobo.
| galaxyLogic wrote:
| Does it work on Windows?
| pxc wrote:
| There's a community port of NixOS to WSL2, complete with
| systemd support, plus Docker Desktop support and some other
| goodies: https://github.com/nix-community/NixOS-WSL
|
| Nix also works on other WSL distros, provided they're using
| WSL2.
|
| Nix supports cross-compiling Windows binaries as well. I know
| some people use it for that.
|
| There is no 'native' support-- you can't use Nix as an
| alternative to Winget or Chocolatey on Windows. Right now a lot
| of important stuff in Nixpkgs depends on a POSIX shell and Unix
| coreutils implementation for the basic build environment, and
| that's shared between many operating systems. Trying to fit
| Windows into that doesn't really make sense, and there's not
| really any momentum behind the idea of using any particular
| other runtime environment (could be a scripting language
| instead of a shell + coreutils) for those basic builders.
|
| But it's conceivable that some day, one or more companies using
| Nix on WSL might see vaiue in taking that extra step and put
| together a Nix-based package collection for Windows and help
| get the Nix Windows port out the door. It also seems possible
| that a motivated Nix developer could take it somewhere on their
| own, since at least one has a workable PoC IIRC (but they
| didn't want to create/maintain a separate package collection).
|
| For now, it works very well with WSL2 and that's the way to go
| for Windows users.
| chriswarbo wrote:
| It works under WSL. I seem to remember some other experiments
| years ago (maybe cygwin/mingw based?)
| breakds wrote:
| We use NixOS and Nix extensively in the company. A few
| developers actually use NixOS on WSL as daily driver, and it
| was pretty smooth.
| Arubis wrote:
| I've _tried_ going down this route a couple times, with mixed
| success. Thus far the best experience has been with
| [lorelei](https://github.com/shajra/direnv-nix-lorelei), which
| does a decent job making Nix and Direnv play nice and being
| relatively transparent and forgettable once set up.
|
| Still feels like I don't know what's going on under Nix's hood,
| though. That syntax...
| flurie wrote:
| nix-direnv[1] is pretty seamless and performant once you have
| direnv installed and set up. I have a devshell flake template
| that looks similar to theirs. I had an edge case bug that I was
| dealing with, and they had a release that fixed it shortly
| after I reported it.
|
| [1] https://github.com/nix-community/nix-direnv#flakes-support
| lijogdfljk wrote:
| Some of that functionality is built into Nix/Flakes now.. i
| believe. Ie i used to use Lorelei but these days i just use Nix
| and Flakes with Direnv directly. Not sure even how it works,
| but it works great.
|
| But i use Flakes through my entire setup, so i imagine that's
| why.
| GoOnThenDoTell wrote:
| Is there a good book that explains Nix, from theory to real world
| dev usage?
| tmountain wrote:
| I've been out of the loop with Nix for a little while now, but
| I was maintaining roughly a half dozen packages for a little
| while (including semi-complex u-boot stuff), and I learned
| everything I needed to know from this tutorial.
|
| https://nixos.org/guides/nix-pills/
| breakds wrote:
| I would second this. Learning nix takes time and practice,
| but is very rewarding. Reading the nix pills series is
| definitely the most helpful first step. I would also
| recommend https://discourse.nixos.org/ where kind fellow Nix
| users constantly answer questions and give advice.
| SkyMarshal wrote:
| Eelco Dolstra's original PhD Thesis that started it all is
| worth a read:
|
| https://edolstra.github.io/pubs/phd-thesis.pdf
|
| https://philandstuff.github.io/pf-deployment/#/
| qbasic_forever wrote:
| I've gotten into it recently by skimming the docs, then diving
| in and using flakes. All of this from a multi-user/single user
| install on linux, I'm not ready to jump into managing the full
| OS yet.
|
| But IMHO I would try to take a flake centric approach because
| there's a _ton_ of cruft in the docs about stuff like channels
| that all gets completely jettisoned and dropped once flakes are
| the norm. It's just a lot of concepts and CLI commands, flags,
| rituals, etc. in the docs that will give you nothing of value
| in a flakes world. Unfortunately there are no real docs that
| make this clear that the nix world is deep into a major
| transition and flakes are the clear future.
|
| This 1 page intro to the nix language was all I needed to get
| comfortable with it too: https://github.com/tazjin/nix-1p It's
| really a pretty simple data-oriented language when you get down
| to it.
| JamesSwift wrote:
| > It's really a pretty simple data-oriented language when you
| get down to it
|
| Yes, if you think of nix-the-language as a bunch of helpers
| that creates a big key-value JSON object then you will start
| to get a better mental model.
| massysett wrote:
| This is what scares me off from Nix every single time. Even
| the biggest Nix fans keep saying that the docs are terrible.
| When I do try Nix people say "oh don't do it that way, even
| though that's what the docs say, now the way to do it is this
| new way." I can never imagine how Nix is going to help me
| enough to make it worthwhile to endure this hazing.
| qbasic_forever wrote:
| It's aggravating and kept me away from it for a while too.
| Try out small isolated parts of it like nix-shell and the
| flakes version of it nix develop. You can play with that
| stuff without having to dive in and commit moving all your
| existing home and other environments to it. Basically just
| get a little sandbox going to experiment with until you're
| more confident in doing more with it (or you might find you
| don't need it and didn't waste much effort/time).
| cglong wrote:
| (2018)
___________________________________________________________________
(page generated 2022-07-20 23:01 UTC)