summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/builders.nix
diff options
context:
space:
mode:
Diffstat (limited to 'krebs/5pkgs/builders.nix')
-rw-r--r--krebs/5pkgs/builders.nix77
1 files changed, 58 insertions, 19 deletions
diff --git a/krebs/5pkgs/builders.nix b/krebs/5pkgs/builders.nix
index 924e0c086..da7052f38 100644
--- a/krebs/5pkgs/builders.nix
+++ b/krebs/5pkgs/builders.nix
@@ -74,33 +74,59 @@ rec {
writeOut = name: specs0:
let
- specs = mapAttrsToList (path0: spec0: rec {
- path = guard {
- type = types.pathname;
- value = path0;
- };
- var = "file_${hashString "sha1" path}";
- text = spec0.text;
- executable = guard {
- type = types.bool;
- value = spec0.executable or false;
+ writers.link =
+ { path
+ , link
+ }:
+ assert path == "" || types.absolute-pathname.check path;
+ assert types.package.check link;
+ {
+ install = /* sh */ ''
+ ${optionalString (dirOf path != "/") /* sh */ ''
+ ${pkgs.coreutils}/bin/mkdir -p $out${dirOf path}
+ ''}
+ ${pkgs.coreutils}/bin/ln -s ${link} $out${path}
+ '';
};
- mode = guard {
- type = types.file-mode;
- value = spec0.mode or (if executable then "0755" else "0644");
+
+ writers.text =
+ { path
+ , executable ? false
+ , mode ? if executable then "0755" else "0644"
+ , text
+ }:
+ assert path == "" || types.absolute-pathname.check path;
+ assert types.bool.check executable;
+ assert types.file-mode.check mode;
+ rec {
+ var = "file_${hashString "sha1" path}";
+ val = text;
+ install = /* sh */ ''
+ ${pkgs.coreutils}/bin/install -m ${mode} -D ''$${var}Path $out${path}
+ '';
};
- }) specs0;
- filevars = genAttrs' specs (spec: nameValuePair spec.var spec.text);
+ write = spec: writers.${spec.type} (removeAttrs spec ["type"]);
+
+ specs =
+ mapAttrsToList
+ (path: spec: let
+ known-types = [ "link" "text" ];
+ found-types = attrNames (getAttrs known-types spec);
+ type = assert length found-types == 1; head found-types;
+ in spec // { inherit path type; })
+ specs0;
+
+ files = map write specs;
+
+ filevars = genAttrs' (filter (hasAttr "var") files)
+ (spec: nameValuePair spec.var spec.val);
env = filevars // { passAsFile = attrNames filevars; };
in
pkgs.runCommand name env /* sh */ ''
set -efu
- PATH=${makeBinPath [pkgs.coreutils]}
- ${concatMapStrings (spec: /* sh */ ''
- install -m ${spec.mode} -D ''$${spec.var}Path $out${spec.path}
- '') specs}
+ ${concatMapStringsSep "\n" (getAttr "install") files}
'';
writeHaskell =
@@ -205,6 +231,17 @@ rec {
'';
};
+ writeJq = name: src: pkgs.runCommand name {} /* sh */ ''
+ name=${assert types.filename.check name; name}
+ src=${shell.escape src}
+
+ # syntax check
+ printf '%s' "$src" > src.jq
+ ${pkgs.jq}/bin/jq -f src.jq < /dev/null
+
+ cp src.jq "$out"
+ '';
+
writeNixFromCabal =
trace (toString [
"The function `writeNixFromCabal` has been deprecated in favour of"
@@ -213,4 +250,6 @@ rec {
(name: path: pkgs.runCommand name {} /* sh */ ''
${pkgs.cabal2nix}/bin/cabal2nix ${path} > $out
'');
+
+ writeSed = makeScriptWriter "${pkgs.gnused}/bin/sed -f";
}
[cgit] Unable to lock slot /tmp/cgit/57300000.lock: No such file or directory (2)