7 ms·
> how painful was it to learn and get working? nixpkgs (which you can use on macOS or any Linux distro), quite little, you can get up to speed in 15min as a Ho
by lloeki 5y ago
> how painful was it to learn and get working?
nixpkgs (which you can use on macOS or any Linux distro), quite little, you can get up to speed in 15min as a Homebrew replacement:
nix-env -qas ruby # 'q'uery 'a'vailable 'search'
nix-env -I ruby. # install by package name (not recommended)
nix-env -iA nixpkgs.ruby_3_0 # install by "attribute", recommended
nix-env -q # 'q'uery (i.e list installed)
nix-env -e ruby # uninstall (like deleting a git ref)
nix-env -q
nix-collect-garbage # cleanup, like `git gc`
# etc...
And as a general purpose virtualenv/rvm/whatever replacement:
$ cat shell.nix
{
pkgs ? import <nixpkgs> {}, # you can have multiple of these with different names to have e.g a mix of stable and unstable
}:
let
openssl = pkgs.openssl; # just an example of how to set a var
in pkgs.mkShell {
buildInputs = [
openssl
pkgs.ruby_3_0 # or reference attires directly
];
}
$ nix-shell
(nix) $ ruby --version
ruby 3.0.1p64 (2021-04-05) [x86_64-darwin17]
(nix) $ openssl version
OpenSSL 1.1.1k 25 Mar 2021
(nix) $ exit
$ openssl version # back to the system one
LibreSSL 2.8.3
That way it's immediately useful and you can dig in deeper into the concepts as you go, if you want to.
NixOS, it's barely different, only generalised to the whole OS, but it's a bit tougher, because there's this abstraction via configuration that generates e.g systems files or other configurations that you'd operate with directly otherwise on a traditional distro. But the minute you screw things up, having the generation selector to pick and boot on straight in the boot loader you can see the absolutely unparalleled value of the proposition.
- rkangel 5y agoI use nix-shell for dev environments. Once I've got it working it's wonderful - full replicable, across multiple development machines and CI. It's painful though. Some problems I've encountered recently on different projects: Old version of fwup packaged. Can override to get newer version, but needed to add another dependency to make tests pass (and it gets built locally rather than being cached) Pain getting my environment to include the right Python packages so I can run the gigalixir command line tool. Have to workaround an oddity to do with how Erlang is packaged so that I don't get lots of warnings when anything is compiled: shellHook = '' export ERL_LIBS="" '';
- lpmay 5y agoJust a hint - extra attributes in the `mkShell` appear as environment variables in the built shell. So instead of a `shellHook` for this you can just have an attribute `ERL_LIBS="";` I'm not completely sure but I think this approach is preferred because shellHook only runs in `nix-shell` but if you ever wanted to `nix-build` a release it might not run.
- takeda 5y agoThere tools like direnv, that "enter" your env environment as soon as you cd to the directory. This is implemented by changing environment variables like PATH. Because shellHook allows on executing any code, there's no standardized way to undo what it executes, so those tools don't execute that part.
- bemeurer 5y agoPlease don't recommend that people use nix-env. It's one of Nix's biggest footguns and a huge support burden for the maintainers. We've been actively trying to remove mentions of it from the documentation. If you want something "installed" use home-manager. If you just want something for quick dev use nix-shell.
- mason55 5y agoI'm so glad this is the official line now. People giving examples using nix-env -I is, IMO, one of the major reasons it's so hard to get up and running. It's like... here are all the amazing reasons to do declarative config... and here's how you do everything using nix-env -I. Good luck figuring out how to translate it into a NixOS config so you can get all the benefits of declarative config that we just described!
- deleted 5y ago[deleted]
- pxc 5y ago> Good luck figuring out how to translate it into a NixOS config so you can get all the benefits of declarative config that we just described! Guix has a command that converts an imperative profile to a declarative one. Check out the `--export-manifest` option for `guix package`: https://guix.gnu.org/manual/en/guix.html#Invoking-guix-package https://guix.gnu.org/manual/en/guix.html#Invoking-guix-packa... Adding this to nix-env's replacement would be a sound approach imo. Maybe we could have one that also emits a little message for each package which is used in a NixOS module, directing users to a `programs.whatever` option instead of just dumping it in their `environment.systemPackages` list
- open-paren 5y agoIf nix-env is a big ol' footgun, are there any plans to make home-manager a part of the OS itself, instead of just a community project?
- pxc 5y ago