-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
hm: option for default linking method #182
Open
Misterio77
wants to merge
6
commits into
nix-community:master
Choose a base branch
from
Misterio77:hm-default-method
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
413b6ee
refactor(home): use coercedTo with directory type
Misterio77 79e2eeb
refactor(home): inline isSymlink and isBindfs
Misterio77 6f0caea
feat(home): add defaultDirectoryMethod
Misterio77 b625922
docs(home): improve method docs
Misterio77 8d14ed5
fix(home): order of operations causing issue with files
Misterio77 65a12c0
fix(home): order of operations causing issue with files
Misterio77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,10 +6,7 @@ let | |||||
|
||||||
persistentStorageNames = attrNames cfg; | ||||||
|
||||||
getDirPath = v: if isString v then v else v.directory; | ||||||
getDirMethod = v: v.method or "bindfs"; | ||||||
isBindfs = v: (getDirMethod v) == "bindfs"; | ||||||
isSymlink = v: (getDirMethod v) == "symlink"; | ||||||
getDirPath = v: v.directory; | ||||||
|
||||||
inherit (pkgs.callPackage ./lib.nix { }) | ||||||
splitPath | ||||||
|
@@ -44,7 +41,7 @@ in | |||||
home.persistence = mkOption { | ||||||
default = { }; | ||||||
type = with types; attrsOf ( | ||||||
submodule ({ name, ... }: { | ||||||
submodule ({ name, config, ... }: { | ||||||
options = | ||||||
{ | ||||||
persistentStoragePath = mkOption { | ||||||
|
@@ -56,26 +53,45 @@ in | |||||
''; | ||||||
}; | ||||||
|
||||||
defaultDirectoryMethod = mkOption { | ||||||
type = types.enum [ "bindfs" "symlink" ]; | ||||||
default = "bindfs"; | ||||||
description = '' | ||||||
The linking method that should be used for directories. | ||||||
|
||||||
- bindfs is very transparent, and thus used as a safe | ||||||
default. It has, however, a significant performance impact in | ||||||
IO-heavy situations. | ||||||
|
||||||
- symlinks have great performance but may be treated | ||||||
specially by some programs that may e.g. generate | ||||||
errors/warnings, or replace them. | ||||||
|
||||||
This can be overrided on a per entry basis. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
''; | ||||||
}; | ||||||
|
||||||
directories = mkOption { | ||||||
type = with types; listOf (either str (submodule { | ||||||
options = { | ||||||
directory = mkOption { | ||||||
type = str; | ||||||
default = null; | ||||||
description = "The directory path to be linked."; | ||||||
}; | ||||||
method = mkOption { | ||||||
type = types.enum [ "bindfs" "symlink" ]; | ||||||
default = "bindfs"; | ||||||
description = '' | ||||||
The linking method that should be used for this | ||||||
directory. bindfs is the default and works for most use | ||||||
cases, however some programs may behave better with | ||||||
symlinks. | ||||||
''; | ||||||
type = types.listOf ( | ||||||
types.coercedTo types.str (directory: { inherit directory; }) (submodule { | ||||||
options = { | ||||||
directory = mkOption { | ||||||
type = str; | ||||||
description = "The directory path to be linked."; | ||||||
}; | ||||||
method = mkOption { | ||||||
type = types.enum [ "bindfs" "symlink" ]; | ||||||
default = config.defaultDirectoryMethod; | ||||||
description = '' | ||||||
The linking method to be used for this specific | ||||||
directory entry. See | ||||||
<literal>defaultDirectoryMethod</literal> for more | ||||||
information on the tradeoffs. | ||||||
''; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
})); | ||||||
}) | ||||||
); | ||||||
default = [ ]; | ||||||
example = [ | ||||||
"Downloads" | ||||||
|
@@ -218,8 +234,8 @@ in | |||||
mkLinksToPersistentStorage = persistentStorageName: | ||||||
listToAttrs (map | ||||||
(mkLinkNameValuePair persistentStorageName) | ||||||
(map getDirPath (cfg.${persistentStorageName}.files ++ | ||||||
(filter isSymlink cfg.${persistentStorageName}.directories))) | ||||||
(cfg.${persistentStorageName}.files ++ (map getDirPath | ||||||
(filter (v: v.method == "symlink") cfg.${persistentStorageName}.directories))) | ||||||
); | ||||||
in | ||||||
foldl' recursiveUpdate { } (map mkLinksToPersistentStorage persistentStorageNames); | ||||||
|
@@ -294,7 +310,7 @@ in | |||||
mkBindMountServicesForPath = persistentStorageName: | ||||||
listToAttrs (map | ||||||
(mkBindMountService persistentStorageName) | ||||||
(map getDirPath (filter isBindfs cfg.${persistentStorageName}.directories)) | ||||||
(map getDirPath (filter (v: v.method == "bindfs") cfg.${persistentStorageName}.directories)) | ||||||
); | ||||||
in | ||||||
builtins.foldl' | ||||||
|
@@ -358,7 +374,7 @@ in | |||||
mkBindMountsForPath = persistentStorageName: | ||||||
concatMapStrings | ||||||
(mkBindMount persistentStorageName) | ||||||
(map getDirPath (filter isBindfs cfg.${persistentStorageName}.directories)); | ||||||
(map getDirPath (filter (v: v.method == "bindfs") cfg.${persistentStorageName}.directories)); | ||||||
|
||||||
mkUnmount = persistentStorageName: dir: | ||||||
let | ||||||
|
@@ -378,7 +394,7 @@ in | |||||
mkUnmountsForPath = persistentStorageName: | ||||||
concatMapStrings | ||||||
(mkUnmount persistentStorageName) | ||||||
(map getDirPath (filter isBindfs cfg.${persistentStorageName}.directories)); | ||||||
(map getDirPath (filter (v: v.method == "bindfs") cfg.${persistentStorageName}.directories)); | ||||||
|
||||||
mkLinkCleanup = persistentStorageName: dir: | ||||||
let | ||||||
|
@@ -403,12 +419,12 @@ in | |||||
mkLinkCleanupForPath = persistentStorageName: | ||||||
concatMapStrings | ||||||
(mkLinkCleanup persistentStorageName) | ||||||
(map getDirPath (filter isSymlink cfg.${persistentStorageName}.directories)); | ||||||
(map getDirPath (filter (v: v.method == "symlink") cfg.${persistentStorageName}.directories)); | ||||||
|
||||||
|
||||||
in | ||||||
mkMerge [ | ||||||
(mkIf (any (path: (filter isSymlink cfg.${path}.directories) != [ ]) persistentStorageNames) { | ||||||
(mkIf (any (path: (filter (v: v.method == "symlink") cfg.${path}.directories) != [ ]) persistentStorageNames) { | ||||||
# Clean up existing empty directories in the way of links | ||||||
cleanEmptyLinkTargets = | ||||||
dag.entryBefore | ||||||
|
@@ -417,7 +433,7 @@ in | |||||
${concatMapStrings mkLinkCleanupForPath persistentStorageNames} | ||||||
''; | ||||||
}) | ||||||
(mkIf (any (path: (filter isBindfs cfg.${path}.directories) != [ ]) persistentStorageNames) { | ||||||
(mkIf (any (path: (filter (v: v.method == "bindfs") cfg.${path}.directories) != [ ]) persistentStorageNames) { | ||||||
createAndMountPersistentStoragePaths = | ||||||
dag.entryBefore | ||||||
[ "writeBoundary" ] | ||||||
|
@@ -447,7 +463,7 @@ in | |||||
unmountBindMounts | ||||||
''; | ||||||
}) | ||||||
(mkIf (any (path: (cfg.${path}.files != [ ]) || ((filter isSymlink cfg.${path}.directories) != [ ])) persistentStorageNames) { | ||||||
(mkIf (any (path: (cfg.${path}.files != [ ]) || ((filter (v: v.method == "symlink") cfg.${path}.directories) != [ ])) persistentStorageNames) { | ||||||
createTargetFileDirectories = | ||||||
dag.entryBefore | ||||||
[ "writeBoundary" ] | ||||||
|
@@ -457,7 +473,7 @@ in | |||||
(targetFilePath: '' | ||||||
mkdir -p ${escapeShellArg (concatPaths [ cfg.${persistentStorageName}.persistentStoragePath (dirOf targetFilePath) ])} | ||||||
'') | ||||||
(map getDirPath (cfg.${persistentStorageName}.files ++ (filter isSymlink cfg.${persistentStorageName}.directories)))) | ||||||
(cfg.${persistentStorageName}.files ++ (map getDirPath (filter (v: v.method == "symlink") cfg.${persistentStorageName}.directories)))) | ||||||
persistentStorageNames); | ||||||
}) | ||||||
]; | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since you're removing all the other accessors, maybe this one should go, too?