I would like to install a program on myself. Of course there is no /usr/local/bin/ folder on nixos. Where would I install the program on Nixos now?
Thanks
I would like to install a program on myself. Of course there is no /usr/local/bin/ folder on nixos. Where would I install the program on Nixos now?
Thanks
Generally you write a derivation for your program and then install it via the nix
package manager. If you have never written a derivation before there are many examples you can review while reading through the nixpkgs manual. If you get stuck with anything please feel free to post questions.
Thanks man, for programs i write a derivation. I understand that. But we’re dealing with something like that, for example:
sudo mv drush.phar /usr/local/bin/drush
where do I put this in nixos. To make it even more understandable, I try to set up the following:
Thx
Still write a derivation. There are a few simple derivation builders - check pkgs.writeScriptBin and pkgs.runCommand
Then, when your derivation is ready in a file, install it with nix-env -if ./file.nix
Or include to environment.systemPackages list in configuration.nix
I thought the recommendation was to add drush
per drupal
project and use it from there?
Have a look at wp-cli that’s packaged as a .phar: nixpkgs/default.nix at 5ffe9b81e0c875633ea210de765d63a5d71326de · NixOS/nixpkgs · GitHub
In case of wp-cli, writing a proper derivation allowed us to get command completion as well as set php parameters needed specifically by wp-cli.
@peterhoeg, still something simple as “mv” is expected here. The simplest thing I think is
drush.nix:
with import <nixpkgs> {};
runCommand "drush" {
src = fetchurl {
url = "https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar";
sha256 = "0kix7wgxr1mnx77ywcc1gw45rvs9kv273k8h005lf61g1a02mwy3";
};
buildInputs = [ php makeWrapper ];
} ''
mkdir -p $out/bin
cp $src $out/bin/drush
chmod +x $out/bin/drush
wrapProgram $out/bin/drush --prefix PATH : ${lib.makeBinPath [ php ]}
''
The wrapper (last line) is optional.
If it’s truly just one file (and similar to the /usr/local/bin
scenario), then how about mv file $HOME/bin
and be done with it?
Alternatively, the problem that OP is trying to fix (according to the drush-launcher repo):
> However, it is inconvenient to type vendor/bin/drush in order to execute Drush commands
You could also just use direnv
and add the following to the project .envrc
:
PATH_add ./vendor/bin
We do have it already?
Although it may not be up to date anymore.
@JosW That should probably be removed. At one point I thought about updating it, then I read upstream has the official recommendation to not package drush
but instead use composer
to include it with everydrupal
install, IIRC.
Whilst there’s plenty of good answers here already, I feel like the “hacky” answers are still missing, so I’ll expand on the recommendation given by @peterhoeg.
I have $HOME/.local/bin
in my PATH
variable, which I use whenever I want to just test a program I download from a Github release for example. The latest version of kind
comes to mind, which is outdated in nixpkgs. Taking the time to contribute an update back to nixpkgs is great, but sometimes I don’t have time to be updating and testing derivations, so I’ll just add the program in $HOME/.local/bin
.
Bear in mind that this approach will only work for a statically compiled program or otherwise programs that with the given interpreter can be executed with dependencies that it can find in your system. In the case of drush
, I see the release is a .phar
file, which as far as I understand is an archive file which should contain all the dependencies for the php
program already, and according to Wikipedia, all you need is php
. Looking at drush.phar
, it already has a shebang that uses the env
trampoline to execute with php
.
Seems to me like just downloading the release into a directory that is in your PATH
and making it executable should be enough, provided you already have php
installed (I tested this and works okay, seemingly).
Of course later if you have the time, writing the derivation and committing it upstream to nixpkgs benefits everyone Best of luck!