{ 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}: '' if [ -e ${source} ]; then if [ -e ${target} ]; then rm -rf ${target} fi ln -s ${source} ${target} fi ''; 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 }: mergeListsToAttrs (map (x: "${dir}/${x}") (builtins.attrNames attrs)) (map (y: { text = y; executable = exec; }) (builtins.attrValues attrs)); prependShebangToString = x: "#!/usr/bin/env bash\n" + x; localBinFromStringAttrs = attrs: homeFilesFromStringAttrs { dir = ".local/bin"; attrs = builtins.mapAttrs (name: value: prependShebangToString value) attrs; exec = true; }; mergeListsToAttrs = names: values: nixpkgs.lib.listToAttrs (nixpkgs.lib.zipListsWith (name: value: { inherit name value; }) names values); mkEnumFromDirContents = dir: nixpkgs.lib.types.enum (map (name: nixpkgs.lib.removeSuffix ".nix" name) (builtins.attrNames (builtins.readDir dir))); mkOptionalListOfType = type: nixpkgs.lib.types.either (type) (nixpkgs.lib.types.listOf (type)); mkMirroredModulesFlakeModule = moduleName: func: { flake.nixosModules.${moduleName} = let isHomeModule = false; in func; flake.homeModules.${moduleName} = let isHomeModule = true; in func; }; }; }