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: Multiline shebang not working #280033

Open
tobiasBora opened this issue Jan 10, 2024 · 4 comments · Fixed by #280092
Open

nix: Multiline shebang not working #280033

tobiasBora opened this issue Jan 10, 2024 · 4 comments · Fixed by #280092

Comments

@tobiasBora
Copy link
Contributor

Describe the bug

The documentation here https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html?highlight=shebang#shebang-interpreter mentions that one can create an executable file:

#!/usr/bin/env nix
#! nix shell nixpkgs#bash nixpkgs#hello nixpkgs#cowsay --command bash

hello | cowsay

and run it, but I get an error:

$ chmod +x test
$./test
error: './test' is not a recognised command
Try 'nix --help' for more information.

I found a solution using the -S option of env like:

#!/usr/bin/env -S nix shell nixpkgs#bash nixpkgs#hello nixpkgs#cowsay --command bash

hello | cowsay

This works, but I don't see how to run this way more complex stuff. For instance, the documentation mentions that we can run:

#!/usr/bin/env nix
//! ```cargo
//! [dependencies]
//! time = "0.1.25"
//! ```
/*
#!nix shell nixpkgs#rustc nixpkgs#rust-script nixpkgs#cargo --command rust-script
*/
fn main() {
    for argument in std::env::args().skip(1) {
        println!("{}", argument);
    };
    println!("{}", std::env::var("HOME").expect(""));
    println!("{}", time::now().rfc822z());
}
// vim: ft=rust

but I get the same error.

Steps To Reproduce

Steps to reproduce the behavior: just described in previous section.

Notify maintainers

Metadata

I'm running NixOs 2caf4ef

Add a 👍 reaction to issues you find important.

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/nix-shell-shebang-flakes-haskell/38064/4

@eclairevoyant
Copy link
Member

This only works with nix 2.19 and up.

@tobiasBora
Copy link
Contributor Author

Ok thanks, I tried to run the latest nix version via nix shell, but it was of course only in the current shell, while I guess nix-env nix would use the system nix. But I have 2 questions:

  1. would it be possible to mention the -S syntax in the doc that works for any version of nix?
  2. is the construction
//! ```cargo
//! [dependencies]
//! time = "0.1.25"
//! ```

documented somewhere?

@NasaGeek
Copy link
Contributor

Reopening since the nixVersions.stable update was reverted.

@NasaGeek NasaGeek reopened this Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants