aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-14 04:09:35 +0000
committertv <tv@krebsco.de>2026-11-14 06:23:52 +0100
commit36181e19ccef8d86d53dc5d504eb382c7d9b25fe (patch)
treeecc3e5463ecabe1086ed748335f95fda820191ad /pkgs
parent4ac279ac50b2a842b08d39a875c7c1b89998fd13 (diff)
krops: use lib/with.nix everywhere, and no with
lib/default.nix is for backwards compatibility only, so the examples in the README and ci.nix use lib/with.nix, as klib, with nixpkgs' lib from pkgs. pkgs.populate and its checks name what they use from nixpkgs' lib, builtins, and klib, instead of bringing them into scope with with, and the scenarios inherit what they use from the builder and nixpkgs' lib, which the builder doesn't pass on anymore. Nix tells undefined names when parsing then, and a name means the same wherever it's used. The derivations and the scenarios stay the same.
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/krops/checks.nix34
-rw-r--r--pkgs/krops/populate.nix53
-rw-r--r--pkgs/populate/tests/builder.nix4
-rw-r--r--pkgs/populate/tests/default.nix7
-rw-r--r--pkgs/populate/tests/scenarios.nix8
5 files changed, 53 insertions, 53 deletions
diff --git a/pkgs/krops/checks.nix b/pkgs/krops/checks.nix
index c6e0da7..d9026fe 100644
--- a/pkgs/krops/checks.nix
+++ b/pkgs/krops/checks.nix
@@ -2,9 +2,9 @@
# throws an error naming what's wrong. lib is nixpkgs' lib.
{ lib }:
-with lib;
-with builtins;
-with import ../../lib/with.nix { inherit lib; };
+let
+ klib = import ../../lib/with.nix { inherit lib; };
+in
{
# Populate replaces and removes what's at the target paths of sources, so
@@ -13,9 +13,9 @@ with import ../../lib/with.nix { inherit lib; };
# 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" ] ||
+ if builtins.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"
+ throw "krops: source name ${builtins.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;
@@ -23,22 +23,22 @@ with import ../../lib/with.nix { inherit lib; };
# 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);
+ components = builtins.filter (x: x != "" && x != ".") (lib.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"
+ if !builtins.isString path || builtins.substring 0 1 path != "/" then
+ throw "krops: target path ${builtins.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 ||
+ throw "krops: target path ${builtins.toJSON path} can't be used: it must not be the root directory"
+ else if builtins.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"
+ throw "krops: target path ${builtins.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});
+ drawnFrom = name: map (x: x.source) (klib.flakeFollows source.${name});
check = name: from:
if from == name then
throw "krops: source ${name} draws inputs from itself"
@@ -46,9 +46,9 @@ with import ../../lib/with.nix { inherit lib; };
throw "krops: source ${name} draws inputs from missing source ${from}"
else
true;
- sorted = toposort (a: b: elem a (drawnFrom b)) (attrNames source);
+ sorted = lib.toposort (a: b: builtins.elem a (drawnFrom b)) (builtins.attrNames source);
in
- all (name: all (check name) (drawnFrom name)) (attrNames source) &&
+ builtins.all (name: builtins.all (check name) (drawnFrom name)) (builtins.attrNames source) &&
(if sorted ? cycle then
throw "krops: sources draw inputs from each other: ${toString sorted.cycle}"
else
@@ -59,11 +59,11 @@ with import ../../lib/with.nix { inherit lib; };
# fetchOnTarget do.
checkCopyingWithSudo = target: source: let
copies = name: let s = source.${name}; in
- elem s.type [ "flake" "flake-input" ] &&
+ builtins.elem s.type [ "flake" "flake-input" ] &&
!(s.${s.type}.fetchOnTarget or false);
- name = findFirst copies null (attrNames source);
+ name = lib.findFirst copies null (builtins.attrNames source);
in
- if name != null && target.sudo or false && !isLocalTarget target then
+ if name != null && target.sudo or false && !klib.isLocalTarget target then
throw "krops: source ${target.path}/${name}: copying flakes to targets with sudo is not supported"
else
true;
diff --git a/pkgs/krops/populate.nix b/pkgs/krops/populate.nix
index c887e04..83da9a6 100644
--- a/pkgs/krops/populate.nix
+++ b/pkgs/krops/populate.nix
@@ -6,17 +6,14 @@
, ...
}@args:
-with lib;
-with builtins;
-with import ../../lib/with.nix { inherit lib; };
-
let
+ klib = import ../../lib/with.nix { inherit lib; };
checks = import ./checks.nix { inherit lib; };
# Arguments populate doesn't use, which overrides written for krops 1 may
# set. They come through ..., because callPackage would set named ones.
- unused = filter (name: args ? ${name}) [ "dash" "implementation" "jq" ];
- unexpected = attrNames (removeAttrs args ([
+ unused = builtins.filter (name: args ? ${name}) [ "dash" "implementation" "jq" ];
+ unexpected = builtins.attrNames (removeAttrs args ([
"coreutils" "findutils" "git" "lib" "nix" "openssh" "pass" "passage"
"rsync" "writers" "populate-unwrapped"
] ++ unused));
@@ -24,10 +21,10 @@ let
# The parts of a target string, like mkTarget parses it, without its
# defaults, which populate fills in when it runs.
parseTarget = s: let
- parts = match "(([^@]*)@)?(([^:/]+))?(:([^/]+))?(/.*)?" s;
+ parts = builtins.match "(([^@]*)@)?(([^:/]+))?(:([^/]+))?(/.*)?" s;
in
- if parts == null then throw "krops: invalid target ${toJSON s}"
- else { host = elemAt parts 3; path = elemAt parts 6; };
+ if parts == null then throw "krops: invalid target ${builtins.toJSON s}"
+ else { host = builtins.elemAt parts 3; path = builtins.elemAt parts 6; };
populate =
{ backup ? false, force ? false, prune ? false, source, target }:
@@ -37,28 +34,28 @@ let
# it, goes part by part, with whether it's local decided now, like the
# other functions of krops do.
parsed = parseTarget target;
- path = if isString target then (if parsed.path != null then parsed.path else "/var/src") else target.path;
- host = if isString target then (if parsed.host != null then parsed.host else "localhost") else target.host;
+ path = if builtins.isString target then (if parsed.path != null then parsed.path else "/var/src") else target.path;
+ host = if builtins.isString target then (if parsed.host != null then parsed.host else "localhost") else target.host;
targetArgs =
- if isString target then [ target ]
+ if builtins.isString target then [ target ]
else [
"--user" (if target.user or null == null then "" else target.user)
"--host" target.host
"--path" target.path
- ] ++ optionals (target.port or null != null) [
+ ] ++ lib.optionals (target.port or null != null) [
"--port" (toString target.port)
- ] ++ optional (target.sudo or false) "--sudo"
- ++ concatMap (arg: [ "--ssh-arg" arg ]) (flatten (target.extraOptions or []))
- ++ [ (if isLocalTarget target then "--local" else "--remote") ];
+ ] ++ lib.optional (target.sudo or false) "--sudo"
+ ++ builtins.concatMap (arg: [ "--ssh-arg" arg ]) (lib.flatten (target.extraOptions or []))
+ ++ [ (if klib.isLocalTarget target then "--local" else "--remote") ];
in
assert checks.checkTargetPath path;
- assert all checks.checkSourceName (attrNames source);
+ assert builtins.all checks.checkSourceName (builtins.attrNames source);
assert checks.checkInputs source;
- assert isString target || checks.checkCopyingWithSudo target source;
+ assert builtins.isString target || checks.checkCopyingWithSudo target source;
writers.writeDash "populate.${host}" /* sh */ ''
set -efu
echo + "$0" >&2
- PATH=${makeBinPath [
+ PATH=${lib.makeBinPath [
coreutils findutils git nix openssh pass passage rsync
]}''${PATH:+:$PATH}
export PATH
@@ -66,21 +63,21 @@ let
# populate runs keep standard input. Store paths in them stay
# dependencies of this script, so building it builds them. The JSON is
# a single line, which can't be the delimiter.
- exec ${populate-unwrapped}/bin/populate ${escapeShellArgs (
- optional backup "--backup" ++
- optional force "--force" ++
- optional prune "--prune"
- )} /dev/fd/3 ${escapeShellArgs targetArgs} 3<<'EOF'
- ${toJSON source}
+ exec ${populate-unwrapped}/bin/populate ${lib.escapeShellArgs (
+ lib.optional backup "--backup" ++
+ lib.optional force "--force" ++
+ lib.optional prune "--prune"
+ )} /dev/fd/3 ${lib.escapeShellArgs targetArgs} 3<<'EOF'
+ ${builtins.toJSON source}
EOF
'';
in
if unexpected != [] then
- throw "krops: populate called with unexpected argument ${head unexpected}"
+ throw "krops: populate called with unexpected argument ${builtins.head unexpected}"
else
- foldr
- (name: warn "krops: populate's argument ${name} is unused")
+ lib.foldr
+ (name: lib.warn "krops: populate's argument ${name} is unused")
populate
unused
diff --git a/pkgs/populate/tests/builder.nix b/pkgs/populate/tests/builder.nix
index 91609a9..e06081a 100644
--- a/pkgs/populate/tests/builder.nix
+++ b/pkgs/populate/tests/builder.nix
@@ -240,10 +240,6 @@ let
};
in {
- inherit lib url gitUrl remoteHost agePath gitHead gitFirst rsyncVersion;
- inherit (lib)
- attrNames concatMap concatStringsSep foldl' isBool mapAttrsToList
- optional optionalAttrs optionals optionalString;
inherit
prelude cartesian flagsName alt targetName
inputModes drawInputs flakeOf scenario twice
diff --git a/pkgs/populate/tests/default.nix b/pkgs/populate/tests/default.nix
index 7b37bb3..3399c77 100644
--- a/pkgs/populate/tests/default.nix
+++ b/pkgs/populate/tests/default.nix
@@ -40,9 +40,10 @@ let
if deploy != null then throw "populate's tests don't deploy" else
pkgs.writers.writeDash "populate" /* sh */ ''
set -efu
- PATH=${lib.makeBinPath (with pkgs; [
- coreutils findutils git nix openssh pass passage rsync
- ])}''${PATH:+:$PATH}
+ PATH=${lib.makeBinPath [
+ pkgs.coreutils pkgs.findutils pkgs.git pkgs.nix pkgs.openssh pkgs.pass
+ pkgs.passage pkgs.rsync
+ ]}''${PATH:+:$PATH}
export PATH
exec ${populate-unwrapped}/bin/populate ${lib.escapeShellArgs (
lib.optional backup "--backup" ++
diff --git a/pkgs/populate/tests/scenarios.nix b/pkgs/populate/tests/scenarios.nix
index 223839b..4b7a42b 100644
--- a/pkgs/populate/tests/scenarios.nix
+++ b/pkgs/populate/tests/scenarios.nix
@@ -4,7 +4,13 @@
# sources. The arguments are those of builder.nix, which builds them.
args:
-with import ./builder.nix args;
+let
+ inherit (args) lib agePath gitFirst gitHead gitUrl rsyncVersion url;
+ inherit (lib) concatMap optional optionalAttrs optionalString;
+ inherit (import ./builder.nix args)
+ alt checkFlake copyingWithSudo drawInputs flakeOf inputModes matrix
+ refuseCopyingWithSudo scenario targetKinds targetName twice;
+in
{