Note that I am running NixOs
, not sure if my answer will valid for other (non-Linux) system.
Is there somewhere I can download the source files from so I don't have to copy them line-by-line?
You could browse nixpkgs, All source files are there.
Is there a way I can nix-build
it without having to modify anything global (eg pkgs/top-level/all-packages.nix)?
David Grayson give excellent answer already.
I would love to add some information.
nix-build
will looking for default.nix
on the current directory and the build result will symlink named result
on current working directory.
Another way to test if nix expression could build is nix-shell
which also looking for default.nix
or shell.nix
on current directory. If the build success you will get shell prompt with your packages avaliable.
Both nix-build
and nix-shell
have -I
argument that you can point to any nix
repository including remote one.
For example, if I use nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz -p hello
, nix
will download binary cache
if exists or build hello
using current master
branch expression and give me a shell which hello
is avaliable.
$ nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz -p hello
downloading ‘https://github.com/NixOS/nixpkgs/archive/master.tar.gz’... [12850/0 KiB, 1404.5 KiB/s]
unpacking ‘https://github.com/NixOS/nixpkgs/archive/master.tar.gz’...
these paths will be fetched (0.04 MiB download, 0.19 MiB unpacked):
/nix/store/s3vlmp0k8b07h0r81bn7lh24q2mqcai8-hello-2.10
fetching path ‘/nix/store/s3vlmp0k8b07h0r81bn7lh24q2mqcai8-hello-2.10’...
*** Downloading ‘https://cache.nixos.org/nar/1ax9cr6qqqqrb4pdm1mpqn7whm6alwp56dvsh5hpgs5g8rrpnjxd.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/s3vlmp0k8b07h0r81bn7lh24q2mqcai8-hello-2.10’...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 40364 100 40364 0 0 40364 0 0:00:01 0:00:01 --:--:-- 37099
[nix-shell:~]$ which hello
/nix/store/s3vlmp0k8b07h0r81bn7lh24q2mqcai8-hello-2.10/bin/hello
Where is pkgs/top-level/all-packages.nix?
There is NIX_PATH
enviroment variable. The nixpkgs
portion will point you to your current repository
$ echo $NIX_PATH
nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels
My all-packages.nix
is located at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/pkgs/top-level/all-packages.nix