diff options
| author | tv <tv@krebsco.de> | 2026-11-14 00:27:45 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-14 01:46:01 +0100 |
| commit | a4540a584d762b000b21cb7e61987c414eb72a1d (patch) | |
| tree | 077bb7dfc4d104e5e133ad96c4485ff99bcd14c5 /pkgs/populate/checks.nix | |
| parent | 8f08426ae3a2e5f0ecc5d010bc6469b41e3d7678 (diff) | |
populate: layer populate below krops
populate is a program of its own, with a Nix library, in pkgs/populate,
which krops uses, and which doesn't use krops:
- default.nix builds the program, with nix-build there or callPackage,
as pkgs.populate-unwrapped.
- lib is populate's Nix library: the types of sources and the POSIX
types they use, evalSource, flakeFollows, hasGeneratedFlake, and
derivesFlake, taking nixpkgs' lib. krops' lib takes them from there,
so it provides them as before, and so does lib/types.
pkgs.populate, the function from populate's arguments to a script
running the program, is krops' own, in pkgs/krops/populate.nix, with
checks.nix next to it. It takes the program as populate-unwrapped,
which callPackage passes from the overlay; the flake, whose nixpkgs
lacks it, passes its own.
Diffstat (limited to 'pkgs/populate/checks.nix')
| -rw-r--r-- | pkgs/populate/checks.nix | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/pkgs/populate/checks.nix b/pkgs/populate/checks.nix deleted file mode 100644 index 22b45c9..0000000 --- a/pkgs/populate/checks.nix +++ /dev/null @@ -1,66 +0,0 @@ -# Checks of populate's arguments during evaluation. Each returns true, or -# throws an error naming what's wrong. -with import ../../lib; - -{ - # Populate replaces and removes what's at the target paths of sources, so - # it refuses names that lead out of the target directory, to the directory - # itself, or to its own state. The remaining names are portable file - # names, which mean themselves to shells, find, and in URLs, and which the - # names of the scripts populating the sources may contain. - checkSourceName = name: - if elem name [ "." ".." ".populate" ] || - builtins.match "[0-9A-Za-z._][0-9A-Za-z._-]*" name == null then - throw "krops: source name ${toJSON name} can't be used: it must consist of letters, digits, and the characters ._-, not start with -, and be neither ., .., nor .populate" - else - true; - - # Populate removes what it finds in the target directory, so it refuses - # paths that aren't absolute, that are the root directory, or that the - # target would resolve to another directory than the one they name. - checkTargetPath = path: let - components = filter (x: x != "" && x != ".") (splitString "/" path); - in - if !isString path || substring 0 1 path != "/" then - throw "krops: target path ${toJSON path} can't be used: it must be absolute" - else if components == [] then - throw "krops: target path ${toJSON path} can't be used: it must not be the root directory" - else if elem ".." components || - builtins.match "[^[:cntrl:]]+" path == null then - throw "krops: target path ${toJSON path} can't be used: it must not contain .. or control characters" - else - true; - - # Inputs get drawn from other sources, so they must exist, and drawing - # must not go round in circles. - checkInputs = source: let - drawnFrom = name: map (x: x.source) (flakeFollows source.${name}); - check = name: from: - if from == name then - throw "krops: source ${name} draws inputs from itself" - else if !(source ? ${from}) then - throw "krops: source ${name} draws inputs from missing source ${from}" - else - true; - sorted = toposort (a: b: elem a (drawnFrom b)) (attrNames source); - in - all (name: all (check name) (drawnFrom name)) (attrNames source) && - (if sorted ? cycle then - throw "krops: sources draw inputs from each other: ${toString sorted.cycle}" - else - true); - - # nix copy logs in as the target's user, so populate can't copy flakes to - # remote targets using sudo, which flake and flake-input sources without - # fetchOnTarget do. - checkCopyingWithSudo = target: source: let - copies = name: let s = source.${name}; in - elem s.type [ "flake" "flake-input" ] && - !(s.${s.type}.fetchOnTarget or false); - name = findFirst copies null (attrNames source); - in - if name != null && target.sudo or false && !isLocalTarget target then - throw "krops: source ${target.path}/${name}: copying flakes to targets with sudo is not supported" - else - true; -} |
