-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Shebang flakes v2 #8327
Shebang flakes v2 #8327
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a superficial perspective of a potential user and manual reader, I mainly have two questions:
- Why is that "weird" escaping needed? If it's technically unavoidable it sure needs the reason documented. Otherwise it appears arbitrary and cumbersome.
- Why is it
nix shell
? What does that have to do with shells at all?
I understand that historically stuff was just tacked onto nix-shell
being a kitchen sink, but this is a different situation. Could we do something like #! nix shebang ... --interpreter <command>
which could be shortened with -i
?
Or even #! nix interpret <command> ...
where the command is positional?
* The experimental nix command is now a `#!-interpreter` by appending the | ||
contents of any `#! nix` lines and the script's location to a single call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* The experimental nix command is now a `#!-interpreter` by appending the | |
contents of any `#! nix` lines and the script's location to a single call. | |
* The experimental `nix` command is now a `#!-interpreter` by concatenating the | |
contents of any `#! nix` lines and the script's location into a single call to ???. |
Is that what you mean? What gets called? This isn't clear.
> You must use double backticks (```` `` ````) when passing a simple Nix expression | ||
> in a nix shell shebang. | ||
|
||
Finally, using the merging of multiple nix shell shebangs the following |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this merging something? I don't understand how it relates to the example. It looks exactly like the other ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple lines of "#!nix" are concatenated after that prefix is removed. This allows breaking up a long line into multiple lines.
import Network.Curl.Download | ||
import Text.HTML.TagSoup | ||
import Data.Either | ||
import Data.ByteString.Char8 (unpack) | ||
|
||
-- Fetch nixos.org and print all hrefs. | ||
main = do | ||
resp <- openURI "https://nixos.org/" | ||
let tags = filter (isTagOpenName "a") $ parseTags $ unpack $ fromRight undefined resp | ||
let tags' = map (fromAttrib "href") tags | ||
mapM_ putStrLn $ filter (/= "") tags' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's pretty much arbitrary stuff just to show the shebang mechanism. The actual scripts should aim to be one liners. Everything else will be noise to 90% of the readers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
history: I tried to copy the previous examples and modify as little as possible. I am not opposed to a simpler script if that would communicate the concept better.
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-05-26-nix-team-meeting-minutes-58/28572/1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining items are release notes and docs updates from @fricklerhandwerk
I started trying to incorporate the suggestions. (hercules-ci@5d33afe) |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nix3-equivilents-to-nix-shell-i-python-p-hello/34417/2 |
34a7333
to
b8db017
Compare
Enables shebang usage of nix shell. All arguments with `#! nix` get added to the nix invocation. This implementation does NOT set any additional arguments other than placing the script path itself as the first argument such that the interpreter can utilize it. Example below: ``` #!/usr/bin/env nix #! nix shell --quiet #! nix nixpkgs#bash #! nix nixpkgs#shellcheck #! nix nixpkgs#hello #! nix --ignore-environment --command bash # shellcheck shell=bash set -eu shellcheck "$0" || exit 1 function main { hello echo 0:"$0" 1:"$1" 2:"$2" } "$@" ``` fix: include programName usage EDIT: For posterity I've changed shellwords to shellwords2 in order not to interfere with other changes during a rebase. shellwords2 is removed in a later commit. -- roberth
fix: release notes
This will allow a different base directory to be used, matching a shebang script location instead of the working directory.
b8db017
to
eb8d947
Compare
Being restrictive about syntax leaves opportunity to improve the syntax and functionality later.
These usages of the working directory are perhaps unlikely to interact with shebangs, but the code is more consistent this way, and we're less likely to miss usages that do interact.
03329bb
to
8387c43
Compare
FYI perhaps we never made this policy, but this was merged (a) without a merge commit and (b) with commits that perhaps don't individually pass tests (my guess from the messages). The combination of those two things makes bisecting later harder. (Merge commit helps with more complicated history because |
Worth a revert and re-merge? |
Three PRs have been merged since, and would have to be remerged, plus you get the general nastiness of force-pushing to master. I'd say leave as is, but pay attention to how you're merging PRs. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nix-shell-with-shebang/17088/4 |
Motivation
This adds shebang support as implemented by @tomberek with the changes/additions
Remaining todo:
--
? All commands or justrun
/shell
/develop
?Context
Based on
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.sh
src/*/tests
tests/nixos/*
Priorities
Add 👍 to pull requests you find important.