Partial revert of 8d16ac9798

Fixes #157.
This commit is contained in:
talyz 2023-12-26 17:01:15 +01:00
parent 8d16ac9798
commit 3d599bd65e
No known key found for this signature in database
GPG key ID: 2DED2151F4671A2B
2 changed files with 16 additions and 8 deletions

View file

@ -1,4 +1,4 @@
{ pkgs, config, lib, utils, ... }:
{ pkgs, config, lib, ... }:
with lib;
let
@ -11,14 +11,11 @@ let
isBindfs = v: (getDirMethod v) == "bindfs";
isSymlink = v: (getDirMethod v) == "symlink";
inherit (utils)
escapeSystemdPath
;
inherit (pkgs.callPackage ./lib.nix { })
splitPath
dirListToPath
concatPaths
sanitizeName
;
mount = "${pkgs.util-linux}/bin/mount";
@ -205,7 +202,7 @@ in
let
link = file:
pkgs.runCommand
"${file}"
"${sanitizeName file}"
{ }
"ln -s '${file}' $out";
@ -238,7 +235,7 @@ in
dir;
targetDir = escapeShellArg (concatPaths [ cfg.${persistentStorageName}.persistentStoragePath dir ]);
mountPoint = escapeShellArg (concatPaths [ config.home.homeDirectory mountDir ]);
name = "bindMount-${escapeSystemdPath targetDir}";
name = "bindMount-${sanitizeName targetDir}";
bindfsOptions = concatStringsSep "," (
optional (!cfg.${persistentStorageName}.allowOther) "no-allow-other"
++ optional (versionAtLeast pkgs.bindfs.version "1.14.9") "fsname=${targetDir}"
@ -345,7 +342,7 @@ in
if ! ${mount} | grep -F ${mountPoint}' ' | grep -F ${targetDir}' ' >/dev/null; then
# The target directory changed, so we need to remount
echo "remounting ${mountPoint}"
${systemctl} --user stop bindMount-${escapeSystemdPath targetDir}
${systemctl} --user stop bindMount-${sanitizeName targetDir}
${bindfs} ${targetDir} ${mountPoint}
mountedPaths[${mountPoint}]=1
fi

11
lib.nix
View file

@ -6,13 +6,18 @@ let
concatStringsSep
hasPrefix
head
replaceStrings
optionalString
removePrefix
foldl'
elem
take
length
last
;
inherit (lib.strings)
sanitizeDerivationName
;
# ["/home/user/" "/.screenrc"] -> ["home" "user" ".screenrc"]
splitPath = paths:
@ -50,6 +55,11 @@ let
[ ]
parents;
sanitizeName = name:
replaceStrings
[ "." ] [ "" ]
(sanitizeDerivationName (removePrefix "/" name));
duplicates = list:
let
result =
@ -75,6 +85,7 @@ in
dirListToPath
concatPaths
parentsOf
sanitizeName
duplicates
;
}