1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-06 16:57:08 +00:00
nix-darwin/modules/system/patches.nix

75 lines
1.8 KiB
Nix
Raw Normal View History

2020-05-26 23:15:07 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.system;
in
{
options = {
system.patches = mkOption {
type = types.listOf types.path;
2022-09-25 14:12:08 -04:00
default = [ ];
example = literalExpression ''
2020-05-26 23:15:07 +02:00
[
(pkgs.writeText "bashrc.patch" ''''
--- a/etc/bashrc
+++ b/etc/bashrc
@@ -8,3 +8,5 @@
shopt -s checkwinsize
[ -r "/etc/bashrc_$TERM_PROGRAM" ] && . "/etc/bashrc_$TERM_PROGRAM"
+
+if test -e /etc/static/bashrc; then . /etc/static/bashrc; fi
'''')
]
'';
description = lib.mdDoc ''
Set of patches to apply to {file}`/`.
2020-05-26 23:15:07 +02:00
::: {.warning}
This can modify everything so use with caution.
:::
2020-05-26 23:15:07 +02:00
Useful for safely changing system files. Unlike the etc module this
won't remove or modify files with unexpected content.
'';
};
};
config = {
2022-09-25 14:12:08 -04:00
system.build.patches = pkgs.runCommand "patches"
2020-05-26 23:15:07 +02:00
{ preferLocalBuild = true; }
''
mkdir -p $out/patches
cd $out/patches
${concatMapStringsSep "\n" (f: "ln -s '${f}' $(basename '${f}')") cfg.patches}
'';
system.activationScripts.patches.text = ''
# Applying patches to /.
echo "applying patches..." >&2
2020-05-29 22:54:25 +02:00
for f in $(ls /run/current-system/patches 2> /dev/null); do
if test ! -e "${config.system.build.patches}/patches/$f"; then
2023-03-07 13:35:24 +00:00
patch --force --reverse --backup -d / -p1 < "/run/current-system/patches/$f" || true
2020-05-29 22:54:25 +02:00
fi
done
2020-05-26 23:15:07 +02:00
${concatMapStringsSep "\n" (f: ''
f="$(basename ${f})"
if ! patch --force --reverse --dry-run -d / -p1 < '${f}' &> /dev/null; then
patch --forward --backup -d / -p1 < '${f}' || true
fi
'') cfg.patches}
2020-05-26 23:15:07 +02:00
'';
};
}