diff --git a/default.nix b/default.nix index 8b605281715be3f74c375a6b5532a4a87a6b4993..35bd691f60b222140f66a7db023678a15fbf144d 100644 --- a/default.nix +++ b/default.nix @@ -11,4 +11,9 @@ # Run some unit tests of the Nix that ties all of these things together (ie, # PrivateStorageio-internal library functionality). unit-tests = pkgs.callPackage ./nixos/unit-tests.nix { }; + + # Build all grids into a single derivation. The derivation also has several + # attributes that are useful for exploring the configuration in a repl or + # with eval. + morph = pkgs.callPackage ./morph {}; } diff --git a/morph/default.nix b/morph/default.nix new file mode 100644 index 0000000000000000000000000000000000000000..52cf7d107a1b4c9e7a146d35e413ec6e53a3041b --- /dev/null +++ b/morph/default.nix @@ -0,0 +1,32 @@ +{ 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