Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions lib/genflake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ let

system = icedos.system.arch or "x86_64-linux";
pkgs = import <nixpkgs> { inherit system; };
inherit (pkgs) lib;
inherit (pkgs) lib writeText;

inherit (lib)
boolToString
concatMapStrings
concatStringsSep
evalModules
fileContents
generators
listToAttrs
optional
pathExists
Expand Down Expand Up @@ -102,7 +103,12 @@ let
}).config;
in
{
inherit flakeInputs evaluatedConfig;
inherit evaluatedConfig;

flakeInputsNix = generators.toPretty {
multiline = true;
allowPrettyValues = true;
} flakeInputs;

flakeFinal = ''
{
Expand Down
48 changes: 42 additions & 6 deletions lib/icedos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
icedosLib,
inputs,
lib,
pkgs,
...
}:

let
inherit (builtins)
hasAttr
length
pathExists
readFile
replaceStrings
Expand All @@ -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
Expand Down Expand Up @@ -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 (
Expand All @@ -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"
Expand All @@ -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
);
Expand Down