magic-nix-cache/flake.nix

162 lines
4.5 KiB
Nix
Raw Normal View History

2023-05-08 09:48:11 +00:00
{
description = "GitHub Actions-powered Nix binary cache";
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.tar.gz";
2023-05-08 09:48:11 +00:00
2024-08-09 17:34:28 +00:00
fenix = {
url = "https://flakehub.com/f/nix-community/fenix/0.1.1727.tar.gz";
2023-05-08 09:48:11 +00:00
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "https://flakehub.com/f/ipetkov/crane/0.16.3.tar.gz";
2023-05-08 09:48:11 +00:00
inputs.nixpkgs.follows = "nixpkgs";
};
2023-10-10 20:16:05 +00:00
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.0.1.tar.gz";
2025-02-19 16:48:48 +00:00
nix.url = "https://flakehub.com/f/NixOS/nix/2.tar.gz";
2023-05-08 09:48:11 +00:00
};
2024-08-09 17:34:28 +00:00
outputs = { self, nixpkgs, fenix, crane, ... }@inputs:
let
supportedSystems = [
"aarch64-linux"
"x86_64-linux"
"aarch64-darwin"
"x86_64-darwin"
2023-05-08 09:48:11 +00:00
];
2024-08-09 17:34:28 +00:00
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f rec {
2024-08-09 17:34:28 +00:00
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.default
];
};
inherit (pkgs) lib;
2024-08-09 17:34:28 +00:00
inherit system;
});
2024-08-09 17:34:28 +00:00
fenixToolchain = system: with fenix.packages.${system};
combine ([
stable.clippy
stable.rustc
stable.cargo
stable.rustfmt
stable.rust-src
stable.rust-analyzer
2024-08-09 17:34:28 +00:00
] ++ nixpkgs.lib.optionals (system == "x86_64-linux") [
targets.x86_64-unknown-linux-musl.stable.rust-std
] ++ nixpkgs.lib.optionals (system == "aarch64-linux") [
targets.aarch64-unknown-linux-musl.stable.rust-std
]);
in
{
2024-08-09 17:34:28 +00:00
overlays.default = final: prev:
let
toolchain = fenixToolchain final.hostPlatform.system;
craneLib = (crane.mkLib final).overrideToolchain toolchain;
crateName = craneLib.crateNameFromCargoToml {
cargoToml = ./magic-nix-cache/Cargo.toml;
};
commonArgs = {
inherit (crateName) pname version;
src = self;
nativeBuildInputs = with final; [
pkg-config
];
buildInputs = [
2025-02-19 18:32:14 +00:00
inputs.nix.packages.${final.stdenv.system}.default
2024-08-09 17:34:28 +00:00
final.boost
] ++ final.lib.optionals final.stdenv.isDarwin [
final.darwin.apple_sdk.frameworks.SystemConfiguration
(final.libiconv.override { enableStatic = true; enableShared = false; })
];
NIX_CFLAGS_LINK = final.lib.optionalString final.stdenv.isDarwin "-lc++abi";
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
rec {
magic-nix-cache = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});
default = magic-nix-cache;
};
packages = forEachSupportedSystem ({ pkgs, ... }: rec {
magic-nix-cache = pkgs.magic-nix-cache;
default = magic-nix-cache;
2024-06-12 21:55:39 +00:00
veryLongChain =
let
2024-06-13 01:20:43 +00:00
ctx = ./README.md;
2024-06-12 21:55:39 +00:00
# Function to write the current date to a file
startFile =
pkgs.stdenv.mkDerivation {
name = "start-file";
buildCommand = ''
2024-06-13 01:20:43 +00:00
cat ${ctx} > $out
2024-06-12 21:55:39 +00:00
'';
};
# Recursive function to create a chain of derivations
createChain = n: startFile:
pkgs.stdenv.mkDerivation {
name = "chain-${toString n}";
src =
if n == 0 then
startFile
else createChain (n - 1) startFile;
buildCommand = ''
echo $src > $out
'';
};
in
# Starting point of the chain
2024-06-13 01:20:43 +00:00
createChain 200 startFile;
});
2024-08-09 17:34:28 +00:00
devShells = forEachSupportedSystem ({ system, pkgs, lib }:
let
toolchain = fenixToolchain system;
in
{
default = pkgs.mkShell {
packages = with pkgs; [
2024-08-09 17:34:28 +00:00
toolchain
nix # for linking attic
boost # for linking attic
bashInteractive
pkg-config
cargo-bloat
cargo-edit
cargo-udeps
cargo-watch
bacon
age
2024-08-09 17:34:28 +00:00
] ++ lib.optionals pkgs.stdenv.isDarwin [
libiconv
darwin.apple_sdk.frameworks.SystemConfiguration
];
NIX_CFLAGS_LINK = lib.optionalString pkgs.stdenv.isDarwin "-lc++abi";
2024-08-09 17:34:28 +00:00
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
};
});
2023-05-08 09:48:11 +00:00
};
}