From 3763bd664749de8793349132ee40a49f95d434ba Mon Sep 17 00:00:00 2001 From: jim3692 Date: Sat, 11 Apr 2026 16:09:45 +0300 Subject: [PATCH 1/2] feat(genflake): support for patching the final flake inputs --- build.sh | 4 ++-- flake.nix | 6 ++++++ lib/genflake.nix | 6 ++++-- lib/icedos.nix | 48 ++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/build.sh b/build.sh index 42f0c8ab..b77023ed 100644 --- a/build.sh +++ b/build.sh @@ -107,11 +107,11 @@ 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")" +ICEDOS_FLAKE_INPUTS_JSON="$(ICEDOS_UPDATE="$update_repos" ICEDOS_STAGE="genflake" nix build $refresh $trace --no-link --print-out-paths --file "$ICEDOS_ROOT/lib/genflake.nix" flakeInputsJson)" +export ICEDOS_FLAKE_INPUTS="$(cat $ICEDOS_FLAKE_INPUTS_JSON | json2nix | sed "1,1d" | sed "\$d")" if [[ "${ICEDOS_FLAKE_INPUTS}" == "" ]]; then exit 1 fi - echo "{ inputs = { $ICEDOS_FLAKE_INPUTS }; outputs = { ... }: { }; }" >"$ICEDOS_STATE_DIR/$FLAKE" ( set -e diff --git a/flake.nix b/flake.nix index 8dea3624..4bc3d1c6 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,15 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + json2nix = { + url = "github:cloudandheat/json2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { + json2nix, nixpkgs, self, ... @@ -73,6 +78,7 @@ nixfmt rsync toml2json + (json2nix.packages.${system}.default) ] }:$PATH" export ICEDOS_ROOT="${self}" diff --git a/lib/genflake.nix b/lib/genflake.nix index 5a625c3d..6db26d56 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 @@ -102,7 +102,9 @@ let }).config; in { - inherit flakeInputs evaluatedConfig; + inherit evaluatedConfig; + + flakeInputsJson = flakeInputs |> toJSON |> writeText "inputs.json"; 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 ); From 1ffe5fb9a265c045d0c51663d3ad2830eca3ccd6 Mon Sep 17 00:00:00 2001 From: jim3692 Date: Tue, 5 May 2026 19:04:30 +0300 Subject: [PATCH 2/2] fix(genflake): use lib.generators.toPretty for nix generation --- build.sh | 4 ++-- flake.nix | 6 ------ lib/genflake.nix | 6 +++++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/build.sh b/build.sh index b77023ed..2df73fe7 100644 --- a/build.sh +++ b/build.sh @@ -107,11 +107,11 @@ if [[ "$update_core" == "1" && -z "$skip_update_core" ]]; then fi # Generate flake inputs -ICEDOS_FLAKE_INPUTS_JSON="$(ICEDOS_UPDATE="$update_repos" ICEDOS_STAGE="genflake" nix build $refresh $trace --no-link --print-out-paths --file "$ICEDOS_ROOT/lib/genflake.nix" flakeInputsJson)" -export ICEDOS_FLAKE_INPUTS="$(cat $ICEDOS_FLAKE_INPUTS_JSON | json2nix | 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 + echo "{ inputs = { $ICEDOS_FLAKE_INPUTS }; outputs = { ... }: { }; }" >"$ICEDOS_STATE_DIR/$FLAKE" ( set -e diff --git a/flake.nix b/flake.nix index 4bc3d1c6..8dea3624 100644 --- a/flake.nix +++ b/flake.nix @@ -1,15 +1,10 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - json2nix = { - url = "github:cloudandheat/json2nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; outputs = { - json2nix, nixpkgs, self, ... @@ -78,7 +73,6 @@ nixfmt rsync toml2json - (json2nix.packages.${system}.default) ] }:$PATH" export ICEDOS_ROOT="${self}" diff --git a/lib/genflake.nix b/lib/genflake.nix index 6db26d56..250cbd30 100644 --- a/lib/genflake.nix +++ b/lib/genflake.nix @@ -12,6 +12,7 @@ let concatStringsSep evalModules fileContents + generators listToAttrs optional pathExists @@ -104,7 +105,10 @@ in { inherit evaluatedConfig; - flakeInputsJson = flakeInputs |> toJSON |> writeText "inputs.json"; + flakeInputsNix = generators.toPretty { + multiline = true; + allowPrettyValues = true; + } flakeInputs; flakeFinal = '' {