Skip to content

Commit

Permalink
ref: change the way dependencies are passed around
Browse files Browse the repository at this point in the history
  • Loading branch information
Dich0tomy committed May 23, 2024
1 parent 8ef072b commit 9102e2a
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 173 deletions.
32 changes: 12 additions & 20 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
systems = import inputs.systems;
perSystem = {
pkgs,
inputs',
system,
lib,
self',
...
}: let
rootDir = ./.;
Expand All @@ -40,31 +38,25 @@
clang-tidy.enable = true;
};
};

buildDeps =
[
pkgs.ctre
pkgs.catch2_3
pkgs.fmt
]
++ import ./nix/dependencies.nix {inherit pkgs;};

nativeDeps = [
pkgs.meson
pkgs.ninja
pkgs.pkg-config
];

in {
formatter = pkgs.alejandra;

_module.args = {
inherit rootDir version nativeDeps buildDeps preCommitCheck;
inherit rootDir version preCommitCheck;

pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
(f: p: {
inherit (pkgs.callPackage ./nix/dependencies {}) tl-optional tl-expected;
})
];
};
};

imports = [
./nix/package
./nix/shell
./nix/package
./nix/shell
];
};
};
Expand Down
46 changes: 0 additions & 46 deletions nix/dependencies.nix

This file was deleted.

