diff options
| author | Daiderd Jordan <daiderd@gmail.com> | 2020-05-26 23:15:07 +0200 |
|---|---|---|
| committer | Daiderd Jordan <daiderd@gmail.com> | 2020-05-29 21:29:20 +0200 |
| commit | 77121650d42cbc11d5a62a9e466b0433324659fb (patch) | |
| tree | 2d2dd9e1c93b710f15a390fca77f33a62f45dcbc /modules/system | |
| parent | f0552188ba714520b7f182b5ab0fac5de05f5b54 (diff) | |
system: add patches module
Diffstat (limited to 'modules/system')
| -rw-r--r-- | modules/system/activation-scripts.nix | 1 | ||||
| -rw-r--r-- | modules/system/default.nix | 1 | ||||
| -rw-r--r-- | modules/system/patches.nix | 64 |
3 files changed, 66 insertions, 0 deletions
diff --git a/modules/system/activation-scripts.nix b/modules/system/activation-scripts.nix index 9140163..bbbda88 100644 --- a/modules/system/activation-scripts.nix +++ b/modules/system/activation-scripts.nix @@ -57,6 +57,7 @@ in ${cfg.activationScripts.users.text} ${cfg.activationScripts.nix.text} ${cfg.activationScripts.applications.text} + ${cfg.activationScripts.patches.text} ${cfg.activationScripts.etc.text} ${cfg.activationScripts.defaults.text} ${cfg.activationScripts.launchd.text} diff --git a/modules/system/default.nix b/modules/system/default.nix index d272a18..629760c 100644 --- a/modules/system/default.nix +++ b/modules/system/default.nix @@ -86,6 +86,7 @@ in mkdir -p $out/darwin cp -f ${../../CHANGELOG} $out/darwin-changes + ln -s ${cfg.build.patches}/patches $out/patches ln -s ${cfg.build.etc}/etc $out/etc ln -s ${cfg.path} $out/sw diff --git a/modules/system/patches.nix b/modules/system/patches.nix new file mode 100644 index 0000000..0820d01 --- /dev/null +++ b/modules/system/patches.nix @@ -0,0 +1,64 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.system; +in + +{ + options = { + + system.patches = mkOption { + type = types.listOf types.path; + default = []; + example = literalExample '' + [ + (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 = '' + Set of patches to apply to <filename>/</filename>. + + Useful for safely changing system files. Unlike the etc module this + won't remove or modify files with unexpected content. + ''; + }; + + }; + + config = { + + system.build.patches = pkgs.runCommandNoCC "patches" + { 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 + + f=$(readlink /run/current-system/patches) + if ! test "$f" = ${config.system.build.patches}/patches; then + for f in $(find /run/current-system/patches/ -type l); do + patch --reverse --backup -d / -p1 < "$f" >/dev/null || true + done + + ${concatMapStringsSep "\n" (f: "patch --forward --backup -d / -p1 < '${f}' || true") cfg.patches} + fi + ''; + + }; +} |
