I am intrigued by the Nix language, because it is functional and because file paths are first class data types.
-
Is Nix language suitable for simple shell scripting, such as calling typical command-line utils and copying/moving files?
-
If yes, is there a way to install only the Nix language on MacOS? What I mean by this is, I don’t want to install Nix’s Multi-User Mode because it sounds like a hassle and intrusive to my computer (AFAIK it requires partitioning my SSD and creating several privileged user accounts).
I appears that in the past, there was a Nix Single-User Mode for MacOS. Has anyone found a way to make that previous install method work on MacOS 13.x?
I’m just working on personal development projects.
>Solution :
Is Nix language suitable for simple shell scripting, such as calling
typical command-line utils and copying/moving files?
It’s not really a general purpose language. And even writing ‘scripts’ in Nix, you would use a regular scripting language like bash. The Nix language is mostly focused on interacting with a nix store.
Nix always get executed in an indepedent/sandboxed enviornment, similar to the docker build environment. As such it won’t have access to your usual filesystem. And that is kind of the entire point of Nix.
However I think that is an implementation detail and technically I don’t think there is anything limiting Nix from running in the context of your native environment. This would have to be developed, which is not a small job.
However saying that you might still find nix useful for writing a shell script. You could write a nix expression that builds a nix package.
For example (just roughly, haven’t checked this):
example = (import (builtins.fetchGit {
url = "ssh://root@example.co.uk:/root/gitrepo/example";
rev = "abcxyz"
}) {});
pkgs.writeScript "example.sh"
''
#!${pkgs.stdenv.shell}
set -e
echo "hi"
cat ${example}/docs/example