From 6ef8900af4bca2901f00c718e3ac8ba457348451 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 26 Oct 2021 13:05:49 +0200 Subject: populate file: admit derivations --- README.md | 2 ++ ci.nix | 4 ++-- lib/types/populate.nix | 8 ++++++-- pkgs/populate/default.nix | 19 +++++++++++++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e9b15b3..d868768 100644 --- a/README.md +++ b/README.md @@ -217,6 +217,8 @@ Supported attributes: whether a file has changed. This is useful when `path` points at files with mangled timestamps, e.g. the Nix store. + The default value is `true` if `path` is a derivation, and `false` otherwise. + * `filters` (optional) List of filters that should be passed to [`rsync`](https://rsync.samba.org/). Filters are specified as attribute sets with the attributes `type` and diff --git a/ci.nix b/ci.nix index 258a4e6..c57f4d7 100644 --- a/ci.nix +++ b/ci.nix @@ -5,7 +5,7 @@ let pkgs = import "${krops}/pkgs" {}; source = lib.evalSource [{ - nixos-config.file = toString (pkgs.writeText "nixos-config" '' + nixos-config.file = pkgs.writeText "nixos-config" '' { pkgs, ... }: { fileSystems."/" = { device = "/dev/sda1"; }; @@ -13,7 +13,7 @@ let services.openssh.enable = true; environment.systemPackages = [ pkgs.git ]; } - ''); + ''; nixpkgs.symlink = toString ; }]; in { diff --git a/lib/types/populate.nix b/lib/types/populate.nix index 894b8cc..18b5cd8 100644 --- a/lib/types/populate.nix +++ b/lib/types/populate.nix @@ -21,11 +21,15 @@ }; file = lib.mkOption { apply = x: - if lib.types.absolute-pathname.check x + if lib.types.absolute-pathname.check x || lib.types.package.check x then { path = x; } else x; default = null; - type = lib.types.nullOr (lib.types.either lib.types.absolute-pathname source-types.file); + type = lib.types.nullOr (lib.types.oneOf [ + lib.types.absolute-pathname + lib.types.package + source-types.file + ]); }; git = lib.mkOption { default = null; diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index d86d949..3be1932 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -45,10 +45,21 @@ let ''; pop.file = target: source: let - config = rsyncDefaultConfig // sourceConfig; - sourceConfig = getAttrs (attrNames rsyncDefaultConfig) source; + config = rsyncDefaultConfig // derivedConfig // sourceConfig; + derivedConfig = { + useChecksum = + if isDerivation source.path + then true + else rsyncDefaultConfig.useChecksum; + }; + sourceConfig = + filterAttrs (name: _: elem name (attrNames rsyncDefaultConfig)) source; + sourcePath = + if isDerivation source.path + then quote (toString source.path) + else quote source.path; in - rsync' target config (quote source.path); + rsync' target config sourcePath; pop.git = target: source: runShell target /* sh */ '' set -efu @@ -198,7 +209,7 @@ let useChecksum = false; exclude = []; filters = []; - deleteExcluded = true + deleteExcluded = true; }; runShell = target: command: -- cgit v1.2.3