From a63ea35a7d4f1e33f9b56e6637dea441ab9783f7 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Sun, 7 Jan 2018 20:50:13 +0300 Subject: Refactor writeFoo to use writeTextFile --- modules/pkgs/writeBashScript.nix | 28 ++++++++++++++++++---------- modules/pkgs/writePHPFile.nix | 16 ++++++++-------- modules/pkgs/writeXML.nix | 19 ++++++++++--------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/modules/pkgs/writeBashScript.nix b/modules/pkgs/writeBashScript.nix index 15e81c5..b193122 100644 --- a/modules/pkgs/writeBashScript.nix +++ b/modules/pkgs/writeBashScript.nix @@ -1,13 +1,21 @@ -{ bash, writeScript, haskellPackages, runCommand }: +{ bash, writeTextFile, haskellPackages }: -name: text: let - f = writeScript name '' - #!${bash}/bin/bash - ${text} - ''; + + shellcheck = haskellPackages.ShellCheck; + in -runCommand name { } '' - ${haskellPackages.ShellCheck}/bin/shellcheck ${f} - cp -a ${f} $out -'' + +name: text: + writeTextFile + { + inherit name; + executable = true; + text = '' + #!${bash}/bin/bash + ${text} + ''; + checkPhase = '' + ${shellcheck}/bin/shellcheck "$out" + ''; + } diff --git a/modules/pkgs/writePHPFile.nix b/modules/pkgs/writePHPFile.nix index e031efe..495083f 100644 --- a/modules/pkgs/writePHPFile.nix +++ b/modules/pkgs/writePHPFile.nix @@ -1,10 +1,10 @@ -{ php, writeText, runCommand }: +{ writeTextFile, php }: name: text: -let - f = writeText name text; -in -runCommand name { } '' - ${php}/bin/php -l '${f}' - cp -a '${f}' $out -'' + writeTextFile + { + inherit name text; + checkPhase = '' + ${php}/bin/php -l "$out" + ''; + } diff --git a/modules/pkgs/writeXML.nix b/modules/pkgs/writeXML.nix index 1cfc075..9ad3826 100644 --- a/modules/pkgs/writeXML.nix +++ b/modules/pkgs/writeXML.nix @@ -1,11 +1,12 @@ -{ writeText, runCommand, libxml2 }: +{ writeTextFile, libxml2 }: name: text: - let - f = writeText "${name}.raw" text; - in - runCommand name { } '' - ${libxml2}/bin/xmllint \ - --format --noblanks --nocdata ${f} \ - > $out - '' + writeTextFile + { + inherit name text; + checkPhase = '' + ${libxml2.bin}/bin/xmllint \ + --format --noblanks --nocdata "$out" > linted + mv linted "$out" + ''; + } -- cgit v1.2.3