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

hm: option for default linking method #182

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 49 additions & 33 deletions home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Collaborator

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?


inherit (pkgs.callPackage ./lib.nix { })
splitPath
Expand Down Expand Up @@ -44,7 +41,7 @@ in
home.persistence = mkOption {
default = { };
type = with types; attrsOf (
submodule ({ name, ... }: {
submodule ({ name, config, ... }: {
options =
{
persistentStoragePath = mkOption {
Expand All @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
This can be overrided on a per entry basis.
This can be overridden on a per entry basis.

'';
};

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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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" ]
Expand Down Expand Up @@ -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" ]
Expand All @@ -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);
})
];
Expand Down
Loading