Skip to content

add HOST_PATH support#1

Open
matthewbauer wants to merge 15 commits intoobsidiansystems:developfrom
matthewbauer:host-which
Open

add HOST_PATH support#1
matthewbauer wants to merge 15 commits intoobsidiansystems:developfrom
matthewbauer:host-which

Conversation

@matthewbauer
Copy link
Copy Markdown
Collaborator

HOST_PATH is set in Nixpkgs during cross-compilation to detect
binaries available at runtime. It makes sure you get the right
architecture in your cross-compiled binaries. When HOST_PATH is not
set, fall back to PATH.
findExecutablesInDirectories was only added in 1.2.4.0.
Copy link
Copy Markdown
Member

@ali-abrar ali-abrar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the changelog and address CI failures. Thanks!

Comment thread src/System/Which.hs
which :: FilePath -> IO (Maybe FilePath)
which f = fmap (fmap (T.unpack . Sh.toTextIgnore)) $ Sh.shelly $ Sh.which $ Sh.fromText $ T.pack f
which f = do
path <- runMaybeT $ MaybeT (lookupEnv "HOST_PATH") <|> MaybeT (lookupEnv "PATH")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the behavior different now compared to when we used which from Shelly?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference is that HOST_PATH is now used when it is available.

Comment thread src/System/Which.hs Outdated
| otherwise -> compileError $ "Path to executable " <> show f <> " was found in " <> show f' <> " which is not in /nix/store. Be sure to add the relevant package to 'backendTools' in default.nix."
| otherwise -> compileError $
"Path to executable " <> show f <> " was found in " <> show f'
<> " which is not in /nix/store. Be sure to add the relevant package to 'backendTools' in default.nix."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment assumes that this package is being used in the context of an obelisk project, it seems. The reference to "backendTools in default.nix" should be changed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I removed this for my rhyolite PR https://github.com/obsidiansystems/rhyolite/pull/100/files#diff-8e11fb146d567575b09cdf4138230cebR24, but then copied my project's which to a separate package and accidentally re-introduced this.

Comment thread test/Spec.hs Outdated
appendFile (bin3 </> "hello") "hello"
makeExecutable $ bin3 </> "hello"
appendFile (bin3 </> "hello2") "hello2"
-- makeExecutable $ bin3 </> "hello2"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just to make sure that non-executable files don't end up in which results.

Comment thread test/Spec.hs

makeExecutable :: FilePath -> IO ()
makeExecutable f = setPermissions f . setOwnerExecutable True =<< getPermissions f

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test here that fails with the old Shelly implementation but passes now?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, this was just to make sure the new implementation of which is correct.

@ryantrinkle
Copy link
Copy Markdown
Member

ryantrinkle commented Sep 12, 2019 via email

@Ericson2314
Copy link
Copy Markdown
Member

@ryantrinkle HOST_PATH is a Nix thing Matt and I added to distinguish between build-time executables and run-time executables, so when you cross compile you get a binary you can actually use.

@ryantrinkle
Copy link
Copy Markdown
Member

This should be done in a package called which-nix rather than which.

@matthewbauer
Copy link
Copy Markdown
Collaborator Author

matthewbauer commented Sep 12, 2019

This should be done in a package called which-nix rather than which.

staticWhich already requires that which results be in /nix/store, so this is already nix-specific. In addition, there's no reason that HOST_PATH needs to be just for Nix. Any time we cross compile with "staticWhich", we will end up getting binaries from the build machine that are the wrong architecture for the target machine. Setting HOST_PATH provides a way to get around that behavior. Otherwise everything using static-which can't cross compile correctly. If there's a better name than HOST_PATH available we can switch to that.

@3noch
Copy link
Copy Markdown
Contributor

3noch commented Jun 5, 2020

I think we just need a version of which that lets you pick which env vars to search instead of hardcoding "arbitrary" choices like this here. Also splitting out any nix-specific logic into a new package is the right move. It can wrap this package and add nix-specific functionality/checks. That's the direction we should go I think.

@matthewbauer
Copy link
Copy Markdown
Collaborator Author

matthewbauer commented Jul 30, 2020

I think we just need a version of which that lets you pick which env vars to search instead of hardcoding "arbitrary" choices like this here. Also splitting out any nix-specific logic into a new package is the right move. It can wrap this package and add nix-specific functionality/checks. That's the direction we should go I think.

So, we could make something like whichWithPath that you could use to specify your own path variable. But then, I'm afraid that everyone would just do whichWithPath "PATH" and cross-compilation would be broken. When using which, all we need to know is whether you will be running the executable at runtime or buildtime. Right now, almost all usages of which are for runtime. I guess if people really object to reading HOST_PATH directly in which, we could add whichWithPaths and make everyone do whichWithPaths ["HOST_PATH" "PATH"] when they want cross-compilation to work.

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

Successfully merging this pull request may close these issues.

6 participants