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

flake is not a recognized command #315

Closed
codygman opened this issue Jun 12, 2021 · 20 comments · Fixed by #322
Closed

flake is not a recognized command #315

codygman opened this issue Jun 12, 2021 · 20 comments · Fixed by #322
Labels
bug Something isn't working upstream concerned with upstream

Comments

@codygman
Copy link
Contributor

codygman commented Jun 12, 2021

Expected Behavior

Successful build following documentation

Current Behavior

Following documentation today, I get this result:

✖2 ❯ nix-shell https://github.com/divnix/devos/archive/core.tar.gz -A shell   --run "flk get community"
fatal: not a git repository (or any of the parent directories): .git

~ took 6s 
❯ cd flk
direnv: error /home/cody/flk/.envrc is blocked. Run `direnv allow` to approve its content

~/flk 
❯ direnv allow
direnv: loading ~/flk/.envrc
direnv: using flake
error: 'print-dev-env' is not a recognised command
Try '/nix/store/rf97ba1qzrh07305n027jb91v3p1n4qi-nix-2.3.12/bin/nix --help' for more information.
error: 'flake' is not a recognised command
Try '/nix/store/rf97ba1qzrh07305n027jb91v3p1n4qi-nix-2.3.12/bin/nix --help' for more information.
direnv: renewed cache
direnv: export ~XDG_DATA_DIRS

Possible Solution

I think either I met something up on my end or there was a update to flakes it broke things.

Steps to Reproduce

The above should work for this.

Context

I was trying to update to the latest devos and thought it was maybe a peculiarity of my set up. So I tried just following the guide to rule that out, and it appears there's some other issue.

Your Environment

✖130 ❯ nix-shell -p nix-info --run "nix-info -m"

  • system: "x86_64-linux"
  • host os: Linux 5.12.9, NixOS, 21.11.20210610.432fc2d (Porcupine)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.4pre20210601_5985b8b
  • channels(cody): ""
  • nixpkgs: /nix/store/v13yb14bkddyc1rxlrna5j3441pyh0r8-source
@codygman codygman added the bug Something isn't working label Jun 12, 2021
@codygman
Copy link
Contributor Author

It looks like I can get around this by just calling nix-shell.

@jojosch
Copy link

jojosch commented Jun 12, 2021

I had the same issue yesterday after updating - resolved it by adding an overlay for nix-direnv which sets enableFlakes=true.

Thats because NixOS/nixpkgs#126137 disabled flake support in nix-direnv by default - and that change is present in your current version 432fc2d.

@codygman
Copy link
Contributor Author

In case anyone else needs it, this took a few minutes to remember:

