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

nix-env-selector does not work with flakes #87

Open
samuela opened this issue Jan 6, 2024 · 8 comments
Open

nix-env-selector does not work with flakes #87

samuela opened this issue Jan 6, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@samuela
Copy link
Contributor

samuela commented Jan 6, 2024

Describe the bug
This bug manifests with similar symptoms as in #56... specifically stuck in the "Applying environment..." state, but AFAICT has a different root cause and I am therefore opening a separate issue.

When selecting a flake.nix from the nix-env-selector drop-down, the error

[Extension Host] Error: Command failed: nix-shell "/home/skainswo/dev/sshenanigans/flake.nix" --run export
error: nix-shell requires a single derivation
Try 'nix-shell --help' for more information.

    at ChildProcess.exithandler (node:child_process:420:12)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1091:16)
    at Socket.<anonymous> (node:internal/child_process:449:11)
    at Socket.emit (node:events:513:28)
    at Pipe.<anonymous> (node:net:322:12)

is shown in the developer console, and the tray icon stays in the "Applying environment..." spinner forever.

To Reproduce
Steps to reproduce the behavior:

  1. Go to a project with a flake. For example, I am currently attempting to use nix-env-selector with https://github.com/samuela/sshenanigans.
  2. Run Nix-Env: Select environment... and select flake.nix from the drop down.
  3. Observe the error and infinity spinner......

Expected behavior
The environment equivalent to nix develop to be applied.

Screenshots
n/a

Environment:

  • OS: macOS 14.1.1, running over SSH on a NixOS 23.05
  • VS Code: Version: 1.85.1 (Universal), Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
  • Version: v1.0.10

Additional context
n/a

@samuela samuela added the bug Something isn't working label Jan 6, 2024
@nyabinary
Copy link

Same here

@MichelleGranat
Copy link

Any progress?

@nyabinary
Copy link

Any progress?

Use direnv vscode extension instead :3 works for me

@acelinkio
Copy link

Would greatly appreciate if this project could be extended to support flakes as well. Flakes have done a great job at increasing Nix's accessibility!

Would like to avoid adding another tool to the mix to setup vscode.

@scaxyz
Copy link

scaxyz commented Apr 26, 2024

What works for me:
I either keep a my old shell.nix file around and use devShells.default = import ./shell.nix { inherit pkgs; }; in the flake.nix file.

Or I create a shell.nix file with (builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default as content.

And then just use the shell.nix as normal with the vscode extention.
(Credits: https://discourse.nixos.org/t/how-to-fetch-flake-in-shell-nix/39587/2 and https://github.com/SlimeVR/SlimeVR-Server/blob/d9955d10e3f055491cea4d6a7e7edef0788235f2/shell.nix#L2)

@OlivierLDff
Copy link

My approach has been to use flake-compat

shell.nix:

(import
  (
    let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
    fetchTarball {
      url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
      sha256 = lock.nodes.flake-compat.locked.narHash;
    }
  )
  { src = ./.; }
).shellNix

@HendrikHuebner
Copy link

HendrikHuebner commented Jun 3, 2024

Any progress?

Use direnv vscode extension instead :3 works for me

@nyabinary
Can you explain how to use it? I've tried creating an envrc with just "nix develop" inside. This has been kind of buggy. WHen I try to hook it to my shell it evaluates the flake and drops me into the devshell, but then it throws an error saying its taking too long. Once I press Ctrl+C it continues to work. I think the problem is that it basically waits for "nix develop" to finish, meaning for me to exit the shell. Could you post your envrc?

@OlivierLDff
Copy link

OlivierLDff commented Aug 13, 2024

I gave a shot at the direnv extension, works perfectly.

@HendrikHuebner here is how I managed.

Content of .envrc (taken from here

#!/bin/sh

#If already set (e.g. in github actions); use that instead
if [ -z "$GITHUB_TOKEN" ]; then
  nix run nixpkgs#gh auth status || nix run nixpkgs#gh auth login
  GITHUB_TOKEN="$(nix run nixpkgs#gh auth token)"
  export GITHUB_TOKEN
fi

NIX_CONFIG="access-tokens = github.com=$GITHUB_TOKEN"
export NIX_CONFIG
use flake

Because my flake use private repo.

If you have a basic flake, you can simply use .envrc:

use flake

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

No branches or pull requests

8 participants