Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated flake.nix for a go project doesn't work: error: undefined variable 'go_1_20' #130

Open
matta opened this issue Jul 28, 2024 · 2 comments

Comments

@matta
Copy link

matta commented Jul 28, 2024

I am following zero-to-nix and tried running fh in a simple go project. The generated flake doesn't work. I am a complete newbie, so I'm not sure how to debug the problem.

The generated flake.nix and flake.lock are:

# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.10)
{
  # A helpful description of your flake
  description = "rfc20.org website";

  # Flake inputs
  inputs = {
    flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*.tar.gz";

    nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz";
  };

  # Flake outputs that other flakes can use
  outputs = { self, flake-schemas, nixpkgs }:
    let
      # Helpers for producing system-specific outputs
      supportedSystems = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" "aarch64-linux" ];
      forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
        pkgs = import nixpkgs { inherit system; };
      });
    in {
      # Schemas tell Nix about the structure of your flake's outputs
      schemas = flake-schemas.schemas;

      # Development environments
      devShells = forEachSupportedSystem ({ pkgs }: {
        default = pkgs.mkShell {
          # Pinned packages available in the environment
          packages = with pkgs; [
            go_1_20
            nixpkgs-fmt
          ];
        };
      });
    };
}
{
  "nodes": {
    "flake-schemas": {
      "locked": {
        "lastModified": 1721999734,
        "narHash": "sha256-G5CxYeJVm4lcEtaO87LKzOsVnWeTcHGKbKxNamNWgOw=",
        "rev": "0a5c42297d870156d9c57d8f99e476b738dcd982",
        "revCount": 75,
        "type": "tarball",
        "url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.5/0190ef2f-61e0-794b-ba14-e82f225e55e6/source.tar.gz"
      },
      "original": {
        "type": "tarball",
        "url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A.tar.gz"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1722087241,
        "narHash": "sha256-2ShmEaFi0kJVOEEu5gmlykN5dwjWYWYUJmlRTvZQRpU=",
        "rev": "8c50662509100d53229d4be607f1a3a31157fa12",
        "revCount": 633516,
        "type": "tarball",
        "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2405.633516%2Brev-8c50662509100d53229d4be607f1a3a31157fa12/0190f691-c019-7d99-b723-4b2dd6dfd38f/source.tar.gz"
      },
      "original": {
        "type": "tarball",
        "url": "https://flakehub.com/f/NixOS/nixpkgs/%2A.tar.gz"
      }
    },
    "root": {
      "inputs": {
        "flake-schemas": "flake-schemas",
        "nixpkgs": "nixpkgs"
      }
    }
  },
  "root": "root",
  "version": 7
}

The output of 'nix develop' is:

% nix develop
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:9:12:
            8|
            9|   strict = derivationStrict drvAttrs;
             |            ^
           10|

       … while evaluating derivation 'nix-shell'
         whose name attribute is located at /nix/store/d6533m6b80n3c9lia5kvaz59ad3fynwk-source/pkgs/stdenv/generic/make-derivation.nix:333:7

       … while evaluating attribute 'nativeBuildInputs' of derivation 'nix-shell'
         at /nix/store/d6533m6b80n3c9lia5kvaz59ad3fynwk-source/pkgs/stdenv/generic/make-derivation.nix:377:7:
          376|       depsBuildBuild              = elemAt (elemAt dependencies 0) 0;
          377|       nativeBuildInputs           = elemAt (elemAt dependencies 0) 1;
             |       ^
          378|       depsBuildTarget             = elemAt (elemAt dependencies 0) 2;

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: undefined variable 'go_1_20'
       at /nix/store/n6zxrknnddqz7hk4z8mijbzia23i43bc-source/flake.nix:30:13:
           29|           packages = with pkgs; [
           30|             go_1_20
             |             ^
           31|             nixpkgs-fmt
matta added a commit to matta/rfc20 that referenced this issue Jul 28, 2024
I ran:

   nix run "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz#fh" -- init

...answered a few questions, and generated a broken config.

See DeterminateSystems/fh#130
@matta
Copy link
Author

matta commented Jul 28, 2024

I suppose the cool thing about flakes is that the repro is now available at:

nix develop "github:matta/rfc20?rev=7e841a805579a41d2677667cb2b76b05e2f554d5"

@cole-h
Copy link
Member

cole-h commented Jul 29, 2024

You could try replacing go_1_20 with go_1_21, go_1_22, or go_1_23. go_1_20 was removed because it is EOL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants