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/lib/utils: Add fileSystems.<name>.depends
option and generalise fsBefore (fixes #86955)
#86967
Conversation
This comment has been minimized.
This comment has been minimized.
481d8d9
to
aba704a
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6cbb64e
to
8ccc574
Compare
fileSystems.<name>.depends
option and generalise fsBefore (fixes #86955)
I marked this as stale due to inactivity. → More info |
8ccc574
to
e350a5e
Compare
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.
I am successfully using this to work around an issue when combining impermanence and agenix
It's working beautifully so I believe it is ready for merging
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.
Why do we normalise at all?
The mountPoint
already requires there to be no trailing slash and I see no reason why depends
shouldn't do the same.
Btw, mountPoint
and depends
could also use types.path
.
e350a5e
to
31c4b44
Compare
Well when I originally made this #95406 wasn't even created yet. I'm not entirely convinced the |
nonEmptyWithoutTrailingSlash = addCheckDesc "non-empty without trailing slash" types.str | ||
(s: isNonEmpty s && (builtins.match ".+/" s) == null); |
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.
Is there a reason for these not to start with a /
?
nonEmptyWithoutTrailingSlash = addCheckDesc "non-empty without trailing slash" types.str | |
(s: isNonEmpty s && (builtins.match ".+/" s) == null); | |
nonEmptyPathWithoutTrailingSlash = addCheckDesc "non-empty without trailing slash" types.path | |
(s: isNonEmpty s && (builtins.match ".+/" s) == null); |
Note that this doesn't make much sense:
- any
path
is non-empty - the path
/
has a trailing slash but is still allowed (even before this change)
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.
I just copied the check used by #95406
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.
I know you did. I guess we can leave improving this to a different PR.
bdf293e
to
76b6a3c
Compare
76b6a3c
to
cd716e6
Compare
cd716e6
to
e6cbf44
Compare
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.
@jakobrs Sorry for my confusing comments along the way!
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
nixos/lib/utils.nix
Outdated
in hasPrefix a'.mountPoint b'.device | ||
|| hasPrefix a'.mountPoint b'.mountPoint | ||
|| any (dependency: hasPrefix a'.mountPoint dependency) b'.depends; |
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.
Thanks for doing this! I just have a small stylistic suggestion, but other than that, I think this looks ready to be merged.
in hasPrefix a'.mountPoint b'.device | |
|| hasPrefix a'.mountPoint b'.mountPoint | |
|| any (dependency: hasPrefix a'.mountPoint dependency) b'.depends; | |
in | |
hasPrefix a'.mountPoint b'.device | |
|| hasPrefix a'.mountPoint b'.mountPoint | |
|| any (hasPrefix a'.mountPoint) b'.depends; |
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.
@jakobrs It ended up in the wrong commit and is still missing the formatting. While the indentation means the hasPrefix
lines don't line up as neatly, it shows more clearly on a quick glance what belongs to the expression, separating it from the let .. in
.
e6cbf44
to
c4d00ed
Compare
c4d00ed
to
ea34fe2
Compare
The commit which modifies
I suspect the problem is that some of my mounts have a
The root filesystem is mounted using a device, but the filesystem (BTRFS) has the label "NIXOS". This label is then used to mount additional subvolumes. |
@emmanuelrosa I guess we could just add let
getDevice fs =
if fs.device != null then
fs.device
else if fs.label != null then
"/dev/disk/by-label/${fs.label}"
else
""; # This will be caught when building the fstab, and we'd rather throw there
normalisePath = path: "${path}${optionalString (!(hasSuffix "/" path)) "/"}";
normalise = mount: mount // { device = normalisePath (getDevice mount);
mountPoint = normalisePath mount.mountPoint;
depends = map normalisePath mount.depends;
}; This would have the advantage of having "more correct" semantics, although it's a little more complex. |
Here is a PR: #127309 |
Motivation for this change
See #86955 for an example configuration where this matters.
What's new
The PR adds a
fileSystems.<name>.depends
option that can be used to specify what other mount points need to be mounted before this one, and makesfsBefore
recognise more forms of dependencies "out of the box", to fix #86955.Note: The following three comments of mine were created before a force push and no longer apply.
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)