nix-init/flake.nix

216 lines
5.9 KiB
Nix
Raw Normal View History

2023-01-15 07:41:10 +03:00
{
2023-09-18 23:46:16 +03:00
description = "Generate Nix packages from URLs with hash prefetching, dependency inference, license detection, and more";
2023-01-15 07:41:10 +03:00
inputs = {
2023-02-24 20:11:19 +03:00
crane = {
2023-03-20 03:34:36 +03:00
url = "github:ipetkov/crane";
2023-09-18 23:46:16 +03:00
inputs = {
nixpkgs.follows = "nixpkgs";
flake-compat.follows = "";
rust-overlay.follows = "";
};
2023-02-24 20:11:19 +03:00
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
};
2023-06-15 03:48:05 +03:00
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
2023-01-15 07:41:10 +03:00
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
2023-06-15 03:48:05 +03:00
outputs = inputs@{ crane, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
2023-06-15 03:48:05 +03:00
perSystem = { inputs', lib, pkgs, self', system, ... }:
let
inherit (builtins)
attrValues
getAttr
listToAttrs
readDir
;
inherit (lib)
concatMapAttrs
flip
getExe
hasSuffix
importTOML
licenses
maintainers
nameValuePair
optionalAttrs
optionals
pipe
sourceByRegex
;
inherit (crane.lib.${system}.overrideToolchain inputs'.fenix.packages.default.toolchain)
buildDepsOnly
buildPackage
cargoClippy
cargoFmt
cargoNextest
;
inherit (pkgs)
bzip2
callPackage
curl
darwin
installShellFiles
2023-06-21 21:26:41 +03:00
libgit2
2023-06-15 03:48:05 +03:00
libiconv
mkShell
nix
nixpkgs-fmt
nurl
openssl
pkg-config
spdx-license-list-data
stdenv
zlib
zstd
;
src = sourceByRegex ./. [
"(license-store-cache|src)(/.*)?"
''Cargo\.(toml|lock)''
''build\.rs''
''rustfmt\.toml''
];
2023-07-25 19:03:52 +03:00
get-nix-license = callPackage ./src/get_nix_license.nix { };
2023-06-15 03:48:05 +03:00
license-store-cache = buildPackage {
pname = "license-store-cache";
inherit src;
buildInputs = optionals stdenv.isDarwin [
libiconv
];
2023-01-15 07:41:10 +03:00
2023-06-15 03:48:05 +03:00
doCheck = false;
doNotRemoveReferencesToVendorDir = true;
cargoArtifacts = null;
cargoExtraArgs = "-p license-store-cache";
CARGO_PROFILE = "";
postInstall = ''
cache=$(mktemp)
$out/bin/license-store-cache $cache ${spdx-license-list-data.json}/json/details
rm -rf $out
mv $cache $out
'';
};
args = {
inherit src;
nativeBuildInputs = [
curl
installShellFiles
pkg-config
2023-03-18 21:52:29 +03:00
];
2023-06-15 03:48:05 +03:00
buildInputs = [
bzip2
curl
2023-06-21 21:26:41 +03:00
libgit2
2023-06-15 03:48:05 +03:00
openssl
zlib
zstd
] ++ optionals stdenv.isDarwin [
2023-10-09 05:57:03 +03:00
darwin.apple_sdk.frameworks.SystemConfiguration
2023-06-15 03:48:05 +03:00
] ++ optionals (stdenv.isDarwin && stdenv.isx86_64) [
darwin.apple_sdk.frameworks.CoreFoundation
];
cargoArtifacts = buildDepsOnly args;
cargoExtraArgs = "--no-default-features";
2023-06-30 02:21:45 +03:00
doInstallCargoArtifacts = false;
2023-06-15 03:48:05 +03:00
postPatch = ''
mkdir -p data
2023-07-25 19:03:52 +03:00
ln -s ${get-nix-license} data/get_nix_license.rs
2023-06-15 03:48:05 +03:00
ln -s ${license-store-cache} data/license-store-cache.zstd
'';
env = {
GEN_ARTIFACTS = "artifacts";
NIX = getExe nix;
NURL = getExe nurl;
ZSTD_SYS_USE_PKG_CONFIG = true;
2023-03-18 22:14:10 +03:00
};
2023-06-15 03:48:05 +03:00
meta = {
license = licenses.mpl20;
maintainers = with maintainers; [ figsoda ];
};
};
in
{
checks = {
build = self'.packages.default;
clippy = cargoClippy (args // {
cargoClippyExtraArgs = "-- -D warnings";
});
fmt = cargoFmt (removeAttrs args [ "cargoExtraArgs" ]);
test =
let
fixtures = src + "/src/lang/rust/fixtures";
lock = src + "/Cargo.lock";
getPackages = flip pipe [
importTOML
(getAttr "package")
(map ({ name, version, ... }@pkg:
nameValuePair "${name}-${version}" pkg))
listToAttrs
];
in
cargoNextest (args // {
2023-06-30 02:49:58 +03:00
cargoArtifacts = null;
2023-06-15 03:48:05 +03:00
cargoLockParsed = importTOML lock // {
package = attrValues (getPackages lock // concatMapAttrs
(name: _: optionalAttrs
(hasSuffix "-lock.toml" name)
(getPackages (fixtures + "/${name}")))
(readDir fixtures));
};
});
};
devShells.default = mkShell {
NIX_INIT_LOG = "nix_init=trace";
RUST_BACKTRACE = true;
shellHook = ''
mkdir -p data
2023-07-25 19:03:52 +03:00
ln -sf ${get-nix-license} data/get_nix_license.rs
2023-06-15 03:48:05 +03:00
ln -sf ${license-store-cache} data/license-store-cache.zstd
'';
};
formatter = nixpkgs-fmt;
packages.default = buildPackage (args // {
doCheck = false;
postInstall = ''
installManPage artifacts/nix-init.1
installShellCompletion artifacts/nix-init.{bash,fish} --zsh artifacts/_nix-init
'';
2023-03-18 21:52:29 +03:00
});
2023-06-15 03:48:05 +03:00
};
};
2023-01-15 07:41:10 +03:00
}