diff --git a/build.sh b/build.sh index 42f0c8ab..2df73fe7 100644 --- a/build.sh +++ b/build.sh @@ -107,7 +107,7 @@ if [[ "$update_core" == "1" && -z "$skip_update_core" ]]; then fi # Generate flake inputs -export ICEDOS_FLAKE_INPUTS="$(ICEDOS_UPDATE="$update_repos" ICEDOS_STAGE="genflake" nix eval $refresh $trace --file "$ICEDOS_ROOT/lib/genflake.nix" flakeInputs | nixfmt | sed "1,1d" | sed "\$d")" +export ICEDOS_FLAKE_INPUTS="$(ICEDOS_UPDATE="$update_repos" ICEDOS_STAGE="genflake" nix eval $refresh $trace --raw --file "$ICEDOS_ROOT/lib/genflake.nix" flakeInputsNix | nixfmt | sed "1,1d" | sed "\$d")" if [[ "${ICEDOS_FLAKE_INPUTS}" == "" ]]; then exit 1 fi diff --git a/lib/genflake.nix b/lib/genflake.nix index 5a625c3d..250cbd30 100644 --- a/lib/genflake.nix +++ b/lib/genflake.nix @@ -4,7 +4,7 @@ let system = icedos.system.arch or "x86_64-linux"; pkgs = import { inherit system; }; - inherit (pkgs) lib; + inherit (pkgs) lib writeText; inherit (lib) boolToString @@ -12,6 +12,7 @@ let concatStringsSep evalModules fileContents + generators listToAttrs optional pathExists @@ -102,7 +103,12 @@ let }).config; in { - inherit flakeInputs evaluatedConfig; + inherit evaluatedConfig; + + flakeInputsNix = generators.toPretty { + multiline = true; + allowPrettyValues = true; + } flakeInputs; flakeFinal = '' { diff --git a/lib/icedos.nix b/lib/icedos.nix index 26494912..7ee82d27 100644 --- a/lib/icedos.nix +++ b/lib/icedos.nix @@ -3,12 +3,14 @@ icedosLib, inputs, lib, + pkgs, ... }: let inherit (builtins) hasAttr + length pathExists readFile replaceStrings @@ -34,6 +36,7 @@ let finalIcedosLib = icedosLib // rec { inputIsOverride = { input }: (hasAttr "override" input) && input.override; + inputHasPatches = { input }: (hasAttr "patches" input) && length input.patches > 0; # Generate a sanitized full submodule name from URL and submodule name # Replaces special characters with underscores for avoiding flake registry warnings and errors @@ -199,7 +202,8 @@ let _getModuleInputs = modules: let - inherit (builtins) attrNames filter; + inherit (builtins) attrNames filter getFlake; + inherit (pkgs) applyPatches; modulesWithInputs = filter (hasAttr "inputs") modules; in flatten ( @@ -214,6 +218,8 @@ let i: let isOverride = inputIsOverride { input = inputs.${i}; }; + hasPatches = inputHasPatches { input = inputs.${i}; }; + moduleIdentifier = if (hasAttr "skipModuleAsInput" _repoInfo && _repoInfo.skipModuleAsInput) then "icedos-config" @@ -222,12 +228,42 @@ let inherit (_repoInfo) url; subMod = meta.name; }; + + patchedInputSource = applyPatches { + name = "${i}-patched"; + patches = inputs.${i}.patches; + src = getFlake inputs.${i}.url |> toString; + }; + + normalInput = rec { + _originalName = if hasPatches then "${i}_source" else i; + name = if isOverride then _originalName else "${moduleIdentifier}-${_originalName}"; + value = removeAttrs inputs.${i} [ + "override" + "patches" + ]; + }; + + patchedInput = rec { + _originalName = i; + name = if isOverride then _originalName else "${moduleIdentifier}-${_originalName}"; + value = + (removeAttrs inputs.${i} [ + "override" + "patches" + ]) + // { + url = "path:${patchedInputSource}"; + }; + }; in - { - _originalName = i; - name = if isOverride then i else "${moduleIdentifier}-${i}"; - value = removeAttrs inputs.${i} [ "override" ]; - } + if hasPatches then + [ + normalInput + patchedInput + ] + else + normalInput ) (attrNames inputs) ) modulesWithInputs );