Skip to content

Commit 05416fa

Browse files
committed
Move set-git-rev to the top level flake
This allows to retain direct access to haskell.nix derivations through the project flake output.
1 parent 5006b56 commit 05416fa

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

flake.nix

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@
8585
}@input:
8686
let
8787
inherit (nixpkgs) lib;
88-
inherit (lib) head systems mapAttrs recursiveUpdate mkDefault
89-
getAttrs optionalAttrs nameValuePair attrNames;
90-
inherit (utils.lib) eachSystem mkApp flattenTree;
88+
inherit (lib) head mapAttrs recursiveUpdate optionalAttrs;
89+
inherit (utils.lib) eachSystem flattenTree;
9190
inherit (iohkNix.lib) prefixNamesWith;
9291
removeRecurse = lib.filterAttrsRecursive (n: _: n != "recurseForDerivations");
9392

@@ -122,12 +121,16 @@
122121
] ++ (import ops-lib.outPath {}).overlays;
123122

124123
collectExes = project:
125-
let inherit (project.pkgs.stdenv) hostPlatform;
126-
in project.exes // (with project.hsPkgs; {
127-
inherit (ouroboros-consensus-cardano.components.exes) db-analyser db-synthesizer db-truncater;
124+
let set-git-rev = import ./nix/set-git-rev.nix { inherit (project) pkgs; };
125+
in
126+
# take all executables from the project local packages
127+
project.exes // (with project.hsPkgs; {
128+
# add some executables from other relevant packages
128129
inherit (bech32.components.exes) bech32;
129-
inherit (cardano-cli.components.exes) cardano-cli;
130-
} // lib.optionalAttrs hostPlatform.isUnix {
130+
inherit (ouroboros-consensus-cardano.components.exes) db-analyser db-synthesizer db-truncater;
131+
# add cardano-node and cardano-cli with their git revision stamp
132+
cardano-node = set-git-rev project.exes.cardano-node;
133+
cardano-cli = set-git-rev cardano-cli.components.exes.cardano-cli;
131134
});
132135

133136
mkCardanoNodePackages = project: (collectExes project) // {
@@ -143,7 +146,10 @@
143146
project = pkgs.cardanoNodeProject;
144147

145148
# This is used by `nix develop .` to open a devShell
146-
devShells = let shell = import ./shell.nix { inherit pkgs customConfig cardano-mainnet-mirror; }; in {
149+
devShells =
150+
let
151+
shell = import ./shell.nix { inherit pkgs customConfig cardano-mainnet-mirror; };
152+
in {
147153
inherit (shell) devops workbench-shell;
148154
default = shell.dev;
149155
cluster = shell;
@@ -201,12 +207,12 @@
201207
backendName = "supervisor";
202208
useCabalRun = false;
203209
cardano-node-rev =
204-
if __hasAttr "rev" self
210+
if builtins.hasAttr "rev" self
205211
then pkgs.gitrev
206212
else throw "Cannot get git revision of 'cardano-node', unclean checkout?";
207213
}).workbench-profile-run;
208214
in
209-
rec {
215+
{
210216
"dockerImage/node" = pkgs.dockerImage;
211217
"dockerImage/submit-api" = pkgs.submitApiDockerImage;
212218

nix/haskell.nix

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ in
319319
project.appendOverlays (with haskellLib.projectOverlays; [
320320
projectComponents
321321
(final: prev:
322-
let inherit (final.pkgs) lib gitrev; in {
322+
let inherit (final.pkgs) lib; in {
323323
profiled = final.appendModule {
324324
modules = [{
325325
enableLibraryProfiling = true;
@@ -361,27 +361,16 @@ project.appendOverlays (with haskellLib.projectOverlays; [
361361
(path: value:
362362
if (lib.isAttrs value) then
363363
lib.recursiveUpdate
364-
(if lib.elemAt path 2 == "exes" && lib.elem (lib.elemAt path 3) [ "cardano-node" "cardano-cli" ] then
365-
# Stamp executables with version info.
366-
# Done outside the haskell.nix derivation to avoid compilation and tests depending on rev.
367-
final.pkgs.buildPackages.runCommand value.name
368-
{
369-
inherit (value) exeName exePath meta passthru;
370-
} ''
371-
mkdir -p $out
372-
cp --no-preserve=timestamps --recursive ${value}/* $out/
373-
chmod -R +w $out/bin
374-
${final.pkgs.pkgsBuildBuild.haskellBuildUtils}/bin/set-git-rev "${gitrev}" $out/bin/*
375-
''
376-
else value)
364+
value
377365
{
378366
# Also add convenient passthru to some alternative compilation configurations:
379367
passthru = {
380368
profiled = lib.getAttrFromPath path final.profiled.hsPkgs;
381369
asserted = lib.getAttrFromPath path final.asserted.hsPkgs;
382370
eventlogged = lib.getAttrFromPath path final.eventlogged.hsPkgs;
383371
};
384-
} else value)
372+
}
373+
else value)
385374
prev.hsPkgs;
386375
})
387376
])

nix/set-git-rev.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{ pkgs }:
2+
drv:
3+
pkgs.buildPackages.runCommand drv.name
4+
{
5+
inherit (drv) exeName exePath meta passthru;
6+
} ''
7+
mkdir -p $out
8+
cp --no-preserve=timestamps --recursive ${drv}/* $out/
9+
chmod -R +w $out/bin
10+
${pkgs.pkgsBuildBuild.haskellBuildUtils}/bin/set-git-rev "${pkgs.gitrev}" $out/bin/*
11+
''

0 commit comments

Comments
 (0)