Skip to content

Commit

Permalink
[DDW-1083] Clean up flake.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrus committed Nov 30, 2022
1 parent 1b7edb5 commit 5f60053
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 81 deletions.
84 changes: 19 additions & 65 deletions flake.nix
Expand Up @@ -5,83 +5,37 @@
};
outputs = inputs: let
sourceLib = import ./nix/source-lib.nix { inherit inputs; };
inherit (sourceLib) forEachCluster;
in {

# FIXME: clean up this repetition soon (but now they differ slightly)
packages = {
x86_64-linux = let
oldCode = sourceLib.forEachCluster (cluster: import ./nix/old-default.nix {
target = "x86_64-linux"; localLibSystem = "x86_64-linux";
inherit cluster sourceLib;
});
in rec {
internal = sourceLib.forEachCluster (cluster: oldCode.${cluster});
package = sourceLib.forEachCluster (cluster: oldCode.${cluster}.daedalus);
installer = sourceLib.forEachCluster (cluster: oldCode.${cluster}.wrappedBundle);
default = package.mainnet;
makeSignedInstaller = sourceLib.forEachCluster (cluster: oldCode.${cluster}.makeSignedLinuxInstaller);
buildkitePipeline = import ./nix/buildkite-pipeline.nix { inherit inputs; targetSystem = "x86_64-linux"; };
};

x86_64-windows = let
oldCode = sourceLib.forEachCluster (cluster: import ./nix/old-default.nix {
target = "x86_64-windows"; localLibSystem = "x86_64-linux";
inherit cluster sourceLib;
});
in rec {
package = sourceLib.forEachCluster (cluster: oldCode.${cluster}.rawapp-win64); # FIXME: this is wrong
installer = sourceLib.forEachCluster (cluster: oldCode.${cluster}.unsigned-windows-installer);
internal = sourceLib.forEachCluster (cluster: oldCode.${cluster});
default = installer.mainnet;
makeSignedInstaller = sourceLib.forEachCluster (cluster: oldCode.${cluster}.makeSignedWindowsInstaller);
buildkitePipeline = import ./nix/buildkite-pipeline.nix { inherit inputs; targetSystem = "x86_64-windows"; };
};

x86_64-darwin = let
oldCode = sourceLib.forEachCluster (cluster: import ./nix/old-default.nix {
target = "x86_64-darwin"; localLibSystem = "x86_64-darwin";
inputsSelf = toString inputs.self;
inherit cluster sourceLib;
});
in rec {
package = sourceLib.forEachCluster (cluster: oldCode.${cluster}.any-darwin.package);
installer = sourceLib.forEachCluster (cluster: oldCode.${cluster}.any-darwin.unsignedInstaller);
internal = sourceLib.forEachCluster (cluster: oldCode.${cluster});
default = package.mainnet;
makeSignedInstaller = sourceLib.forEachCluster (cluster: oldCode.${cluster}.any-darwin.makeSignedInstaller);
buildkitePipeline = import ./nix/buildkite-pipeline.nix { inherit inputs; targetSystem = "x86_64-darwin"; };
};

aarch64-darwin = let
oldCode = sourceLib.forEachCluster (cluster: import ./nix/old-default.nix {
target = "aarch64-darwin"; localLibSystem = "aarch64-darwin";
inputsSelf = toString inputs.self;
inherit cluster sourceLib;
});
in rec {
package = sourceLib.forEachCluster (cluster: oldCode.${cluster}.any-darwin.package);
installer = sourceLib.forEachCluster (cluster: oldCode.${cluster}.any-darwin.unsignedInstaller);
internal = sourceLib.forEachCluster (cluster: oldCode.${cluster});
default = package.mainnet;
makeSignedInstaller = sourceLib.forEachCluster (cluster: oldCode.${cluster}.any-darwin.makeSignedInstaller);
buildkitePipeline = import ./nix/buildkite-pipeline.nix { inherit inputs; targetSystem = "aarch64-darwin"; };
};
packages = __mapAttrs (targetSystem: definition: rec {
internal = forEachCluster (cluster: import definition { inherit inputs cluster targetSystem; });
package = __mapAttrs (_: a: a.package) internal;
installer = __mapAttrs (_: a: a.unsignedInstaller) internal;
default = package.mainnet;
makeSignedInstaller = __mapAttrs (_: a: a.makeSignedInstaller) internal;
buildkitePipeline = import ./nix/buildkite-pipeline.nix { inherit inputs targetSystem; };
}) {
x86_64-linux = ./nix/x86_64-linux.nix;
x86_64-windows = ./nix/x86_64-windows.nix;
x86_64-darwin = ./nix/any-darwin.nix;
aarch64-darwin = ./nix/any-darwin.nix;
};

devShells = sourceLib.forEach [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ] (system:
let all = sourceLib.forEachCluster (cluster: import ./nix/old-shell.nix { inherit system cluster; });
let all = forEachCluster (cluster: import ./nix/old-shell.nix { inherit system cluster; });
in all // { default = all.mainnet; }
);

# Compatibility with older Nix:
defaultPackage = builtins.mapAttrs (_: a: a.default) inputs.self.outputs.packages;
devShell = builtins.mapAttrs (_: a: a.default) inputs.self.outputs.devShells;
defaultPackage = __mapAttrs (_: a: a.default) inputs.self.outputs.packages;
devShell = __mapAttrs (_: a: a.default) inputs.self.outputs.devShells;

hydraJobs = {

# --- Linux ----------------------------------------------------
x86_64-linux.x86_64-linux = let
d = inputs.self.outputs.packages.x86_64-linux.internal.mainnet;
d = inputs.self.outputs.packages.x86_64-linux.internal.mainnet.oldCode;
in {
cardano-bridge = d.daedalus-bridge;
cardano-node = d.cardano-node;
Expand All @@ -99,7 +53,7 @@

# --- Windows (x-compiled from Linux) --------------------------
x86_64-linux.x86_64-windows = let
d = inputs.self.outputs.packages.x86_64-windows.internal.mainnet;
d = inputs.self.outputs.packages.x86_64-windows.internal.mainnet.oldCode;
in {
cardano-bridge = d.daedalus-bridge;
cardano-node = d.cardano-node;
Expand All @@ -108,7 +62,7 @@

# --- Darwin ---------------------------------------------------
x86_64-darwin.x86_64-darwin = let
d = inputs.self.outputs.packages.x86_64-darwin.internal.mainnet;
d = inputs.self.outputs.packages.x86_64-darwin.internal.mainnet.oldCode;
in {
cardano-bridge = d.daedalus-bridge;
cardano-node = d.cardano-node;
Expand Down
29 changes: 21 additions & 8 deletions nix/any-darwin.nix
@@ -1,11 +1,24 @@
{ pkgs, lib, inputsSelf
, nodejs, nodePackages, yarn
, cluster, daedalus-bridge, daedalus-installer, darwin-launcher, launcherConfigs, mock-token-metadata-server
, sourceLib, cardanoNodeVersion, cardanoWalletVersion
, ... }:
{ inputs, targetSystem, cluster }:

assert targetSystem == "x86_64-darwin" || targetSystem == "aarch64-darwin";

let

sourceLib = import ./source-lib.nix { inherit inputs; };

oldCode = import ./old-default.nix {
target = targetSystem;
localLibSystem = targetSystem;
inherit cluster sourceLib;
};

inherit (oldCode) pkgs
nodejs nodePackages yarn
daedalus-bridge daedalus-installer darwin-launcher launcherConfigs mock-token-metadata-server
cardanoNodeVersion cardanoWalletVersion;

inherit (pkgs) lib;

archSuffix = if pkgs.system == "aarch64-darwin" then "arm64" else "x64";
originalPackageJson = builtins.fromJSON (builtins.readFile ../package.json);
electronVersion = originalPackageJson.dependencies.electron;
Expand All @@ -15,7 +28,7 @@ let

in rec {

inherit nodejs nodePackages yarn;
inherit oldCode nodejs nodePackages yarn;

yarn2nix = let
# Nixpkgs master @ 2022-07-18
Expand All @@ -33,13 +46,13 @@ in rec {

# To better cache node_modules, let’s only depend on package.json, and yarn.lock:
srcLockfiles = lib.cleanSourceWith {
src = inputsSelf;
src = inputs.self;
name = "daedalus-lockfiles";
filter = name: type: let b = baseNameOf (toString name); in (b == "package.json" || b == "yarn.lock");
};

srcWithoutNix = lib.cleanSourceWith {
src = inputsSelf;
src = inputs.self;
filter = name: type: !(type == "regular" && (
lib.hasSuffix ".nix" name ||
lib.hasSuffix ".hs" name ||
Expand Down
5 changes: 0 additions & 5 deletions nix/old-default.nix
Expand Up @@ -4,7 +4,6 @@
, localLib ? import ./old-lib.nix { inherit nodeImplementation; system = localLibSystem; }
, cluster ? "mainnet"
, version ? "versionNotSet"
, inputsSelf ? null
, dummyInstaller ? false
, signingKeys ? null
, HSMServer ? null
Expand Down Expand Up @@ -460,9 +459,5 @@ let
cp ${self.newBundle} $out/${fn}
'';

any-darwin = self.callPackage (import ./any-darwin.nix) {
inherit cluster inputsSelf sourceLib;
};

};
in pkgs.lib.makeScope pkgs.newScope packages
3 changes: 0 additions & 3 deletions nix/old-yarn2nix.nix
Expand Up @@ -28,9 +28,6 @@ let
}) {
inherit pkgs nodejs yarn;
};
dotGitExists = builtins.pathExists ../.git;
isNix2 = 0 <= builtins.compareVersions builtins.nixVersion "1.12";
canUseFetchGit = dotGitExists && isNix2;
origPackage = builtins.fromJSON (builtins.readFile ../package.json);
newPackage = (origPackage // {
productName = spacedName;
Expand Down
28 changes: 28 additions & 0 deletions nix/x86_64-linux.nix
@@ -0,0 +1,28 @@
{ inputs, targetSystem, cluster }:

assert targetSystem == "x86_64-linux";

let

sourceLib = import ./source-lib.nix { inherit inputs; };

oldCode = import ./old-default.nix {
target = targetSystem;
localLibSystem = targetSystem;
inherit cluster sourceLib;
};

inherit (oldCode) pkgs;
inherit (pkgs) lib;

in rec {

inherit oldCode;

package = oldCode.daedalus;

unsignedInstaller = oldCode.wrappedBundle;

makeSignedInstaller = throw "We don’t sign binary files inside installers for ‘${targetSystem}’, you’re good.";

}
31 changes: 31 additions & 0 deletions nix/x86_64-windows.nix
@@ -0,0 +1,31 @@
{ inputs, targetSystem, cluster }:

assert targetSystem == "x86_64-windows";

let

sourceLib = import ./source-lib.nix { inherit inputs; };

oldCode = import ./old-default.nix {
target = targetSystem;
localLibSystem = targetSystem;
inherit cluster sourceLib;
};

inherit (oldCode) pkgs;
inherit (pkgs) lib;

in rec {

inherit oldCode;

package = unsignedInstaller; # FIXME: this is wrong

unsignedInstaller = oldCode.unsigned-windows-installer;

makeSignedInstaller = oldCode.pkgs.writeScriptBin "make-signed-installer" ''
echo >&2 'fatal: not yet implemented'
exit 1
'';

}

0 comments on commit 5f60053

Please sign in to comment.