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

nixos/types: cast path type to string, when it is "path" #57168

Closed
wants to merge 1 commit into from

Conversation

danbst
Copy link
Contributor

@danbst danbst commented Mar 9, 2019

Motivation for this change

This handles a specific case, when "path" type was supplied to types.path
option. Previously it was converted into store path, because it was used
in other derivations:

nix-repl> builtins.toJSON /etc/nixos/configuration.nix
"\"/nix/store/wd12lm99vp1syi3ywala46w4zhnvk83z-configuration.nix\""

So making users.users.alice.home = /home/alice; would convert /home/alice
directory into store path.

I can't think of situation when this is what is expected. State dirs and
password files could have been converted into store paths as well.
Having state dir on ro mount would probably result into error, but
password files were simple enough, so could easily be copied into
/nix/store and nobody noticed.

On other hand, we can't cast types.path to string always, because
in many places package is provided instead of path. It worked because of
silent casts... I'll leave a TODO for future contributors.

Reported in https://discourse.nixos.org/t/re-use-existing-home-migrating-from-ubuntu/2353

PS. I don't know how to write automated test for this, because it involves "paths", which are awkward to work with in a reproducible manner. I've tested locally with a local "path".

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

This handles a specific case, when "path" type was supplied to `types.path`
option. Previously it was converted into store path, because it was used
in other derivations:

```
nix-repl> builtins.toJSON /etc/nixos/configuration.nix
"\"/nix/store/wd12lm99vp1syi3ywala46w4zhnvk83z-configuration.nix\""
```

So making `users.users.alice.home = /home/alice;` would convert `/home/alice`
directory into store path.

I can't think of situation when this is what is expected. State dirs and
password files could have been converted into store paths as well.
Having state dir on ro mount would probably result into error, but
password files were simple enough, so could easily be copied into
`/nix/store` and nobody noticed.

On other hand, we can't cast `types.path` to string always, because
in many places package is provided instead of path. It worked because of
silent casts... I'll leave a TODO for future contributors.

Reported in https://discourse.nixos.org/t/re-use-existing-home-migrating-from-ubuntu/2353
@nixos-discourse
Copy link

This pull request has been mentioned on Nix community. There might be relevant details there:

https://discourse.nixos.org/t/re-use-existing-home-migrating-from-ubuntu/2353/5

@lheckemann
Copy link
Member

This isn't desirable in the general case, as importing the path into the store has a key benefit: making it part of the system closure. Not copying paths will make e.g. rollbacks a lot less effective.

@danbst
Copy link
Contributor Author

danbst commented Mar 12, 2019

Alright, agree.

@danbst danbst closed this Mar 12, 2019
@danbst danbst deleted the fix-users-home branch March 12, 2019 23:07
@danbst danbst mentioned this pull request Aug 9, 2019
1 task
@danbst
Copy link
Contributor Author

danbst commented Feb 3, 2020

More principled approach to this is coming #78640

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

Successfully merging this pull request may close these issues.

None yet

4 participants