diff options
author | Justin Bedo <cu@cua0.org> | 2021-10-29 17:39:01 +1100 |
---|---|---|
committer | Justin Bedo <cu@cua0.org> | 2021-10-29 17:39:01 +1100 |
commit | bac9248a5e08e8afdf5485a6e27cfe72e1ca5090 (patch) | |
tree | 8719a280b56122017d46b582cd3da8547dd3f548 | |
parent | ab809b8c77efdad9fb54d3591a0193a1cbe888d1 (diff) |
treewide reformatting and simplification
- simplify with statix
- reformat with nixpkgs-fmt
104 files changed, 936 insertions, 802 deletions
diff --git a/default.nix b/default.nix index 1944de0..59357b2 100644 --- a/default.nix +++ b/default.nix @@ -5,10 +5,11 @@ let bionix = nixpkgs.lib.makeExtensible (self: let callBionix = file: attrs: import file ({ bionix = self; } // attrs); - in with self; { - callBionix = callBionix; + in + with self; { + inherit callBionix; id = x: x; - exec = f: x: y: f x y; + exec = id; exec' = f: exec (_: f) { }; exec'' = f: exec' (_: f) { }; callBionixE = p: exec (callBionix p); @@ -52,15 +53,17 @@ let slurm-run = callPackage ./lib/slurm.nix { }; slurm-exec = f: x: y: - slurm-run x (f (builtins.removeAttrs x [ - "ppn" - "mem" - "walltime" - "partition" - "slurmFlags" - "salloc" - "srun" - ]) y); + slurm-run x (f + (builtins.removeAttrs x [ + "ppn" + "mem" + "walltime" + "partition" + "slurmFlags" + "salloc" + "srun" + ]) + y); slurm = bionix.extend (self: super: { exec = super.slurm-run; }); qsub = attrs: bionix.extend (self: super: @@ -78,7 +81,8 @@ let qsub = attrs: (callPackage ./lib/qsub.nix { }) (qsubDefs // attrs); exec = f: x: y: qsub (builtins.intersectAttrs qsubDefs x) (super.exec f - (builtins.removeAttrs x (builtins.attrNames qsubDefs)) y); + (builtins.removeAttrs x (builtins.attrNames qsubDefs)) + y); }); def = f: defs: attrs: f (defs // attrs); @@ -88,22 +92,24 @@ let name = "link-outputs"; outputs = [ "out" ] ++ attrNames x; nativeBuildInputs = [ pkgs.perl ]; - buildCommand = let - recurse = x: - if x ? type && x.type == "derivation" then - x - else if builtins.typeOf x == "set" then - linkOutputs x - else - abort "linkOutputs: unsupported type"; - link = dst: src: '' - ln -s ${recurse src} $(perl -e 'print $ENV{"${dst}"}') ; ln -s ${ - recurse src - } $out/${dst} - ''; - in '' - mkdir $out - '' + (concatStringsSep "\n" (mapAttrsToList link x)); + buildCommand = + let + recurse = x: + if x ? type && x.type == "derivation" then + x + else if builtins.typeOf x == "set" then + linkOutputs x + else + abort "linkOutputs: unsupported type"; + link = dst: src: '' + ln -s ${recurse src} $(perl -e 'print $ENV{"${dst}"}') ; ln -s ${ + recurse src + } $out/${dst} + ''; + in + '' + mkdir $out + '' + (concatStringsSep "\n" (mapAttrsToList link x)); passthru.linkInputs = x; }; @@ -127,15 +133,15 @@ let # Export nixpkgs and standard library lib pkgs = nixpkgs; lib = nixpkgs.lib // { - types = types; + inherit types; shard = callBionix ./lib/shard.nix { }; }; stage = x@{ name, stripStorePaths ? true, multicore ? false, ... }: (if stripStorePaths then strip else x: x) - (nixpkgs.stdenvNoCC.mkDerivation (x // { - name = "bionix-" + name; - inherit multicore; - })); + (nixpkgs.stdenvNoCC.mkDerivation (x // { + name = "bionix-" + name; + inherit multicore; + })); strip = drv: let stripCommand = '' @@ -156,7 +162,8 @@ let rewriteOutput $o done ''; - in drv.overrideAttrs (attrs: + in + drv.overrideAttrs (attrs: if attrs ? buildCommand then { buildCommand = attrs.buildCommand + stripCommand; } else { @@ -186,13 +193,15 @@ let overlayByType = { lambda = bionix: overlay: bionix.extend - (self: super: nixpkgs.lib.recursiveUpdate super (overlay self super)); + (self: super: nixpkgs.lib.recursiveUpdate super (overlay self super)); path = bionix: path: overlay bionix (import path); }; overlay = bionix: overlay: let overlayType = builtins.typeOf overlay; - in if overlayByType ? ${overlayType} then - overlayByType.${overlayType} bionix overlay + in + if overlayByType ? "${overlayType}" then + overlayByType."${overlayType}" bionix overlay else builtins.throw ("cannot overlay type " + overlayType); -in with nixpkgs.lib; foldl overlay bionix overlays +in +with nixpkgs.lib; foldl overlay bionix overlays diff --git a/doc/default.nix b/doc/default.nix index d68a6b1..ac8bfeb 100644 --- a/doc/default.nix +++ b/doc/default.nix @@ -1,4 +1,4 @@ -{ bionix ? import ./.. {} }: +{ bionix ? import ./.. { } }: with bionix; diff --git a/examples/call.nix b/examples/call.nix index 8a38fdb..81a112e 100644 --- a/examples/call.nix +++ b/examples/call.nix @@ -2,9 +2,10 @@ # with the Platypus variant caller. Each input is preprocessed by aligning # against a reference genome (defaults to GRCH38), fixing mate information, and # marking duplicates. Finally platypus is called over all samples. -{bionix ? import <bionix> {} -,inputs -,ref ? bionix.ref.grch38.seq }: +{ bionix ? import <bionix> { } +, inputs +, ref ? bionix.ref.grch38.seq +}: with bionix; with lib; @@ -13,9 +14,10 @@ let preprocess = flip pipe [ (bwa.align { inherit ref; }) (samtools.sort { nameSort = true; }) - (samtools.fixmate {}) - (samtools.sort {}) - (samtools.markdup {}) + (samtools.fixmate { }) + (samtools.sort { }) + (samtools.markdup { }) ]; -in platypus.call {} (map preprocess inputs) +in +platypus.call { } (map preprocess inputs) diff --git a/examples/default.nix b/examples/default.nix index 9aace38..ef57341 100644 --- a/examples/default.nix +++ b/examples/default.nix @@ -1,6 +1,6 @@ # This example uses the pipelines specified in the call.nix file on the # synthetic data in this directory. -{bionix ? import <bionix> {}}: +{ bionix ? import <bionix> { } }: with bionix; @@ -15,7 +15,7 @@ let sha256 = "0kh29i6fg14dn0fb1xj6pkpk6d83y7zg7aphkbvjrhm82braqkm8"; }; - input2 = fetchFastQ { + input2 = fetchFastQ { url = "https://github.com/PapenfussLab/bionix/raw/master/examples/sample1-2.fq"; sha256 = "0czk85km6a91y0fn4b7f9q7ps19b5jf7jzwbly4sgznps7ir2kdk"; }; @@ -28,7 +28,7 @@ let sha256 = "08gixavfklqvk1m2ic6v56z82vl00qnpsd9xb64z6zl03nz98mcy"; }; - input2 = fetchFastQ { + input2 = fetchFastQ { url = "https://github.com/PapenfussLab/bionix/raw/master/examples/sample2-2.fq"; sha256 = "1xxwm2vq52axpdhm14rh5mg5nzzpxaqnvhzrqhajm27fqksgzjjw"; }; @@ -41,4 +41,5 @@ let sha256 = "0sy9hq8n55knfkiblam50dzaiwhrx6pv8b8l1njdn6kfj4wflz2p"; }; -in import ./call.nix {inherit inputs ref bionix;} +in +import ./call.nix { inherit inputs ref bionix; } diff --git a/examples/ex-nextflow/nextflow-example1.nix b/examples/ex-nextflow/nextflow-example1.nix index 4f00431..687505c 100644 --- a/examples/ex-nextflow/nextflow-example1.nix +++ b/examples/ex-nextflow/nextflow-example1.nix @@ -1,7 +1,8 @@ # This is a translation of the Nextflow example found at # https://www.nextflow.io/example1.html -{ bionix ? import ./../.. {} -, input ? ./sample.fa}: +{ bionix ? import ./../.. { } +, input ? ./sample.fa +}: with bionix; with lib; @@ -24,7 +25,8 @@ let ''; }; -in pipe input [ +in +pipe input [ splitSequences (each reverse) ] diff --git a/examples/ex-tnpair/cluster.nix b/examples/ex-tnpair/cluster.nix index 8d54995..5d4e1de 100644 --- a/examples/ex-tnpair/cluster.nix +++ b/examples/ex-tnpair/cluster.nix @@ -4,11 +4,12 @@ let bionix = import <bionix> { overlays = [ (_: super: - super."${if tmpDir == null then "slurm" else "qsub"}" { - ppn = 24; - mem = 7; - walltime = "3:00:00"; - } // super.lib.optionalAttrs (tmpDir != null) { inherit tmpDir; }) + super."${if tmpDir == null then "slurm" else "qsub"}" + { + ppn = 24; + mem = 7; + walltime = "3:00:00"; + } // super.lib.optionalAttrs (tmpDir != null) { inherit tmpDir; }) (self: super: with super; { @@ -27,4 +28,5 @@ let }) ]; }; -in import ./. { inherit bionix; } +in +import ./. { inherit bionix; } diff --git a/examples/ex-tnpair/default.nix b/examples/ex-tnpair/default.nix index f9581f8..65a2265 100644 --- a/examples/ex-tnpair/default.nix +++ b/examples/ex-tnpair/default.nix @@ -45,6 +45,7 @@ let fetch = s: mapAttrs (_: fetchFastQGZ) s.inputs; -in import ./tnpair.nix { +in +import ./tnpair.nix { inherit pair fetch bionix; } diff --git a/examples/ex-tnpair/tnpair.nix b/examples/ex-tnpair/tnpair.nix index 9e6befe..414a391 100644 --- a/examples/ex-tnpair/tnpair.nix +++ b/examples/ex-tnpair/tnpair.nix @@ -1,4 +1,4 @@ -{bionix ? import <bionix> {}, pair, fetch}: +{ bionix ? import <bionix> { }, pair, fetch }: with bionix; |