Skip to content

Commit

Permalink
Flake related improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jbgi committed May 3, 2021
1 parent 0e67b1f commit 8073d48
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 156 deletions.
4 changes: 2 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ let
# `checks.tests` collect results of executing the tests:
tests = collectChecks haskellPackages;

hlint = callPackage iohkNix.tests.hlint {
src = ./. ;
hlint = callPackage hlintCheck {
inherit (cardanoNodeProject.projectModule) src;
};
};

Expand Down
41 changes: 34 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 33 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,39 @@
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
iohkNix = {
url = "github:input-output-hk/iohk-nix";
url = "github:input-output-hk/iohk-nix/flakes-improvements";
inputs.nixpkgs.follows = "nixpkgs";
};
custom-config = {
url = "path:./custom-config.nix";
flake = false;
};
workbench-config = {
url = "path:./workbench-config.nix";
flake = false;
};
};

outputs = { self, nixpkgs, utils, haskellNix, iohkNix, ... }:
outputs = { self, nixpkgs, utils, haskellNix, iohkNix, custom-config, workbench-config, ... }:
let
inherit (haskellNix.internal) config;
inherit (nixpkgs) lib;
inherit (lib) systems mapAttrs recursiveUpdate mkDefault optionalAttrs nameValuePair;
inherit (lib) head systems mapAttrs recursiveUpdate mkDefault optionalAttrs nameValuePair;
inherit (utils.lib) eachSystem mkApp flattenTree;
inherit (iohkNix.lib) prefixNamesWith collectExes;

overlays = with iohkNix.overlays; [
supportedSystems = import ./supported-systems.nix;
defaultSystem = head supportedSystems;

overlays = [
haskellNix.overlay
haskell-nix-extra
crypto
cardano-lib
iohkNix.overlays.haskell-nix-extra
iohkNix.overlays.crypto
iohkNix.overlays.cardano-lib
iohkNix.overlays.utils
(final: prev: {
customConfig = import ./custom-config.nix;
workbenchConfig = import ./workbench-config.nix;
customConfig = import custom-config;
workbenchConfig = import workbench-config;
gitrev = self.rev or "dirty";
commonLib = lib
// iohkNix.lib
Expand All @@ -35,7 +47,7 @@
(import ./nix/pkgs.nix)
];

in eachSystem (import ./supported-systems.nix) (system:
in eachSystem supportedSystems (system:
let
pkgs = import nixpkgs { inherit system overlays config; };

Expand Down Expand Up @@ -70,7 +82,6 @@
modules = [ ./nix/nixos/cardano-node-service.nix (configModule conf) ];
};


packages = let
deps = with pkgs; [
coreutils
Expand Down Expand Up @@ -105,10 +116,12 @@
in debug // vanilla // {
inherit (devShell) devops;
} // (collectExes flake.packages)
// (prefixNamesWith "static/"
(mapAttrs pkgs.rewriteStatic (collectExes
(if system == "x86_64-darwin" then flake else muslFlake).packages)))
# Linux only packages:
// optionalAttrs (system == "x86_64-linux") (
prefixNamesWith "windows/" (collectExes windowsFlake.packages)
// (prefixNamesWith "static/" (collectExes muslFlake.packages))
// {
"dockerImage/node" = pkgs.dockerImage;
"dockerImage/submit-api" = pkgs.submitApiDockerImage;
Expand All @@ -125,7 +138,13 @@
optionalAttrs (system == "x86_64-linux") (
prefixNamesWith "windows/" windowsFlake.checks
// (prefixNamesWith "nixosTests/" (mapAttrs (_: v: v.${system} or v) pkgs.nixosTests))
);
# checks run on default system only;
) // optionalAttrs (system == defaultSystem) {
hlint = pkgs.callPackage pkgs.hlintCheck {
#inherit (pkgs.cardanoNodeProject.projectModule) src;
src = ./.;
};
};

# Built by `nix build .`
defaultPackage = flake.packages."cardano-node:exe:cardano-node";
Expand All @@ -147,9 +166,7 @@
};
}
# nix run .#<env>/node
// (mapAttrs
(_: drv: (mkApp {inherit drv; exePath = "";}))
(flattenTree pkgs.scripts))
// (mapAttrs (_: drv: (mkApp {inherit drv;})) (flattenTree pkgs.scripts))
# nix run .#<env>/node-entrypoint
// (eachEnv (env: lib.nameValuePair "${env}/node-entrypoint" (utils.lib.mkApp {
drv = packages."${env}/node-entrypoint";
Expand Down
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let
++ iohkNix.overlays.crypto
# iohkNix: nix utilities:
++ iohkNix.overlays.iohkNix
++ iohkNix.overlays.utils
# our own overlays:
++ [
(pkgs: _: with pkgs; {
Expand Down
21 changes: 11 additions & 10 deletions nix/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,29 @@
# Version info, to be passed when not building from a git work tree
, gitrev ? null
, libsodium ? pkgs.libsodium
}:
let

src = haskell-nix.haskellLib.cleanGit {
, src ? (haskell-nix.haskellLib.cleanGit {
name = "cardano-node-src";
src = ../.;
};
})

# It is important this matches in both calls to cabalProject or `cabal configure`
# will run twice.
cabalProjectLocal = ''
, cabalProjectLocal ? ''
allow-newer: terminfo:base
''
# Needed for the Windows cabal constraint solver.
+ lib.optionalString stdenv.hostPlatform.isWindows ''
max-backjumps: 10000
reorder-goals: True
'';
''

projectPackages = lib.attrNames (haskell-nix.haskellLib.selectProjectPackages
, projectPackages ? lib.attrNames (haskell-nix.haskellLib.selectProjectPackages
(haskell-nix.cabalProject' {
inherit src cabalProjectLocal;
compiler-nix-name = compiler;
}).hsPkgs);
}).hsPkgs)
}:
let

