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
20 changes: 20 additions & 0 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ To disable this behaviour and make the build exit, you can do this:
}
```

### Ignore failed patches

When building a configuration and some patches can't be applied (usually due to them being already merged), it a build failure.

To only give a warning instead of a build failure, you can do this:

```nix
# file: flake.nix
{
outputs =
{ nixpkgs-patcher, ... }@inputs:
{
nixosConfigurations.yourHostname = nixpkgs-patcher.lib.nixosSystem {
# ...
nixpkgsPatcher.ignoreFailedPatches = true; # default: false
};
};
}
```

### Using a Different System for Evaluation

For example trying to query the hostname of an aarch64-linux host on an x86_64-linux machine would fail by default, but if you specify `nixpkgsPatcher.system` to be the current machine's system, it works:
Expand Down
46 changes: 45 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
nixpkgs,
patches,
enableTroubleshootingShell,
ignoreFailedPatches,
pkgs,
}:
pkgs.applyPatches {
Expand All @@ -62,6 +63,42 @@
breakpointHook
];

patchPhase = ''
runHook prePatch

local -a patchesArray
concatTo patchesArray patches

local -a flagsArray
concatTo flagsArray patchFlags=-p1

for i in "''${patchesArray[@]}"; do
echo "applying patch $i"
local uncompress=cat
case "$i" in
*.gz)
uncompress="gzip -d"
;;
*.bz2)
uncompress="bzip2 -d"
;;
*.xz)
uncompress="xz -d"
;;
*.lzma)
uncompress="lzma -d"
;;
esac

# "2>&1" is a hack to make patch fail if the decompressor fails (nonexistent patch, etc.)
# shellcheck disable=SC2086
$uncompress < "$i" 2>&1 | patch "''${flagsArray[@]}" \
|| ${builtins.toJSON ignoreFailedPatches}
done

runHook postPatch
'';

failureHook = ''
failedPatches=$(find . -name "*.rej")
for failedPatch in $failedPatches; do
Expand Down Expand Up @@ -91,6 +128,7 @@
patchInputRegex ? defaultPatchInputRegex,
patches ? null,
enableTroubleshootingShell ? true,
ignoreFailedPatches ? false,
pkgs ? null,
system ? null,
}@args:
Expand Down Expand Up @@ -127,7 +165,10 @@
nixpkgs = nixpkgs';
patches = patches';
pkgs = pkgs';
inherit enableTroubleshootingShell;
inherit
enableTroubleshootingShell
ignoreFailedPatches
;
};
in
patchedNixpkgs;
Expand Down Expand Up @@ -234,11 +275,14 @@

enableTroubleshootingShell = config.enableTroubleshootingShell or true;

ignoreFailedPatches = config.ignoreFailedPatches or false;

patchedNixpkgs = patchNixpkgsRaw {
inherit
nixpkgs
patches
enableTroubleshootingShell
ignoreFailedPatches
pkgs
;
};
Expand Down