4 changes: 4 additions & 0 deletions nix/dependencies/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{pkgs}: {
tl-optional = pkgs.callPackage ./tl-optional {version = "1.1.0";};
tl-expected = pkgs.callPackage ./tl-expected {version = "1.1.0";};
}
23 changes: 23 additions & 0 deletions nix/dependencies/tl-expected/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
pkgs,
version,
}:
pkgs.stdenv.mkDerivation {
pname = "expected";
inherit version;

src = pkgs.fetchFromGitHub {
owner = "TartanLlama";
repo = "expected";
rev = "v${version}";
sha256 = "sha256-AuRU8VI5l7Th9fJ5jIc/6mPm0Vqbbt6rY8QCCNDOU50=";
};

nativeBuildInputs = [pkgs.cmake];

strictDeps = true;

postInstall = ''
install -Dm644 ${./expected.pc} $out/lib/pkgconfig/expected.pc
'';
}
File renamed without changes.
23 changes: 23 additions & 0 deletions nix/dependencies/tl-optional/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
pkgs,
version,
}:
pkgs.stdenv.mkDerivation {
pname = "optional";
inherit version;

src = pkgs.fetchFromGitHub {
owner = "TartanLlama";
repo = "optional";
rev = "v${version}";
sha256 = "sha256-WPTXTQmzJjAIJI1zM6svZZTO8gP/jt5xDHHRCCu9cmI=";
};

strictDeps = true;

nativeBuildInputs = [pkgs.cmake];

postInstall = ''
install -Dm644 ${./optional.pc} $out/lib/pkgconfig/optional.pc
'';
}
File renamed without changes.
27 changes: 11 additions & 16 deletions nix/package/default.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
{
pkgs,
lib,
nativeDeps,
buildDeps,
rootDir,
version,
...
}:
let
package = pkgs.callPackage ./package.nix {
inherit nativeDeps buildDeps rootDir version;
};
in
{
packages.dev = package.dev;
packages.default = package.out;
pkgs,
rootDir,
version,
...
}: let
package = pkgs.callPackage ./package.nix {
inherit rootDir version;
};
in {
packages.dev = package.dev;
packages.default = package.out;
}
97 changes: 56 additions & 41 deletions nix/package/package.nix
Original file line number Diff line number Diff line change
@@ -1,57 +1,72 @@
{
pkgs,
lib,
nativeDeps,
buildDeps,
rootDir,
version
version,
stdenv,
meson,
ninja,
pkg-config,
ctre,
catch2_3,
tl-optional,
tl-expected,
fmt,
}:
pkgs.stdenv.mkDerivation {
pname = "dire";
inherit version;
stdenv.mkDerivation {
pname = "dire";
inherit version;

outputs = ["out" "dev"];
outputs = ["out" "dev"];

strictDeps = true;
enableParallelBuilding = true;
strictDeps = true;
enableParallelBuilding = true;

dontUseCmakeConfigure = true;
dontUseCmakeConfigure = true;

nativeBuildInputs = nativeDeps;
nativeBuildInputs = [
meson
ninja
pkg-config
];

buildInputs = buildDeps;
buildInputs = [
ctre
catch2_3
fmt
tl-optional
tl-expected
];

src = rootDir;
src = rootDir;

mesonBuildType = "release";
mesonBuildType = "release";

# We use mesonFlags, because mesonFlagsArray & the Nix ecosystem
# don't have the capabilities to properly handle these flags
# e.g. appending \ to the one-before-last argument making the command fail
# or simply not supporting the `-DX=Y` option style
mesonFlags = [
"--optimization=3"
"-Db_lto_threads=8"
"-Db_lto=true"
"-Dstrip=true"
];
# We use mesonFlags, because mesonFlagsArray & the Nix ecosystem
# don't have the capabilities to properly handle these flags
# e.g. appending \ to the one-before-last argument making the command fail
# or simply not supporting the `-DX=Y` option style
mesonFlags = [
"--optimization=3"
"-Db_lto_threads=8"
"-Db_lto=true"
"-Dstrip=true"
];

buildPhase = ''
meson compile dire
'';
buildPhase = ''
meson compile dire
'';

installPhase = ''
mkdir -p {$dev,$out}/lib $dev/lib/pkgconfig $dev/include
installPhase = ''
mkdir -p {$dev,$out}/lib $dev/lib/pkgconfig $dev/include
cp src/lib/libdire.a $out/lib
cp src/lib/libdire.a $dev/lib
cp src/lib/libdire.a $out/lib
cp src/lib/libdire.a $dev/lib
cp -r $src/src/lib/include/* $dev/include
cp -r $src/src/lib/include/* $dev/include
substitute \
${./dire.pc} \
$dev/lib/pkgconfig/dire.pc \
--subst-var out \
--subst-var version
'';
}
substitute \
${./dire.pc} \
$dev/lib/pkgconfig/dire.pc \
--subst-var out \
--subst-var version
'';
}
54 changes: 4 additions & 50 deletions nix/shell/default.nix
Original file line number Diff line number Diff line change
@@ -1,57 +1,11 @@
{
pkgs,
nativeDeps,
buildDeps,
preCommitCheck,
...
}: let
shellDeps = [
pkgs.doxygen
pkgs.cmake
pkgs.graphviz
];

baseShellAttrs = {
hardeningDisable = ["all"];

packages = nativeDeps ++ shellDeps;

buildInputs = buildDeps;
};

gccStdenv = pkgs.gcc11Stdenv;

clangStdenv = pkgs.llvmPackages_16.stdenv;

ciGcc = pkgs.mkShell.override {stdenv = gccStdenv;} baseShellAttrs;

ciClang = pkgs.mkShell.override {stdenv = clangStdenv;} baseShellAttrs;

devPackages =
[
pkgs.act
]
++ shellDeps;

baseDevShellAttrs =
baseShellAttrs
// {
inherit (preCommitCheck) shellHook;

packages = baseShellAttrs.packages ++ devPackages;
};

devClang = pkgs.mkShell.override {stdenv = clangStdenv;} (baseDevShellAttrs
// {
env = {
CLANGD_PATH = "${pkgs.clang-tools_16}/bin/clangd";
ASAN_SYMBOLIZER_PATH = "${pkgs.llvmPackages_16.bintools-unwrapped}/bin/llvm-symbolizer";
};
});

devGcc = pkgs.mkShell.override {stdenv = gccStdenv;} baseDevShellAttrs;
shells = pkgs.callPackage ./shells.nix {inherit preCommitCheck;};
in {
devShells = {
inherit ciGcc ciClang devGcc devClang;
};
devShells = {
inherit (shells) ciGcc ciClang devGcc devClang;
};
}
Loading

0 comments on commit 9102e2a

Please sign in to comment.