diff --git a/overlays/direnv.nix b/overlays/direnv.nix
index ae697fb..753b756 100644
--- a/overlays/direnv.nix
+++ b/overlays/direnv.nix
@@ -1,5 +1,5 @@
 final: prev: {
-  direnv = prev.direnv.override {
+  nix-direnv = prev.nix-direnv.override {
     enableFlakes = true;
   };
 }

NOTE: Make sure you've added the overlay to git

@codygman
Copy link
Contributor Author

This is fixed for me in, but perhaps this should be the default?

@blaggacao
Copy link
Contributor

Thank you both for report and solution.

This is fixed for me in, but perhaps this should be the default?

It should, but unfortunately this would be harmful for older nixpkgs versions. I think there is no way around using builtins.functionArgs to peak the function and check for the availability of enableFlakes.

Does the override function expose the original package functions args?

Along those lines?

if ((builtins.functionArgs prev.nix-direnv.override) ? enableFlakes or null) != null then prev.nix-direnv.override { ... } else prev.nix-direnv

If you have an itch for a PR, please feel free to submit one to master. 😉

@andrevmatos
Copy link

The issue re-appeared for me after today's lock update, even with above fix.

@jojosch
Copy link

jojosch commented Jun 15, 2021

I did update now as well and can confirm that with the current workaround and an updated home-manger the error reappears. See nix-community/home-manager@e0f2949 for the change.

Now programs.direnv.enableNixDirenvIntegration = true; needs to be "replaced" with programs.direnv.nix-direnv.enable = true; and programs.direnv.nix-direnv.enableFlakes = true; when using home-manager after the above mentioned commit.

@blaggacao
Copy link
Contributor

I see. @Pacman99 Do we have "overlays" for home manager? I think the actual fix could be quite similar ...

@codygman
Copy link
Contributor Author

Could this error be related to the overlay issues fixed by #55?

@Pacman99
Copy link
Member

I see. @Pacman99 Do we have "overlays" for home manager?

I mean any nixpkgs overlay for the host's channel will be applied for the nixpkgs passed to home-manager since it just inherits from the host.
If your talking about the module option, we could do something like this in the direnv profile:

{ config, ... }:
{
  programs.direnv.nix-direnv.enable = config.programs.direnv.enableNixDirenvIntegration;
}

@blaggacao
Copy link
Contributor

I guess we need to conditionally enable
programs.direnv.nix-direnv.enableFlakes = true;  only for hm versions that have this option.

@codygman
Copy link
Contributor Author

This is still broken for me... I think. Maybe it's a separate problem but now I'm getting:

❯ bud rebuild tower switch
error: unrecognised flag '--extra-experimental-features'
Try 'nix --help' for more information.

hci  devos-develop 「↪ ✘ 𝚫 📁 」  ⎔ 
❯ nix --version
nix (Nix) 2.4pre20210601_5985b8b

@cawilliamson
Copy link

This is still broken for me... I think. Maybe it's a separate problem but now I'm getting:

❯ bud rebuild tower switch
error: unrecognised flag '--extra-experimental-features'
Try 'nix --help' for more information.

hci  devos-develop 「↪ ✘ 𝚫 📁 」  ⎔ 
❯ nix --version
nix (Nix) 2.4pre20210601_5985b8b

Did you ever find a fix for this? Stuck on the EXACT same problem right now! :(

@Pacman99
Copy link
Member

nix-direnv flakes support should be fixed, so I'm going to close this. The latest problem can be tracked in #406

@ParetoOptimalDev
Copy link

ParetoOptimalDev commented Mar 14, 2022

Using the example in divnix/digga as of 396b04b this error still happens:

❯ cd examples/devos/
direnv: loading ~/code/digga/examples/devos/.envrc
direnv: using flake
error: 'print-dev-env' is not a recognised command
Try '/nix/store/xpcka92iqchf7gn2w4mrqcjjkdxxaan3-nix-2.3.16/bin/nix --help' for more information.
error: 'flake' is not a recognised command
Try '/nix/store/xpcka92iqchf7gn2w4mrqcjjkdxxaan3-nix-2.3.16/bin/nix --help' for more information.
direnv: renewed cache
direnv: export ~XDG_DATA_DIRS

I thought maybe my personal flake was the issue, but it's the same as the one in the example/devos/flake.nix and my direnv is the same as example/devos/flake/users/profiles/direnv.

@ParetoOptimalDev
Copy link

Then after:

@@ -1,9 +1,9 @@
 {
   programs.direnv = {
     enable = true;
     nix-direnv = {
       enable = true;
+      enableFlakes = true;
     };
   };
 }

I get:

digga  main 
❯ bud
This script must be run either from the flake's devshell or its root path must be specified

It works fine after nix develop though.

@ParetoOptimalDev
Copy link

I notice that going back and forth between bud rebuild, opening a new shell, bud not working, and then doing nix develop I get these lockfile changes:

modified   flake.lock
@@ -624,7 +624,10 @@
     "nixos-generators": {
       "inputs": {
         "nixlib": "nixlib",
-        "nixpkgs": "nixpkgs_3"
+        "nixpkgs": [
+          "digga",
+          "blank"
+        ]
       },
       "locked": {
         "lastModified": 1637655461,
@@ -687,22 +690,6 @@
       }
     },
     "nixpkgs_3": {
-      "locked": {
-        "lastModified": 1646955661,
-        "narHash": "sha256-AYLta1PubJnrkv15+7G+6ErW5m9NcI9wSdJ+n7pKAe0=",
-        "owner": "NixOS",
-        "repo": "nixpkgs",
-        "rev": "e9545762b032559c27d8ec9141ed63ceca1aa1ac",
-        "type": "github"
-      },
-      "original": {
-        "owner": "NixOS",
-        "ref": "nixpkgs-unstable",
-        "repo": "nixpkgs",
-        "type": "github"
-      }
-    },
-    "nixpkgs_4": {
       "locked": {
         "lastModified": 1641016545,
         "narHash": "sha256-JMNwvnBzG0RjGG3eH27Y5/GlJ9ryeCdGJfqGbqxnmZY=",
@@ -773,7 +760,7 @@
     "pre-commit-hooks": {
       "inputs": {
         "flake-utils": "flake-utils_5",
-        "nixpkgs": "nixpkgs_4"
+        "nixpkgs": "nixpkgs_3"

Not sure if this matters, but seems weird.

@ParetoOptimalDev
Copy link

ParetoOptimalDev commented Mar 14, 2022

All of my issues were caused by a typo in:

- bud.localFlakeClone = "/home/nixoss/system";
+ bud.localFlakeClone = "/home/nixos/system";

@ParetoOptimalDev
Copy link

Apparently not, I use the system installed (from bud switch) bud version rather than direnv giving me the shell version.

I have to use nix develop to get the correct one.

Maybe my install somehow got in s bad state?

I'll create a VM from the Bud devos example and see if I can reproduce this issue later

@DrPyser
Copy link

DrPyser commented Apr 28, 2022

I'm also experiencing this issue. Maybe it's worth reopening?
It's unclear to me what should be the nix version used by the flake devShell, and how to explicitly configure it.
My system configuration uses nix 2.7

> readlink (which nix)
/nix/store/7gjn39gw0dli14vvwm7bqy99dljw3b2z-nix-2.7.0/bin/nix

. Why is that not the one used to start the flake environment from direnv?

Edit: All good now that I applied previously mentioned fix with direnv.nix-direnv.enableFlakes = true; in home-manager conf and it worked. Didn't understand how direnv+nix-direnv got its nix package...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream concerned with upstream
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants