Created
November 30, 2023 22:49
-
-
Save bzm3r/410fc1bcd1f22426a266a7af2b61bdf3 to your computer and use it in GitHub Desktop.
How to not worry, and still be happy.
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
{ | |
config, | |
lib, | |
pkgs, | |
_user, | |
... | |
}: let | |
inherit (builtins) replaceStrings; | |
inherit (lib.attrsets) mapAttrsToList; | |
inherit (lib.lists) flatten; | |
inherit (lib.modules) mkIf mkDefault mkDerivedConfig; | |
inherit (lib.options) mkOption; | |
inherit (lib.types) attrsOf lines nullOr path str submodule; | |
_tmpfileType = prefix: | |
attrsOf (submodule ({ | |
config, | |
options, | |
name, | |
... | |
}: { | |
options = { | |
source = mkOption {type = path;}; | |
target = mkOption {type = str;}; | |
text = mkOption { | |
default = null; | |
type = nullOr lines; | |
}; | |
}; | |
config = { | |
source = mkIf (config.text != null) (mkDerivedConfig options.text (pkgs.writeText "xdg-${prefix}-${replaceStrings ["/"] ["-"] name}")); | |
target = mkDefault name; | |
}; | |
})); | |
in { | |
options = { | |
home.file = mkOption { | |
default = {}; | |
type = _tmpfileType "homeFile"; | |
}; | |
xdg = { | |
configFile = mkOption { | |
default = {}; | |
type = _tmpfileType "configFile"; | |
}; | |
dataFile = mkOption { | |
default = {}; | |
type = _tmpfileType "dataFile"; | |
}; | |
}; | |
}; | |
config.systemd.user.tmpfiles.users.${_user}.rules = let | |
_tmpStr = prefix: _: file: "L+ '${prefix}/${file.target}' - - - - ${file.source}"; | |
in | |
flatten [ | |
(mapAttrsToList (_tmpStr "%h") config.home.file) | |
(mapAttrsToList (_tmpStr "%h/.config") config.xdg.configFile) | |
(mapAttrsToList (_tmpStr "%h/.local/share") config.xdg.dataFile) | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment