Skip to content

Commit

Permalink
Switch to flake-parts and nci (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehllie authored Oct 19, 2023
1 parent 5a866f6 commit ffba97f
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 98 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
52 changes: 52 additions & 0 deletions crates.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ ... }: {
perSystem = { pkgs, lib, ... }: {
nci =
let
llvmPackages = pkgs.llvmPackages_16;
major = lib.versions.major llvmPackages.llvm.version;
minor = lib.versions.minor llvmPackages.llvm.version;
llvm-sys-ver = "${major}${builtins.substring 0 1 minor}";
env = {
"LLVM_SYS_${llvm-sys-ver}_PREFIX" = llvmPackages.llvm.dev;
};
in
{
projects.ante.path = ./.;
crates.ante = {
depsDrvConfig = {
inherit env;
};
drvConfig = {
inherit env;
mkDerivation = {
nativeBuildInputs = [ pkgs.installShellFiles ];
buildInputs = lib.attrValues
{
inherit (pkgs)
libffi
libxml2
ncurses;
} ++ [ llvmPackages.llvm ];

postPatch = ''
substituteInPlace tests/golden_tests.rs --replace \
'target/debug' "target/$(rustc -vV | sed -n 's|host: ||p')/release"
'';

preBuild = ''
export ANTE_STDLIB_DIR=$out/lib
find stdlib -type f -exec install -Dm644 "{}" -t $ANTE_STDLIB_DIR \;
'';

postInstall = ''
installShellCompletion --cmd ante \
--bash <($out/bin/ante --shell-completion bash) \
--fish <($out/bin/ante --shell-completion fish) \
--zsh <($out/bin/ante --shell-completion zsh)
'';
};
};
};
};
};
}
63 changes: 10 additions & 53 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,53 +1,10 @@
let
ante =
{ installShellFiles
, lib
, libffi
, libxml2
, llvmPackages
, ncurses
, rustPlatform
}:

let
major = lib.versions.major llvmPackages.llvm.version;
minor = lib.versions.minor llvmPackages.llvm.version;
llvm-sys-ver = "${major}${builtins.substring 0 1 minor}";
toml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
in

rustPlatform.buildRustPackage {
pname = "ante";
src = ./.;
inherit (toml.package) version;
cargoHash = "sha256-Mn5LukLn9bz8Z4YTNEk4CK5ItYFRngoB7Zp9XJVhM74=";

nativeBuildInputs = [ llvmPackages.llvm installShellFiles ];
buildInputs = [ libffi libxml2 ncurses ];

postPatch = ''
substituteInPlace tests/golden_tests.rs --replace \
'target/debug' "target/$(rustc -vV | sed -n 's|host: ||p')/release"
'';

shellHook = ''
export LLVM_SYS_${llvm-sys-ver}_PREFIX=${llvmPackages.llvm.dev}
'';

preBuild = ''
$shellHook
export ANTE_STDLIB_DIR=$out/lib
mkdir -p $ANTE_STDLIB_DIR
cp -r $src/stdlib/* $ANTE_STDLIB_DIR
'';

postInstall = ''
installShellCompletion --cmd ante \
--bash <($out/bin/ante --shell-completion bash) \
--fish <($out/bin/ante --shell-completion fish) \
--zsh <($out/bin/ante --shell-completion zsh)
'';
};
in
{ pkgs ? import <nixpkgs> { } }: with pkgs;
callPackage ante { llvmPackages = llvmPackages_13; }
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix
207 changes: 191 additions & 16 deletions flake.lock

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

Loading

0 comments on commit ffba97f

Please sign in to comment.