Created
January 28, 2022 19:11
-
-
Save kkharji/87c63ec7d5792ea739af4ed5c37a7e15 to your computer and use it in GitHub Desktop.
Link to base directory instead of store. Usage: home.link.".config/git/template" = "modules/git/template";
This file contains hidden or 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
let | |
mkConfig = { config, lib, ... }: | |
with lib; | |
{ | |
config = { | |
home.activation.manualLinkOfFiles = | |
let | |
createLink = t: o: '' | |
ORIGIN="${config.toFullLink o}" | |
TARGET="$HOME/${t}" | |
PARENT="''${TARGET%/*}" | |
[ ! -d "$PARENT" ] && mkdir -p "$PARENT" | |
[ -d "$TARGET" ] && rm -rf "$TARGET" | |
[ -f "$TARGET" ] && rm "$TARGET" | |
$DRY_RUN_CMD ln -s $VERBOSE_ARG $ORIGIN $TARGET | |
''; | |
in | |
lib.hm.dag.entryAfter | |
[ "writeBoundary" ] | |
(if ((length (attrNames config.home.link)) != 0) then | |
(strings.concatStringsSep "\n" (mapAttrsToList createLink config.home.link)) | |
else | |
""); | |
}; | |
}; | |
getOptions = { config, lib, ... }: | |
with lib; { | |
options = { | |
nixenv = { | |
root = mkOption { | |
type = types.str; | |
default = "$HOME/system"; | |
defaultText = literalExample "$HOME/system"; | |
description = "the root to where the system configuration lies."; | |
}; | |
}; | |
home = { | |
link = mkOption { | |
description = "Similar to home.file but links outside of store."; | |
default = { }; | |
}; | |
}; | |
toFullLink = mkOption { | |
default = o: "${config.nixenv.root}/${o}"; | |
description = "convert a link to fully qualified link"; | |
}; | |
}; | |
}; | |
in | |
{ | |
home = { ... }: { imports = [ getOptions mkConfig ]; }; | |
common = getOptions; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment