Skip to content

Commit

Permalink
Move cabal-install, nix-tools building logic to overlay files
Browse files Browse the repository at this point in the history
  • Loading branch information
pranaysashank committed Jan 18, 2025
1 parent 1de979c commit 3b6ae81
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 138 deletions.
62 changes: 25 additions & 37 deletions overlays/cabal-install.nix
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
{ stdenv, fetchurl, lib }:

stdenv.mkDerivation rec {
pname = "cabal-install";
version = "3.14.1.1";

src = fetchurl {
url = "https://downloads.haskell.org/~cabal/cabal-install-${version}/cabal-install-${version}-x86_64-linux-alpine3_18.tar.xz";
sha256 = "sha256-KA273YDQ3grmr0dkNghQkUjLLs8JZ80lW1q8skHZWd4=";
};

# Prevent Nix from automatically unpacking the source
dontUnpack = true;

# No build steps are required
buildPhase = "";

installPhase = ''
mkdir -p $out/bin
# Manually extract the tarball
tar -xJf ${src}
# Move the 'cabal' binary to $out/bin
cp -v cabal $out/bin/
# Ensure the binary is executable
chmod +x $out/bin/cabal
'';

# No dependencies are needed since the binary is statically linked
buildInputs = [];

meta = with lib; {
description = "The cabal-install tool (binary distribution)";
homepage = "https://www.haskell.org/cabal/";
license = licenses.bsd3;
platforms = platforms.linux;
maintainers = [];
};
final: prev:
{ bootstrap-cabal-install =
let
cabal-install-src = final.pkgs.fetchurl {
url = "https://hackage.haskell.org/package/cabal-install-3.14.1.1/cabal-install-3.14.1.1.tar.gz";
sha256 = "sha256-8R02Srh/tGJ1qYfmBFOFdzIUd4CoxZJGDuyKFtu2us4=";
};
cabal-install-pkgs = final.haskell-nix.cabalProjectWithPlan
{ src = cabal-install-src;
compiler-nix-name = "ghc912";
cabalProject = ''
packages:
./cabal-install.cabal
package cabal-install
tests: false
'';
}
(_: {
"extra-hackages" = [];
"index-state-max" = "2025-01-17T00:00:00Z";
"projectNix" = ../materialized/cabal-install-3.14.1.1;
"sourceRepos" = [];
"src" = cabal-install-src;
});
in cabal-install-pkgs.hsPkgs.cabal-install.components.exes.cabal;
}
64 changes: 2 additions & 62 deletions overlays/default.nix
Original file line number Diff line number Diff line change
@@ -1,73 +1,13 @@
{ sources }:
let
overlays = {
cabal-install-overlay = final: prev:
{ bootstrap-cabal-install =
let
cabal-install-src = final.pkgs.fetchurl {
url = "https://hackage.haskell.org/package/cabal-install-3.14.1.1/cabal-install-3.14.1.1.tar.gz";
sha256 = "sha256-8R02Srh/tGJ1qYfmBFOFdzIUd4CoxZJGDuyKFtu2us4=";
};
cabal-install-pkgs = final.haskell-nix.cabalProjectWithPlan
{ src = cabal-install-src;
compiler-nix-name = "ghc912";
cabalProject = ''
packages:
./cabal-install.cabal
package cabal-install
tests: false
'';
}
(_: {
"extra-hackages" = [];
"index-state-max" = "2025-01-17T00:00:00Z";
"projectNix" = ../materialized/cabal-install-3.14.1.1;
"sourceRepos" = [];
"src" = cabal-install-src;
});
in cabal-install-pkgs.hsPkgs.cabal-install.components.exes.cabal;
};
cabal-install-overlay = import ./cabal-install.nix;

haskell = import ./haskell.nix { inherit sources; };

# Here is where we import nix-tools into the overlays that haskell.nix is
# going to use.
nix-tools = (final: prev:
let

# Import the overlay from nix-tools' subdirectory
nix-tools-exes = final.callPackage ./nix-tools.nix {};

in
{
haskell-nix =
prev.haskell-nix // {
nix-tools =
let nix-tools-pkgs = final.haskell-nix.cabalProjectWithPlan
{ src = ../nix-tools; compiler-nix-name = "ghc912"; }
(_: {
"extra-hackages" = [];
"index-state-max" = "2025-01-17T00:00:00Z";
"projectNix" = ../materialized/nix-tools;
"sourceRepos" = [
(final.pkgs.fetchgit {
url = "https://github.com/kronor-io/hackage-db";
sha256 = "11g395vrrsaasl1ssk8qfbcc9wx6aygipsldyclgn4szpm4xzm7h";
rev = "83f819cb08742d3c86a83b407d45c1f6c1c7e299";
})
];
"src" = ../nix-tools;
});
in {
exes = {
truncate-index = nix-tools-pkgs.hsPkgs.nix-tools.components.exes.truncate-index;
make-install-plan = nix-tools-pkgs.hsPkgs.nix-tools.components.exes.make-install-plan;
plan-to-nix = nix-tools-pkgs.hsPkgs.nix-tools.components.exes.plan-to-nix;
hackage-to-nix = nix-tools-pkgs.hsPkgs.nix-tools.components.exes.hackage-to-nix;
};
};
};
});
nix-tools = import ./nix-tools.nix;

bootstrap = import ./bootstrap.nix;
ghc = import ./ghc.nix;
Expand Down
68 changes: 29 additions & 39 deletions overlays/nix-tools.nix
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
{ stdenv, fetchurl, lib }:

stdenv.mkDerivation rec {
pname = "nix-tools";
version = "0.1.0.0";

src = fetchurl {
url = "https://pgnb.s3.ap-south-2.amazonaws.com/nix-tools-alpine-amd.tar.xz";
sha256 = "sha256-/qff9cYlWGvlWPHgsgC9OXxidK4lrF754u91gh9BbTA=";
};

# Prevent Nix from automatically unpacking the source
dontUnpack = true;

# No build steps are required
buildPhase = "";

installPhase = ''
mkdir -p $out/bin
# Manually extract the tarball
tar -xJf ${src}
# Move all binaries to $out/bin
find ./dist-newstyle/ -type f -executable | xargs -I {} cp -v {} $out/bin/
# Ensure the binaries are executable
chmod +x $out/bin/*
'';

# No dependencies are needed since the binary is statically linked
buildInputs = [];

meta = with lib; {
description = "nix-tools";
homepage = "https://github.com/input-output-hk/haskell.nix";
license = licenses.bsd3;
platforms = platforms.linux;
maintainers = [];
};
final: prev:
{
haskell-nix =
prev.haskell-nix // {
nix-tools =
let nix-tools-pkgs = final.haskell-nix.cabalProjectWithPlan
{ src = ../nix-tools; compiler-nix-name = "ghc912"; }
(_: {
"extra-hackages" = [];
"index-state-max" = "2025-01-17T00:00:00Z";
"projectNix" = ../materialized/nix-tools;
"sourceRepos" = [
(final.pkgs.fetchgit {
url = "https://github.com/kronor-io/hackage-db";
sha256 = "11g395vrrsaasl1ssk8qfbcc9wx6aygipsldyclgn4szpm4xzm7h";
rev = "83f819cb08742d3c86a83b407d45c1f6c1c7e299";
})
];
"src" = ../nix-tools;
});
in {
exes = {
truncate-index = nix-tools-pkgs.hsPkgs.nix-tools.components.exes.truncate-index;
make-install-plan = nix-tools-pkgs.hsPkgs.nix-tools.components.exes.make-install-plan;
plan-to-nix = nix-tools-pkgs.hsPkgs.nix-tools.components.exes.plan-to-nix;
hackage-to-nix = nix-tools-pkgs.hsPkgs.nix-tools.components.exes.hackage-to-nix;
};
};
};
}

0 comments on commit 3b6ae81

Please sign in to comment.