1

This is the sequel of this question.

I've a bash list of command that generated a file nix directory when these commands are executed.

mkdir nix
rm -fr node_module
node2nix -16 --development --input package.json --lock package-lock.json --node-env ./nix/node-env.nix --composition ./nix/default.nix  --output ./nix/node-package.nix

I have flake.nix file that use nix to create an envirnoment.

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

 outputs = { self, nixpkgs, flake-utils, ... }:
   flake-utils.lib.eachDefaultSystem (system:
     let
       pkgs = import nixpkgs { inherit system; };
       #npm_pack = import (./nix );
       npm_pack = import ./nix { inherit pkgs ;};
       in with pkgs;{
        #devShell = mkShell { buildInputs = [ npm_pack.package ];};
        devShell = npm_pack.shell;
      });
}

It is executed with this command:

  nix develop --extra-experimental-features nix-command --extra-experimental-features flakes --ignore-environment

Is there a way to modify the flake.nix file to create the nix directory and then do the work it has to do with nix directory.

I know that I could ONE create bash file (see the in answer why I don't like it)

In order to create the flake.nix I thinking about using something like a sheelhook in the beginning.I need too to be sure that node and node2nix are installed. Therefore I need those line

 node2nix.url ="github:svanderburg/node2nix"; # in the input
 nodejs = pkgs.nodejs-16_x; #in the output
 
Peter Becich
  • 989
  • 3
  • 14
  • 30
  • Because `node2nix` goes out to the network to look up dependencies whose hashes aren't previously known, it can't be done in a pure, sandboxed derivation; this is why the normal practice is to check the files that process creates in to git and include them with your flake. – Charles Duffy Jan 12 '23 at 18:27

1 Answers1

0

running this script works

#/nix/store/4xw8n979xpivdc46a9ndcvyhwgif00hz-bash-5.1-p16/bin/bash
#nix-shell -p node2nix nodejs stdenv --pure
npm init -y
npm install  node-gyp-build
mkdir nix;
rm -fr node_modules ;
node2nix -16 --development --input package.json --lock package-lock.json --node-env ./nix/node-env.nix --composition ./nix/default.nix  --output ./nix/node-package.nix
nix develop --extra-experimental-features nix-command --extra-experimental-features flakes --ignore-environment

but it doesn't work if somebody has not the bash in the directory than my bash. Therefore I prefer a solution consisting of implementing a big flake.nix because I'm sure it works if nix is installed

and it need to files : the flake.nix and the script.sh

  • If you want nix-shell to set up an interpreter, you should get rid of the shebang pointing direct to bash and use a `#!/usr/bin/env nix-shell` OS shebang, such that nix-shell itself is responsible for reading the line below and using it to download (if necessary) and then run the interpreter for the rest of the script. – Charles Duffy Jan 12 '23 at 18:29