3

I am trying to create a .nix file that installs nvm

First I tried to add inside configuration.nix :

system.activationScripts = {

  dotfiles = pkgs.lib.stringAfters [ "users" ]
    ''
    curl NVM_URL | bash
    ''
  }
}

But it complained bash and curl are not defined....

So I tried to create a small .nix package,

{ stdenv, fileurl };
stdenv.mkDerivation {
   name="nvm-0.33.0"
   builder = ./install.sh;
   fileurl{
      url: NVM_GIT_MASTER.zip;
   };
}

But then it complain `cannot auto-call a function that has an argument without a default valu {'stdenv'}

After running nix-build --dry-run ./text,nix

What's going on? I am reading nix pages, and banging my head on the wall.

Ant
  • 193
  • 1
  • 9

1 Answers1

2

I should think the not defined error is because neither curl nor bash are present in PATH when the system derivation is built. The manual entry for system.activationScripts says:

A set of shell script fragments that are executed when a NixOS system configuration is activated. Examples are updating /etc, creating accounts, and so on. Since these are executed every time you boot the system or run nixos-rebuild, it's important that they are idempotent and fast.

So I guess for that reason you should have the minimum amount of code in system.activationScripts anyway.

The cannot autocall error suggests that the package you wrote is being called without it's arguments supplied. The normal way to take care of this is to use the callPackage function in the pkgs.lib set. You can find examples of its use throughout nixpkgs.

I think you're not using nix the right way to solve whatever your objective is. It could be worth seeing if you can find existing config.nix that use node packages to see how that's done. Also I notice that there's already support for nodePackages in nix so perhaps that might help you. There's also the nixos channel on IRC that more helpful too.

Hope that helps!

brocking
  • 191
  • 2