aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md3
-rw-r--r--README.md17
-rw-r--r--ci.nix6
-rw-r--r--lib/default.nix5
-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
-rw-r--r--tests/scenarios.nix7
10 files changed, 75 insertions, 69 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 642c8a6..ea60f0b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,8 @@
- `lib/with.nix` is krops' lib without nixpkgs' lib, which it takes from
its caller, e.g. a flake's `nixpkgs.lib`. `pkgs.krops`, `pkgs.populate`
and krops' flake use the nixpkgs lib they get, instead of
- `<nixpkgs/lib>`, which `lib/default.nix` still merges with krops' lib.
+ `<nixpkgs/lib>`. `lib/default.nix` stays for backwards compatibility,
+ merging `<nixpkgs/lib>`, builtins, and `lib/with.nix`.
- A `passage` source's `identities_file` defaults to
`~/.passage/identities` when populate runs, instead of during
evaluation.
diff --git a/README.md b/README.md
index d71a6d0..2fb83b5 100644
--- a/README.md
+++ b/README.md
@@ -24,10 +24,10 @@ let
sha256 = "07mg3iaqjf1w49vmwfchi7b1w55bh7rvsbgicp2m47gnj9alwdb6";
};
- lib = import "${krops}/lib";
pkgs = import "${krops}/pkgs" {};
+ klib = import "${krops}/lib/with.nix" { inherit (pkgs) lib; };
- source = lib.evalSource [{
+ source = klib.evalSource [{
nixpkgs.git = {
clean.exclude = ["/.version-suffix"];
ref = "4b4bbce199d3b3a8001ee93495604289b01aaad3";
@@ -75,9 +75,8 @@ machine that uses them.
krops' flake provides `populate`, `writeDeploy`, and the other functions
described below as `lib.<system>`, and its `lib` directory provides
-`evalSource` and `mkTarget`. `lib/with.nix` is a function taking nixpkgs'
-lib, as below; `lib/default.nix` merges it, with `<nixpkgs/lib>`, into
-nixpkgs' lib and builtins:
+`evalSource` and `mkTarget` in `lib/with.nix`, krops' lib, a function
+taking nixpkgs' lib:
```nix
{
@@ -87,12 +86,12 @@ nixpkgs' lib and builtins:
outputs = { self, krops, nixpkgs, ... }: let
system = "x86_64-linux";
- lib = import "${krops}/lib/with.nix" { inherit (nixpkgs) lib; };
+ klib = import "${krops}/lib/with.nix" { inherit (nixpkgs) lib; };
in {
apps.${system}.deploy = {
type = "app";
program = toString (krops.lib.${system}.writeDeploy "deploy" {
- source = lib.evalSource [{
+ source = klib.evalSource [{
nixos-config.file = toString ./configuration.nix;
nixpkgs.flake-input = { url = toString self; name = "nixpkgs"; };
}];
@@ -142,7 +141,7 @@ Example:
```nix
pkgs.krops.writeDeploy "deploy" {
source = /* ... */;
- target = lib.mkTarget "user@host/path" // {
+ target = klib.mkTarget "user@host/path" // {
extraOptions = [
"-o" "LogLevel=DEBUG"
["-i" "/path/to/identity/file"]
@@ -325,7 +324,7 @@ that means.
## Source Types
-`lib.evalSource` turns sources, written in Nix, into what `pkgs.populate`
+`klib.evalSource` turns sources, written in Nix, into what `pkgs.populate`
passes to populate. [populate's
README](pkgs/populate/README.md#source-types) describes the source types:
`derivation`, `file`, `flake`, `flake-input`, `git`, `pass`, `passage`,
diff --git a/ci.nix b/ci.nix
index c57f4d7..d492eff 100644
--- a/ci.nix
+++ b/ci.nix
@@ -1,10 +1,10 @@
let
krops = ./.;
- lib = import "${krops}/lib";
pkgs = import "${krops}/pkgs" {};
+ klib = import "${krops}/lib/with.nix" { inherit (pkgs) lib; };
- source = lib.evalSource [{
+ source = klib.evalSource [{
nixos-config.file = pkgs.writeText "nixos-config" ''
{ pkgs, ... }: {
@@ -20,6 +20,6 @@ in {
test = pkgs.krops.writeTest "test" {
force = true;
source = source;
- target = "${lib.getEnv "HOME"}/krops-test";
+ target = "${builtins.getEnv "HOME"}/krops-test";
};
}
diff --git a/lib/default.nix b/lib/default.nix
index 89788e4..46afaae 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -1,5 +1,6 @@
-# krops' lib: nixpkgs' lib from <nixpkgs/lib>, builtins, and what krops
-# defines, see ./with.nix, which takes nixpkgs' lib from its caller instead.
+# krops' lib as krops 1 had it, for backwards compatibility: nixpkgs' lib
+# from <nixpkgs/lib>, builtins, and krops' own lib, ./with.nix, which krops
+# uses, with nixpkgs' lib from its caller.
let
lib = import <nixpkgs/lib>;
in
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
{
diff --git a/tests/scenarios.nix b/tests/scenarios.nix
index ad4617d..e61d25b 100644
--- a/tests/scenarios.nix
+++ b/tests/scenarios.nix
@@ -4,7 +4,12 @@
# and targets, which give the target of each kind for a path.
{ targets, ... }@args:
-with import ../pkgs/populate/tests/builder.nix (removeAttrs args [ "targets" ]);
+let
+ inherit (args) lib gitHead gitUrl;
+ inherit (lib) concatStringsSep optional optionalAttrs optionals optionalString;
+ inherit (import ../pkgs/populate/tests/builder.nix (removeAttrs args [ "targets" ]))
+ alt drawInputs matrix scenario targetKinds twice;
+in
{