Skip to content
Snippets Groups Projects
default.nix 1.32 KiB
Newer Older
  • Learn to ignore specific revisions
  • { pkgs ? import ../nixpkgs.nix {} }:
    let
      lib = pkgs.lib;
      gridlib = import ./lib;
      inherit (gridlib.pkgs) ourpkgs;
      grids-path = "${builtins.toString ./.}/grid";
      grid-configs = lib.mapAttrs (n: v: grids-path + "/${n}/grid.nix") (lib.filterAttrs (n: v: v == "directory") (builtins.readDir grids-path));
      # It would be useful if morph exposed this as a function.
      # https://github.com/DBCDK/morph/pull/166
      morph-eval = networkExpr: (import "${pkgs.morph.lib}/eval-machines.nix") { inherit networkExpr; };
      grids = lib.mapAttrs (n: v: (morph-eval v)) grid-configs;
      # Derivation with symlinks to the morph output for each grid.
      output = pkgs.runCommand "privatestorage-morph"
        { preferLocalBuild = true; allowSubstitutes = false; passthru = { inherit gridlib ourpkgs grids; }; }
        ''
          mkdir $out
          ${lib.concatStringsSep "\n" (
          lib.mapAttrsToList (
            name: morph:
              let
                output = morph.machines {
                  # It would be nice if we didn't need to write this data to a file.
                  # https://github.com/DBCDK/morph/pull/186
                  argsFile = pkgs.writeText "args" (builtins.toJSON { Names = lib.attrNames morph.nodes; });
                };
              in
                ''
                  ln -s ${output} $out/${lib.escapeShellArg name}
                ''
          ) grids
        )}'';
    in output