populate file: admit derivations

This commit is contained in:
tv 2021-10-26 13:05:49 +02:00
parent 53eda9cafe
commit 6ef8900af4
4 changed files with 25 additions and 8 deletions

View File

@ -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

4
ci.nix
View File

@ -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 <nixpkgs>;
}];
in {

View File

@ -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;

View File

@ -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: