default.nix 9.47 KB
Newer Older
Valentin Reis's avatar
Valentin Reis committed
1 2 3 4 5 6
{ # host package set (unused except for fetching nixpkgs)
  hostPkgs        ? import <nixpkgs> {}

, # versioned nixpkgs
  pkgs            ? import (hostPkgs.nix-update-source.fetch ./pkgs.json).src {}

Valentin Reis's avatar
Valentin Reis committed
7 8 9
, # versioned nixpkgs-older version for zmcat
  pkgs-old        ? import (hostPkgs.nix-update-source.fetch ./pkgs-old.json).src {}

Valentin Reis's avatar
Valentin Reis committed
10
, # fetcher alias for the remaining arguments
Valentin Reis's avatar
Valentin Reis committed
11
  fetched         ? s: (pkgs.nix-update-source.fetch s).src
Valentin Reis's avatar
Valentin Reis committed
12 13

, #source overrides: core nrm components
Valentin Reis's avatar
Valentin Reis committed
14 15 16 17
  aml-src         ? fetched aml/pin.json
, libnrm-src      ? fetched libnrm/pin.json
, nrm-src         ? fetched nrm/pin.json
, containers-src  ? fetched containers/pin.json
Valentin Reis's avatar
Valentin Reis committed
18 19

, #source overrides: applications
Valentin Reis's avatar
Valentin Reis committed
20 21 22 23 24
  amg-src         ? fetched amg/pin.json
, qmcpack-src     ? fetched qmcpack/pin.json
, openmc-src      ? fetched openmc/pin.json
, stream-src      ? fetched stream/pin.json
, lammps-src      ? fetched lammps/pin.json
Valentin Reis's avatar
Valentin Reis committed
25

Valentin Reis's avatar
Valentin Reis committed
26
, #source overrides: tooling
27 28 29
  argotk-src       ? builtins.fetchGit {inherit (fetched argotk/pin.json) url rev;}
, repoquality-src  ? builtins.fetchGit {inherit (fetched repoquality/pin.json) url rev;}
, argonix-src      ? builtins.fetchGit {inherit (fetched argonix/pin.json) url rev;}
Valentin Reis's avatar
Valentin Reis committed
30
, experiments-src  ? fetched experiments/pin.json
31 32 33

, #used for hardware experiments.
  sudoPath ? null
Valentin Reis's avatar
Valentin Reis committed
34 35 36

, #whether to rebuild apps when libnrm changes.
  rebuildApps ? true
Valentin Reis's avatar
.  
Valentin Reis committed
37 38
}:
let
Valentin Reis's avatar
Valentin Reis committed
39
  callPackage = pkgs.lib.callPackageWith (pkgs // argopkgs);
40

Valentin Reis's avatar
Valentin Reis committed
41
  argopkgs = rec {
42
    # library of nix expressions
Valentin Reis's avatar
style.  
Valentin Reis committed
43
    argolib       = import ../lib/utils.nix;
44
    # Argo components (source overridabel via argument)
Valentin Reis's avatar
Valentin Reis committed
45 46 47 48 49 50
    aml           = callPackage ./aml        {src=aml-src;};
    nrm           = callPackage ./nrm        {src=nrm-src;};
    containers    = callPackage ./containers {src=containers-src;};
    libnrm        = callPackage ./libnrm     {src=libnrm-src;};
    libnrm-pinned = callPackage ./libnrm     {src=fetched libnrm/pin.json;};
    libnrm-pmpi   = libnrm.overrideAttrs (oldAttrs: rec {
Valentin Reis's avatar
Valentin Reis committed
51 52 53
      configureFlags = "--enable-pmpi";
      buildInputs = oldAttrs.buildInputs ++ [ pkgs.mpich2 ];
    });
54

Valentin Reis's avatar
Valentin Reis committed
55 56 57 58
    # applications with replaceDependency for libnrm.
    repLibnrm = path: src: extra:
    let
      drv = callPackage path {
Valentin Reis's avatar
style.  
Valentin Reis committed
59 60 61
        nrmSupport = true;
        src = src;
        libnrm = libnrm-pinned;
Valentin Reis's avatar
Valentin Reis committed
62
      };
Valentin Reis's avatar
Valentin Reis committed
63
    in if !rebuildApps then drv else pkgs.replaceDependency {
Valentin Reis's avatar
Valentin Reis committed
64 65 66 67 68 69 70 71 72
      drv = drv;
      oldDependency = libnrm-pinned;
      newDependency = libnrm;
    };
    amg          = repLibnrm ./amg     amg-src     {};
    qmcpack      = repLibnrm ./qmcpack qmcpack-src {};
    openmc       = repLibnrm ./openmc  openmc-src  {};
    lammps       = repLibnrm ./lammps  lammps-src  {};
    stream       = repLibnrm ./stream  stream-src  {iterationCount="20000";};
Valentin Reis's avatar
Valentin Reis committed
73

74
    # data (static, non source overridable via arguments)
Valentin Reis's avatar
Valentin Reis committed
75
    openmc-data = fetched openmc/data.json;
Valentin Reis's avatar
Valentin Reis committed
76

77 78 79 80
    # tools
    zymake = callPackage ./zymake {
      inherit (pkgs.ocamlPackages) findlib ocamlbuild topkg batteries;
    };
Valentin Reis's avatar
Valentin Reis committed
81 82
    haskellPackages = pkgs.haskellPackages.override {
      overrides = self: super: with pkgs.haskell.lib;
Valentin Reis's avatar
Valentin Reis committed
83
      rec {
Valentin Reis's avatar
Valentin Reis committed
84
        panpipe        = (pkgs.haskell.lib.doJailbreak super.panpipe);
Valentin Reis's avatar
Valentin Reis committed
85
        spdx           = (pkgs.haskell.lib.doJailbreak super.spdx);
Valentin Reis's avatar
Valentin Reis committed
86
        generic-pretty = doJailbreak super.generic-pretty;
Valentin Reis's avatar
Valentin Reis committed
87

Valentin Reis's avatar
Valentin Reis committed
88 89 90 91 92
        #minor cabal and version fix
        panhandle    = (self.callCabal2nix "panhandle" (builtins.fetchGit {
                      inherit (panhandle-src) url rev; })) {};

        #argo tools
Valentin Reis's avatar
Valentin Reis committed
93 94 95
        argotk = (self.callCabal2nix "argotk" argotk-src) {};
        argonix = (self.callCabal2nix "argonix" argonix-src) {};
        repoquality = (self.callCabal2nix "repoquality" repoquality-src) {};
96
      };
Valentin Reis's avatar
Valentin Reis committed
97
    };
Valentin Reis's avatar
Valentin Reis committed
98

99
    # re-export from hpkgs and add non-haskell build rule specialization
Valentin Reis's avatar
Valentin Reis committed
100 101 102
    inherit (haskellPackages) repoquality;

    argotk = haskellPackages.argotk.overrideAttrs (old:{
Valentin Reis's avatar
Valentin Reis committed
103 104 105 106 107 108 109 110 111 112 113 114
        buildInputs=old.buildInputs ++ [pkgs.hwloc];
        installPhase = old.installPhase + ''
          mkdir $out/share/
          ARGOTK_SHARE=share $out/bin/argotk --bash-completion-script argotk > $out/share/argotk.sh
          cp -r share/* $out/share/
          substituteInPlace $out/share/simple-H2O.xml --replace \
                H2O.HF.wfs.xml $out/share/H2O.HF.wfs.xml
          substituteInPlace $out/share/simple-H2O.xml --replace \
                O.BFD.xml $out/share/O.BFD.xml
          substituteInPlace $out/share/simple-H2O.xml --replace \
                H.BFD.xml $out/share/H.BFD.xml
        '';
Valentin Reis's avatar
Valentin Reis committed
115 116 117 118 119 120 121 122
      });

    argonix = haskellPackages.argonix.overrideAttrs (old:{
        installPhase = old.installPhase + ''
          mkdir $out/share/
          $out/bin/argonix --bash-completion-script argonix > $out/share/argonix.sh
        '';
      });
123

124
    # fix for nrm
Valentin Reis's avatar
Valentin Reis committed
125
    pyzmq = pkgs.pythonPackages.pyzmq.override { zeromq3 = pkgs.zeromq; };
Valentin Reis's avatar
Valentin Reis committed
126

127
    # archived for sake of the simplicity of this file
Valentin Reis's avatar
Valentin Reis committed
128 129
    zmcat = pkgs-old.haskellPackages.callPackage ./zmcat {};
    zmqat = pkgs-old.haskellPackages.zmqat;
130

131
    # ci/experimental environments
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    testBuildInputs =  [
      # argotk runs mpiexec:
      pkgs.mpich2
      # argotk uses hwloc to choose CPU counts:
      pkgs.hwloc
      # these are needed for some reason:
      pkgs.coreutils
      pkgs.utillinux
      pkgs.git
      # argo tools
      argotk
      # argo components
      containers
      nrm
    ];

Valentin Reis's avatar
Valentin Reis committed
148 149
    test = pkgs.stdenv.mkDerivation rec {
      name = "testEnv";
150

Valentin Reis's avatar
Valentin Reis committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164
      buildInputs = [
        # argotk runs mpiexec:
        pkgs.mpich2
        # argotk uses hwloc to choose CPU counts:
        pkgs.hwloc
        # these are needed for some reason:
        pkgs.coreutils
        pkgs.utillinux
        pkgs.git
        # argo tools
        argotk
        # argo components
        containers
        nrm
Valentin Reis's avatar
Valentin Reis committed
165
      ];
166

Valentin Reis's avatar
Valentin Reis committed
167
      #required to be able to build the drv.
168
      installPhase = "mkdir $out";
Valentin Reis's avatar
Valentin Reis committed
169
      unpackPhase = "true";
Valentin Reis's avatar
Valentin Reis committed
170

171 172 173 174 175 176 177
      __noChroot = true;
      shellHook =''
        echo ""
        echo "ENTERING ENVIRONMENT: Sources of impurity for this build are: /tmp/ /etc/argo/ /var/run/ /var/lock/".
        echo "ENTERING ENVIRONMENT: Moreover, sandboxing is disabled, in particular because of:"
        echo "ENTERING ENVIRONMENT: /tmp/nrm-* sockets, /etc/argo, /var/run/, /var/lock/ which all need read access. "
        echo "ENTERING ENVIRONMENT: until these components are patched to allow for alternative paths, no sandbox use is possible."
178
        source ${argotk}/share/argotk.sh # bash completion
179
        echo ""
180
      '';
181
      #argotk uses this environment variable.
182
      ARGOTK_SHARE = "${argotk}/share";
Valentin Reis's avatar
Valentin Reis committed
183 184
      OPENMC_CROSS_SECTIONS = "${openmc-data}/cross_sections.xml";
      OPENMC_PWD = "${argotk}/share/openmc";
Valentin Reis's avatar
Valentin Reis committed
185
    };
Valentin Reis's avatar
Valentin Reis committed
186

Valentin Reis's avatar
Valentin Reis committed
187
    testApplications = test.overrideAttrs (old:{
Valentin Reis's avatar
Valentin Reis committed
188
      name = "testEnv-with-applications";
Valentin Reis's avatar
Valentin Reis committed
189 190 191 192 193 194 195 196 197
      buildInputs = testBuildInputs ++ [
        lammps
        qmcpack
        openmc
        stream
        amg
        openmc-data
      ];
    });
Valentin Reis's avatar
Valentin Reis committed
198

Valentin Reis's avatar
Valentin Reis committed
199 200 201
    expe = testApplications.overrideAttrs (old:{
      name = "power-experiments";
      buildInputs = old.buildInputs ++ [
202 203
        #debug tools
        pkgs.which
Valentin Reis's avatar
Valentin Reis committed
204
        zmcat
205 206 207

        #experiment tools
        zymake
208
      ];
Valentin Reis's avatar
Valentin Reis committed
209
      buildPhase = "zymake ${experiments-src}/experiments/zymakefile";
Valentin Reis's avatar
Valentin Reis committed
210 211 212 213
      installPhase = ''
        mkdir -p $out
        cp -r o/* $out
      '';
Valentin Reis's avatar
Valentin Reis committed
214
    });
Valentin Reis's avatar
Valentin Reis committed
215

Valentin Reis's avatar
Valentin Reis committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
    analysis = pkgs.stdenv.mkDerivation rec {
      name = "analysis";
      src = experiments-src;

      #required to be able to build the drv.
      installPhase = "mkdir $out";
      unpackPhase = "true";

      buildInputs = [
        (pkgs.rWrapper.override{ packages = with pkgs.rPackages; [
          pkgs.rlwrap
          pkgs.pandoc
          docopt
          formatR
          purrr
          knitr
          cowplot
          plotly
          lubridate
          dplyr
          ggplot2
          xtable
          ggthemes
          data_table
        ];})
      ];
    };

    report = analysis.overrideAttrs (old:{
      buildPhase = ''
        echo "analysis/zymakefolder.R ${expe}"
        analysis/zymakefolder.R ${expe}
      '';
      installPhase = ''
        mkdir -p $out
        cp -r index* $out
      '';
    });
254

255
    doArgotk = drv: command: drv.overrideAttrs (old:{
Valentin Reis's avatar
Valentin Reis committed
256
      buildPhase = "argotk "+command+" --verbose";
Valentin Reis's avatar
Valentin Reis committed
257 258 259 260 261
      installPhase = ''
        mkdir $out
        cp _output/* $out/
      '';
    });
262 263 264 265 266 267 268 269 270 271
    testHello       = doArgotk test "TestHello";
    testListen      = doArgotk test "TestListen";
    testPerfwrapper = doArgotk test "TestPerfwrapper";
    testPower       = doArgotk test "TestPower";
    testSTREAM      = doArgotk testApplications "TestSTREAM";
    testAMG         = doArgotk testApplications "TestAMG";
    testOpenMC      = doArgotk testApplications "TestOpenMC";
    testLAMMPS      = doArgotk testApplications "TestLAMMPS";
    testQMCPack     = doArgotk testApplications "TestQMCPack";
    testAll         = doArgotk test "tests";
Valentin Reis's avatar
Valentin Reis committed
272

273
  };
274
# re-exporting a full nixpkgs-like package set
275
in pkgs // argopkgs
Valentin Reis's avatar
Valentin Reis committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305




    #jupyter =
      #let
        #jupyter = import (fetched jupyter/pin.json) {};
      #in
       #(jupyter.jupyterlabWith {
          #kernels = [
            #(jupyter.kernels.juniperWith {
              #name = "analysis";
              #packages = p: with p; [ ggplot2
                  #pkgs.which
                  #docopt
                  #purrr
                  #knitr
                  #cowplot
                  #plotly
                  #lubridate
                  #dplyr
                  #ggplot2
                  #xtable
                  #ggthemes
                  #data_table
              #];
            #})
          #];
         #}).env;