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

Support Windows paths in canonPath and absPath #9767

Merged
merged 2 commits into from
Feb 27, 2024

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Jan 14, 2024

Motivation

canonPath and absPath work on native paths, and so should switch between supporting Unix paths and Windows paths accordingly.

The templating is because CanonPath, which shares the implementation, should always be Unix style. It is the pure "nix-native" path type for virtual file operations --- it is part of Nix's "business logic", and should not vary with the host OS accordingly.

Context

Depends on #9759

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

Copy link

dpulls bot commented Jan 15, 2024

🎉 All dependencies have been resolved !

@Ericson2314
Copy link
Member Author

A few meetings ago @edolstra had asked whether it would be better to go straight to using std;:filesystem. I would indeed like to try that, but rather to it as a follow-up step.

(This PR more straightforwardly preserves behavior by reusing code, and increasing test coverage. We can afterwards try std::filesystem::weakly_canonical with the test suite expanded in this PR, and see if it does the same thing.)

@edolstra
Copy link
Member

I'm pretty wary about adding a lot of complexity to support Windows, if we haven't even decided whether we want that, what that would look like, and whether there is sufficient interest to justify the complexity. (Having no access to Windows development machines, I really don't want to maintain code with a lot of WIN32 #ifdefs.)

It might be better to develop a Windows proof-of-concept on a separate branch for the time being.

@Ericson2314
Copy link
Member Author

Ericson2314 commented Jan 29, 2024

If we haven't even decided whether we want that, what that would look like, and whether there is sufficient interest to justify the complexity.

There are now some years-old separate branches in https://github.com/nix-windows/nix. I did write up that document. I am trying to minimize the CPP by dropping features to start, focusing on the unit tests, etc. and using more std::filesystem (but I think taht is best after the initial unit test push).

We can try asking the Nix community some more, but while I expect people to be passively interested I wouldn't expect much up-front commitment. The Windows and Unix industries are fairly disjoint, and plenty of people are happily avoiding Windows (certainly myself included for any downstream project I have full control over.) For me, this is more an expanding into new areas thing / growing the Nix community in new ways, than making something existing community members will immediate jump on.

(Having no access to Windows development machines, I really don't want to maintain code with a lot of WIN32 #ifdefs.)

I do all the development cross compiling from Linux, and will be creating a derivation to run the unit tests with Wine before merging something more significant. I would be fine simply not testing native Windows builds for the imminent future (a long trial mode) so there is no build/test failure that can only be reproduced on them.

@Ericson2314
Copy link
Member Author

In the meantime, #9881 is the first part which should be worthwhile with or without Windows.

@Ericson2314
Copy link
Member Author

@edolstra Discourse is not letting me reply to myself another time, so if you could comment in https://discourse.nixos.org/t/nix-on-windows/1113 saying you're trying to gauge user interest, that would be appreciated.

@Ericson2314 Ericson2314 mentioned this pull request Jan 30, 2024
Comment on lines +12 to +18
#ifdef _WIN32
# define FS_SEP "\\"
# define FS_ROOT "C:" FS_SEP // Need a mounted one, C drive is likely
#else
# define FS_SEP "/"
# define FS_ROOT FS_SEP
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Can't we get this from NativePath and save a #ifdef?

Copy link
Member Author

@Ericson2314 Ericson2314 Feb 16, 2024

Choose a reason for hiding this comment

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

Yes, though then I couldn't rely on "easy" literal concatenation. Also note that FS_ROOT we still cannot get from it because on Windows it is an arbitrary choice of drive just for testing purposes.

@Ericson2314
Copy link
Member Author

We agreed I would try to get rid of CanonPath::fromCwd first.

@Ericson2314 Ericson2314 marked this pull request as draft February 5, 2024 14:57
@roberth
Copy link
Member

roberth commented Feb 5, 2024

Discussed in meeting today

@Ericson2314:

  • CanonPath should be the platonic ideal path

  • PosixFileAccessor

    • Rename to NativeFileAccessor
    • Have std::filesystem::path root/prefix
  • It'd be ok to specify installables on multiple drives in one CLI.

    • In the language this won't be observed, except the root paths not being equal, just as we want to do with path values from fetched repos (lazy trees)
    • Drive letter is not observable within the language
  • In the legacy model, we don't seem to have a particularly good way to represent paths on multiple drives, because the legacy CLI uses a single big / InputAccessor.

  • @Ericson2314: even store paths could be independent roots, avoiding the exposure of their "mounts" into the store / the storedir

    • @edolstra: We might just require that everything in an invocation is on the same drive.
// split path, trying to make the native prefix as short as possible, and CanonPath suffix as long as possible
std::fs::path -> (std::fs::path, CanonPath)
    
// feed native prefix to NativeInputAccessor to create SourcePath
(std::fs::path, CanonPath) -> SourcePath
-I foo=D:\asdfasdf
-I bar=C:\asdfasdf
-E '((import <foo>) (import <bar>))'
SourcePath rootPath(CanonPath path);
SourcePath rootPath(std::fs:path path); 
SourcePath rootPath(std::fs:path path, cwd ...)

Agreed CanonPath::fromCwd must go

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/2024-02-05-nix-team-meeting-minutes-121/39340/1

@Ericson2314 Ericson2314 force-pushed the canon-path-split branch 2 times, most recently from e8096e9 to 3e06333 Compare February 16, 2024 15:09
This prepares the code to also support Windows paths in the next commit.
@Ericson2314 Ericson2314 force-pushed the canon-path-split branch 2 times, most recently from 24d6be7 to 2d21bf5 Compare February 16, 2024 15:28
@Ericson2314 Ericson2314 marked this pull request as ready for review February 16, 2024 15:28
@Ericson2314 Ericson2314 changed the title Support Windows paths in canonPath and absPath without messing up CanonPath Support Windows paths in canonPath and absPath Feb 16, 2024
`canonPath` and `absPath` work on native paths, and so should switch
between supporting Unix paths and Windows paths accordingly.

The templating is because `CanonPath`, which shares the implementation,
should always be Unix style. It is the pure "nix-native" path type for
virtual file operations --- it is part of Nix's "business logic", and
should not vary with the host OS accordingly.
@edolstra edolstra self-assigned this Feb 23, 2024
@edolstra edolstra merged commit c3e9e3d into NixOS:master Feb 27, 2024
9 checks passed
@Ericson2314 Ericson2314 deleted the canon-path-split branch February 27, 2024 16:21
@Ericson2314
Copy link
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants