Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comparison with nix shell? #1

Open
thedavidmeister opened this issue Jan 5, 2019 · 8 comments
Open

comparison with nix shell? #1

thedavidmeister opened this issue Jan 5, 2019 · 8 comments

Comments

@thedavidmeister
Copy link

looks cool

how does this compare with nix?

e.g. normally i would do:

nix-shell -p python3 --run python3
echo 'main = putStrLn "Magic Works."' > hello.hs
nix-shell -p haskell.compiler.ghc863 --run 'ghc -o hello hello.hs'

and then if i needed to cleanup later i can:

nix-collect-garbage
@pendashteh
Copy link
Owner

nix-shell seems to be a powerful tool. I'd say it covers almost everything magic does. However, magic has advatnages in specific cases that it is designed for.

Firstly, it's auto-cleanup. (using docker run --rm) One less command to memorise, to remember and to type. Big deal!

The other advatnage is guessing the package names. magic uses images from docker hub. I've found those on docker hub much easier to guess compared to nix repository. You can clearly see the difference in the 'haskell' example.

Also, searching for the name of a package seems to be easier for docker hub. For example, try finding 'r' in both.

Another advtange could be the range of available options. I'm assuming docker hub images are more diverse and up-to-date than nix. I could be wrong.
For example, there doesn't seem to be a nix package for behat. (I must say I haven't managed to get a magic behat thing working either, but at least there is hope :D)

Also, may I say magic is just more beautiful?!

@thedavidmeister
Copy link
Author

nix definitely does auto cleanup, and docker --rm doesn't clean up base images, nix-collect-garbage is more like the various docker prune commands

nix would be cleaner overall i'd say, if you do nix -p curl -p git then you get a shell with curl and git, docker has 2000 different curl options some of which include git, but then doing nix -p curl doesn't add any more overhead as it reuses the curl it already has, docker would need a new image for that

i dunno if docker images or nix packages are more beautiful or easier to guess, or how important that is... that's pretty subjective

i could argue that it is "beautiful" that packages are namespaced and nix is a full functional language with a REPL ;)

FYI though, -p has tab completion and nix-env has --query, and can search here https://nixos.org/nixos/packages.html#

i found a whole wiki article on getting R setup in nix, including the standard IDE, but didn't find it that easy to find R on docker 🤷‍♂️

behat is definitely not "no hope", several options:

  • use composer directly nix-shell -p php73Packages.composer
  • "nixify" an existing composer project automatically with composer2nix https://github.com/svanderburg/composer2nix
  • hit a tarball/url with builtin nix functionality
  • use magic one day, nix-shell -p docker -p magic --run magic behat :P

i haven't tried the docker approach with more "day to day" stuff like GUIs and long running processes

a fully validating/synching ETH node:

nix-shell -p parity --run "parity --no-warp"

firefox:

nix-shell -p firefox --run firefox

@pendashteh
Copy link
Owner

Good points.

Being able to get two or more packages in one shell, can be handy. Something that magic can't do as it's at the mercy of the image provider.

Examples of parity and firefox are also not possible with magic.

I tried nix-shell, it's handy. However, it doesn't seem to be an isolated shell; which is not what it's designed for. Whereas, a magic command only has access to the current directory. So, isolation can be an advtange, when it's desired.

In contrast, nix-shell has an advatnage when dealing with ports; like php -S localhost:8000. Something that you need to handle sperately when using docker.

In summary, nix-shell seems to be flexible and powerful. I am already thinking of a wrapper around nix-shell to do things that I couldn't easily do on top of docker. Something like a SQL query:

$ nixelect USING drush, sqlite RUN drush si --db-url=sqlite://.db THEN PURGE

@thedavidmeister
Copy link
Author

if you're looking for more isolation, try --pure or checkout nix-build or even nix-container for increasing levels of isolation :)

@pendashteh
Copy link
Owner

Here is a use-case in which nix-shell is not an option but magic works:

On a fresh OSX you can run native linux command without any extra software like brew:

$ magic bash wget

Same applies to Windows or any environment that runs docker.

@thedavidmeister
Copy link
Author

windows only supports docker on more expensive versions :(

nix-shell is on OSX also ;)

one thing... they're not mutually exclusive as nix can be run inside docker pretty easily

@pendashteh
Copy link
Owner

I'm actually playing with running nix in a docker (magic style): #3
Very powerful, much more predictable packages plus the ability to load more than one package. And that's before I even know about the nix concepts (which look very alien)

@thedavidmeister
Copy link
Author

@pendashteh awesome

i think some of the alien-ness comes from how minimal it is: https://learnxinyminutes.com/docs/nix/

you have to BYO mental models and abstractions to fill in the gaps of more word-y languages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants