1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-15 17:51:01 +00:00
nix-darwin/modules/system/patches.nix
Emily e65131e69c treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]; thanks
to @pennae for writing this tool! It automatically checks that the
resulting documentation doesn't change, although my fork loosens
this a little to ignore some irrelevant whitespace and typographical
differences.

As of this commit there is no DocBook remaining in the options
documentation.

You can play along at home if you want to reproduce this commit:

    $ NIX_PATH=nixpkgs=flake:nixpkgs/c1bca7fe84c646cfd4ebf3482c0e6317a0b13f22 \
      nix shell nixpkgs#coreutils \
      -c find . -name '*.nix' \
      -exec nix run github:emilazy/nix-doc-munge/0a7190f600027bf7baf6cb7139e4d69ac2f51062 \
      {} +

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge
2023-06-24 10:48:55 +01:00

74 lines
1.8 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.system;
in
{
options = {
system.patches = mkOption {
type = types.listOf types.path;
default = [ ];
example = literalExpression ''
[
(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}`/`.
::: {.warning}
This can modify everything so use with caution.
:::
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.runCommand "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
for f in $(ls /run/current-system/patches 2> /dev/null); do
if test ! -e "${config.system.build.patches}/patches/$f"; then
patch --force --reverse --backup -d / -p1 < "/run/current-system/patches/$f" || true
fi
done
${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}
'';
};
}