summary refs log tree commit diff
path: root/pkgs/build-support/trivial-builders.nix
diff options
context:
space:
mode:
authorPasquale <p3dimaria@hotmail.it>2021-11-28 01:28:11 +0100
committerPasquale <p3dimaria@hotmail.it>2021-11-28 01:39:42 +0100
commit0f316ecef2269f084545f137dd880147b5bd492b (patch)
tree69238c860d3ae34284b9c318574f1c2519aa9125 /pkgs/build-support/trivial-builders.nix
parent549025bbedac9080a513507a263a6c06326be62c (diff)
downloadnixpkgs-0f316ecef2269f084545f137dd880147b5bd492b.tar
nixpkgs-0f316ecef2269f084545f137dd880147b5bd492b.tar.gz
nixpkgs-0f316ecef2269f084545f137dd880147b5bd492b.tar.bz2
nixpkgs-0f316ecef2269f084545f137dd880147b5bd492b.tar.lz
nixpkgs-0f316ecef2269f084545f137dd880147b5bd492b.tar.xz
nixpkgs-0f316ecef2269f084545f137dd880147b5bd492b.tar.zst
nixpkgs-0f316ecef2269f084545f137dd880147b5bd492b.zip
concatTextFile: init
nixos/networking: using concatTextFile
Diffstat (limited to 'pkgs/build-support/trivial-builders.nix')
-rw-r--r--pkgs/build-support/trivial-builders.nix65
1 files changed, 65 insertions, 0 deletions
diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix
index 3c9f3189d2c..ee5a492cdc1 100644
--- a/pkgs/build-support/trivial-builders.nix
+++ b/pkgs/build-support/trivial-builders.nix
@@ -322,6 +322,71 @@ rec {
     $CC -x c code.c -o "$n"
     '';
 
+
+  /* concat a list of files to the nix store.
+   * The contents of files are added to the file in the store.
+   *
+   * Examples:
+   * # Writes my-file to /nix/store/<store path>
+   * concatTextFile {
+   *   name = "my-file";
+   *   files = [ drv1 "${drv2}/path/to/file" ];
+   * }
+   * # See also the `concatdText` helper function below.
+   *
+   * # Writes executable my-file to /nix/store/<store path>/bin/my-file
+   * concatTextFile {
+   *   name = "my-file";
+   *   files = ''
+   *     Contents of File
+   *   '';
+   *   executable = true;
+   *   destination = "/bin/my-file";
+   * }
+   */
+  concatTextFile =
+    { name # the name of the derivation
+    , files
+    , executable ? false # run chmod +x ?
+    , destination ? ""   # relative path appended to $out eg "/bin/foo"
+    , checkPhase ? ""    # syntax checks, e.g. for scripts
+    , meta ? { }
+    }:
+    runCommandLocal name
+      { inherit files executable checkPhase meta destination; }
+      ''
+        n=$out$destination
+        mkdir -p "$(dirname "$n")"
+        cat $files > "$n"
+        touch "$n"
+
+        eval "$checkPhase"
+
+        (test -n "$executable" && chmod +x "$n") || true
+      '';
+
+
+  /*
+   * Writes a text file to nix store with no optional parameters available.
+   *
+   * Example:
+   * # Writes contents of files to /nix/store/<store path>
+   * concatText "my-file" [ file1 file2 ]
+   *
+  */
+  concatText = name: files: concatTextFile { inherit name files; };
+
+    /*
+   * Writes a text file to nix store with and mark it as executable.
+   *
+   * Example:
+   * # Writes contents of files to /nix/store/<store path>
+   * concatdScript "my-file" [ file1 file2 ]
+   *
+  */
+  concatScript = name: files: concatTextFile { inherit name files; executable=true; };
+
+
   /*
    * Create a forest of symlinks to the files in `paths'.
    *