# This creates the Haskell package set.
# https://input-output-hk.github.io/haskell.nix/user-guide/projects/
Expand Down Expand Up @@ -180,4 +179,6 @@ let
# package with libsodium:
setLibSodium = "ln -s ${libsodium}/bin/libsodium-23.dll $out/bin/libsodium-23.dll";
in
pkgSet
pkgSet // {
inherit projectPackages;
}
11 changes: 11 additions & 0 deletions nix/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ final: prev: with final;
buildPackages
gitrev
;
inherit (cardanoNodeProject) projectPackages;
inherit (cardanoNodeProject.projectModule) src cabalProjectLocal;
profiling = true;
}).hsPkgs;
cardanoNodeEventlogHaskellPackages = (import ./haskell.nix {
Expand All @@ -34,6 +36,8 @@ final: prev: with final;
buildPackages
gitrev
;
inherit (cardanoNodeProject) projectPackages;
inherit (cardanoNodeProject.projectModule) src cabalProjectLocal;
eventlog = true;
}).hsPkgs;
cardanoNodeAssertedHaskellPackages = (import ./haskell.nix {
Expand All @@ -45,6 +49,8 @@ final: prev: with final;
buildPackages
gitrev
;
inherit (cardanoNodeProject) projectPackages;
inherit (cardanoNodeProject.projectModule) src cabalProjectLocal;
assertedPackages = [
"ouroboros-consensus"
"ouroboros-consensus-cardano"
Expand Down Expand Up @@ -76,6 +82,11 @@ final: prev: with final;
inherit (cardanoNodeProject) index-state;
};

hlint = haskell-nix.tool compiler "hlint" {
version = "3.2.7";
inherit (cardanoNodeProject) index-state;
};

cardanolib-py = callPackage ./cardanolib-py {};

scripts = lib.recursiveUpdate (import ./scripts.nix { inherit pkgs customConfig; })
Expand Down
35 changes: 13 additions & 22 deletions nix/scripts-submit-api.nix
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
{ pkgs
, customConfig
}:
}:
with pkgs.commonLib;
let
customConfig' = customConfig // (customConfig.submit-api or {});
mkScript = envConfig: let

configModule = { options, config, ...}: {
services.cardano-submit-api = recursiveUpdate {
enable = true;
network = envConfig.name;
environment = envConfig;
cardanoNodePkgs = pkgs;
} (let validOptions = attrNames options.services.cardano-submit-api;
in filterAttrs (n: _: elem n validOptions) customConfig');
};

serviceScript = (modules.evalModules {
prefix = [];
service = evalService {
inherit pkgs customConfig;
serviceName = "cardano-submit-api";
modules = [
./nixos/cardano-submit-api-service.nix
systemdCompatModule
configModule
{
services.cardano-submit-api = {
network = lib.mkDefault envConfig.name;
cardanoNodePkgs = lib.mkDefault pkgs;
};
}
];
args = { inherit pkgs; };
check = false;
}).config.services.cardano-submit-api.script;
};

in pkgs.writeScript "cardano-submit-api-${envConfig.name}" ''
in pkgs.writeScript "cardano-submit-api-${service.network}" ''
#!${pkgs.runtimeShell}
set -euo pipefail
${serviceScript} $@
${service.script} $@
'';

scripts = forEnvironments (environment: recurseIntoAttrs {
Expand Down
Loading

0 comments on commit 8073d48

Please sign in to comment.