nix-community / nix-init

Generate Nix packages from URLs with hash prefetching, dependency inference, license detection, and more [maintainer=@figsoda]
https://discourse.nixos.org/t/25035
Mozilla Public License 2.0
883 stars 19 forks source link

nixpkgs not found #415

Closed tcurdt closed 7 months ago

tcurdt commented 7 months ago

I am trying to generate a first nix config from a go project.

What's the problem?

# nix run github:nix-community/nix-init -- -u https://github.com/tcurdt/release-go
Enter tag or revision (defaults to v1.0.3)
❯ v1.0.3
Enter version
❯ 1.0.3
Enter pname
❯ release-go
Error: command exited with exit status: 1
stdout:

stderr:
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring
error:
       … while calling the 'import' builtin

         at «string»:1:43:

            1| let pname="release-go";version="1.0.3";in(import(<nixpkgs>){}).fetchFromGitHub {
             |                                           ^
            2|     owner = "tcurdt";

       … while calling the 'findFile' builtin

         at «string»:1:50:

            1| let pname="release-go";version="1.0.3";in(import(<nixpkgs>){}).fetchFromGitHub {
             |                                                  ^
            2|     owner = "tcurdt";

       error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)
viperML commented 7 months ago

What is the output of the following commands?

printenv NIX_PATH
nix-instantiate --eval --expr '<nixpkgs>'
tcurdt commented 7 months ago
# printenv NIX_PATH
/root/.nix-defexpr/channels:nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels

# nix-instantiate --eval --expr '<nixpkgs>'
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring
error:
       … while calling the 'findFile' builtin

         at «string»:1:1:

            1| <nixpkgs>
             | ^

       error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

Looking at this, it feels more like a newbie (me) getting stuck in between channels and flakes rather than a nix-init problem.

viperML commented 7 months ago

Why do you think that's the problem? Did you remove any channels?

EDIT: Also why running the commands as root (#) ?

tcurdt commented 7 months ago

Why do you think that's the problem? Did you remove any channels?

My channels were empty at some stage. The system is setup via flake. But I re-added unstable to give it a try.

nix-channel --list
unstable https://nixos.org/channels/nixpkgs-unstable
# nix-channel --update

But that didn't help

EDIT: Also why running the commands as root (#) ?

No particular reason. It's just a throw-away vm for now.

But I am getting the same error as user

[tcurdt@nixos:~]$ nix-instantiate --eval --expr '<nixpkgs>'
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring
error:
       … while calling the 'findFile' builtin

         at «string»:1:1:

            1| <nixpkgs>
             | ^

       error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

TBH I don't understand the per-user/root when I am user tcurdt

viperML commented 7 months ago

Root's channels are propagated to regular users

tcurdt commented 7 months ago

This helped

$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
$ nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --update nixpkgs
$  nix-instantiate --eval --expr '<nixpkgs>'
/root/.nix-defexpr/channels/nixpkgs

Can't say I understand the problem/fix yet, but I now have a default.nix 🥳

{ lib
, buildGoModule
, fetchFromGitHub
}:

buildGoModule rec {
  pname = "release-go";
  version = "1.0.3";

  src = fetchFromGitHub {
    owner = "tcurdt";
    repo = "release-go";
    rev = "v${version}";
    hash = "sha256-Ai4uvLkl4e4Z6x1wZb5BzpLvWhxHhg4D1QpCdSjwQ5I=";
  };

  vendorHash = null;

  ldflags = [
    "-s"
    "-w"
    "-X=main.version=${version}"
    "-X=main.commit=${src.rev}"
    "-X=main.date=1970-01-01T00:00:00Z"
    "-X=main.treeState=false"
    "-X=main.builtBy=goreleaser"
  ];

  meta = with lib; {
    description = "";
    homepage = "https://github.com/tcurdt/release-go";
    license = licenses.unfree; # FIXME: nix-init did not find a license
    maintainers = with maintainers; [ ];
    mainProgram = "release-go";
  };
}
nixos-discourse commented 7 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/making-packages-projects-available-to-nixos/38462/4

viperML commented 7 months ago

Should the issue be closed?

tcurdt commented 7 months ago

I am still stuck actually getting the build to work - but that's probably another more unrelated matter. Let's close it.