Files
nix-helper-flake/flake.nix
T

33 lines
1019 B
Nix

{
description = "A flake that provides a set of useful helper functions";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
outputs = { self, nixpkgs }: rec {
mkIfElse = with nixpkgs.lib; p: yes: no: mkMerge [
(mkIf p yes)
(mkIf (!p) no)
];
mkSymlinkActivationScript = {target, source, isDir ? false}: ''
if [ -e ${target} ]; then
rm${if isDir then " -rf" else ""} ${target}
fi
ln -s ${source} ${target}
'';
attrByStrPath = strPath: set: nixpkgs.lib.attrByPath (nixpkgs.lib.strings.splitString "." strPath) null set;
setAttrByStrPath = strPath: value: nixpkgs.lib.setAttrByPath (nixpkgs.lib.strings.splitString "." strPath) value;
homeFilesFromStringAttrs = { dir, attrs, exec ? false }: nixpkgs.lib.mergeAttrsList (map (x: nixpkgs.lib.mergeAttrsList (map (y: {
"${dir}/${x}" = {
text = y;
executable = exec;
};
}) (builtins.attrValues attrs)) ) (builtins.attrNames attrs));
};
}