diff options
author | tv <tv@krebsco.de> | 2020-02-18 14:36:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-18 14:36:30 +0100 |
commit | ed9fc6658226b1525bc008205d76276f0054c6c5 (patch) | |
tree | 1047d711c21c7cf5c0c5026f2159ad0453fc2a0b | |
parent | 8161ec736759a7f21d9d6ec6e5ff8189df9ebbe7 (diff) | |
parent | 56d4dc28b325503c8b0261e2c12bdbaecc6903b9 (diff) |
Merge pull request #15 from nyantec/feature/filters
support for include filters
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | lib/types/populate.nix | 34 | ||||
-rw-r--r-- | pkgs/populate/default.nix | 7 |
3 files changed, 50 insertions, 2 deletions
@@ -157,6 +157,17 @@ Supported attributes: manual](https://download.samba.org/pub/rsync/rsync.html) for further information. +* `filters` (optional) + List of filters that should be passed to rsync. Filters are specified as + attribute sets with the attributes `type` and `pattern`. Supported filter + types are `include` and `exclude`. This allows for more advanced + configurations. + +* `deleteExcluded` (optional) + boolean that controls whether the excluded directories should be deleted + if they exist on the target. This is passed to the `--delete-excluded` option + of rsync. Defaults to `true`. + ### `git` diff --git a/lib/types/populate.nix b/lib/types/populate.nix index e23ddb0..0427dbd 100644 --- a/lib/types/populate.nix +++ b/lib/types/populate.nix @@ -54,6 +54,18 @@ }; }); + filter = lib.types.submodule { + options = { + type = lib.mkOption { + type = lib.types.enum ["include" "exclude"]; + default = "exclude"; + }; + pattern = lib.mkOption { + type = lib.types.str; + }; + }; + }; + source-types = { derivation = lib.types.submodule { options = { @@ -76,6 +88,28 @@ default = []; example = [".git"]; }; + filters = lib.mkOption { + type = lib.types.listOf filter; + default = []; + example = [ + { + type = "include"; + pattern = "*.nix"; + } + { + type = "include"; + pattern = "*/"; + } + { + type = "exclude"; + pattern = "*"; + } + ]; + }; + deleteExcluded = lib.mkOption { + default = true; + type = lib.types.bool; + }; }; }; git = lib.types.submodule { diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index 736376e..78bf3c8 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -45,7 +45,7 @@ let ''; pop.file = target: source: let - configAttrs = ["useChecksum" "exclude"]; + configAttrs = ["useChecksum" "exclude" "filters" "deleteExcluded"]; config = filterAttrs (name: _: elem name configAttrs) source; in rsync' target config (quote source.path); @@ -161,9 +161,12 @@ let ${concatMapStringsSep " " (pattern: /* sh */ "--exclude ${quote pattern}") (config.exclude or [])} \ + ${concatMapStringsSep " " + (filter: /* sh */ "--${filter.type} ${quote filter.pattern}") + (config.filters or [])} \ -e ${quote (ssh' target)} \ -vFrlptD \ - --delete-excluded \ + ${optionalString (config.deleteExcluded or true) /* sh */ "--delete-excluded"} \ "$source_path" \ ${quote ( optionalString (!isLocalTarget target) ( |