nix/flake.nix

318 lines
12 KiB
Nix
Raw Permalink Normal View History

2019-04-08 15:28:05 +00:00
{
description = "The purely functional package manager";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
inputs.nixpkgs-regression.url = "github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2";
2024-06-03 15:00:48 +00:00
inputs.nixpkgs-23-11.url = "github:NixOS/nixpkgs/a62e6edd6d5e1fa0329b8653c801147986f8d446";
inputs.flake-compat = { url = "github:edolstra/flake-compat"; flake = false; };
2024-07-24 13:24:10 +00:00
inputs.libgit2 = { url = "github:libgit2/libgit2/v1.8.1"; flake = false; };
2019-04-08 15:28:05 +00:00
# dev tooling
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
inputs.git-hooks-nix.url = "github:cachix/git-hooks.nix";
# work around https://github.com/NixOS/nix/issues/7730
inputs.flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
inputs.git-hooks-nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.git-hooks-nix.inputs.nixpkgs-stable.follows = "nixpkgs";
# work around 7730 and https://github.com/NixOS/nix/issues/7807
inputs.git-hooks-nix.inputs.flake-compat.follows = "";
inputs.git-hooks-nix.inputs.gitignore.follows = "";
outputs = inputs@{ self, nixpkgs, nixpkgs-regression, libgit2, ... }:
2019-04-08 15:28:05 +00:00
let
inherit (nixpkgs) lib;
2023-12-02 17:25:47 +00:00
2022-12-06 17:00:10 +00:00
officialRelease = false;
2023-08-23 18:28:24 +00:00
linux32BitSystems = [ "i686-linux" ];
linux64BitSystems = [ "x86_64-linux" "aarch64-linux" ];
2023-08-23 18:28:24 +00:00
linuxSystems = linux32BitSystems ++ linux64BitSystems;
darwinSystems = [ "x86_64-darwin" "aarch64-darwin" ];
systems = linuxSystems ++ darwinSystems;
crossSystems = [
"armv6l-unknown-linux-gnueabihf"
"armv7l-unknown-linux-gnueabihf"
"riscv64-unknown-linux-gnu"
"x86_64-unknown-netbsd"
2024-06-04 08:17:58 +00:00
"x86_64-unknown-freebsd"
"x86_64-w64-mingw32"
];
2023-11-30 22:48:44 +00:00
stdenvs = [
"ccacheStdenv"
"clangStdenv"
"gccStdenv"
"libcxxStdenv"
"stdenv"
];
/**
`flatMapAttrs attrs f` applies `f` to each attribute in `attrs` and
merges the results into a single attribute set.
This can be nested to form a build matrix where all the attributes
generated by the innermost `f` are returned as is.
(Provided that the names are unique.)
See https://nixos.org/manual/nixpkgs/stable/index.html#function-library-lib.attrsets.concatMapAttrs
*/
flatMapAttrs = attrs: f: lib.concatMapAttrs f attrs;
forAllSystems = lib.genAttrs systems;
forAllCrossSystems = lib.genAttrs crossSystems;
forAllStdenvs = f:
lib.listToAttrs
(map
(stdenvName: {
name = "${stdenvName}Packages";
value = f stdenvName;
})
stdenvs);
# We don't apply flake-parts to the whole flake so that non-development attributes
# load without fetching any development inputs.
devFlake = inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ ./maintainers/flake-module.nix ];
systems = lib.subtractLists crossSystems systems;
perSystem = { system, ... }: {
_module.args.pkgs = nixpkgsFor.${system}.native;
};
};
# Memoize nixpkgs for different platforms for efficiency.
nixpkgsFor = forAllSystems
(system: let
make-pkgs = crossSystem: stdenv: import nixpkgs {
localSystem = {
inherit system;
};
crossSystem = if crossSystem == null then null else {
config = crossSystem;
} // lib.optionalAttrs (crossSystem == "x86_64-unknown-freebsd13") {
useLLVM = true;
};
overlays = [
(overlayFor (p: p.${stdenv}))
];
};
stdenvs = forAllStdenvs (make-pkgs null);
native = stdenvs.stdenvPackages;
in {
inherit stdenvs native;
static = native.pkgsStatic;
cross = forAllCrossSystems (crossSystem: make-pkgs crossSystem "stdenv");
});
binaryTarball = nix: pkgs: pkgs.callPackage ./scripts/binary-tarball.nix {
2023-11-30 22:48:44 +00:00
inherit nix;
};
2021-06-26 05:12:03 +00:00
overlayFor = getStdenv: final: prev:
2023-11-30 22:48:44 +00:00
let
stdenv = getStdenv final;
in
2022-01-25 00:28:44 +00:00
{
nixStable = prev.nix;
# A new scope, so that we can use `callPackage` to inject our own interdependencies
# without "polluting" the top level "`pkgs`" attrset.
# This also has the benefit of providing us with a distinct set of packages
# we can iterate over.
nixComponents = lib.makeScope final.nixDependencies.newScope (import ./packaging/components.nix {
inherit (final) lib;
inherit officialRelease;
src = self;
});
# The dependencies are in their own scope, so that they don't have to be
# in Nixpkgs top level `pkgs` or `nixComponents`.
nixDependencies = lib.makeScope final.newScope (import ./packaging/dependencies.nix {
inherit inputs stdenv;
pkgs = final;
});
2024-10-17 19:38:05 +00:00
nix = final.nixComponents.nix-cli;
2023-02-06 15:36:57 +00:00
2024-04-21 11:52:56 +00:00
# See https://github.com/NixOS/nixpkgs/pull/214409
# Remove when fixed in this flake's nixpkgs
pre-commit =
if prev.stdenv.hostPlatform.system == "i686-linux"
then (prev.pre-commit.override (o: { dotnet-sdk = ""; })).overridePythonAttrs (o: { doCheck = false; })
else prev.pre-commit;
2024-01-17 18:08:03 +00:00
};
in {
# A Nixpkgs overlay that overrides the 'nix' and
# 'nix-perl-bindings' packages.
overlays.default = overlayFor (p: p.stdenv);
hydraJobs = import ./packaging/hydra.nix {
inherit
inputs
binaryTarball
forAllCrossSystems
forAllSystems
lib
linux64BitSystems
nixpkgsFor
self
officialRelease
;
};
2021-10-15 10:36:29 +00:00
checks = forAllSystems (system: {
binaryTarball = self.hydraJobs.binaryTarball.${system};
installTests = self.hydraJobs.installTests.${system};
nixpkgsLibTests = self.hydraJobs.tests.nixpkgsLibTests.${system};
2023-12-09 18:55:47 +00:00
rl-next =
let pkgs = nixpkgsFor.${system}.native;
in pkgs.buildPackages.runCommand "test-rl-next-release-notes" { } ''
2024-06-03 16:38:38 +00:00
LANG=C.UTF-8 ${pkgs.changelog-d}/bin/changelog-d ${./doc/manual/rl-next} >$out
2023-12-09 18:55:47 +00:00
'';
2024-05-27 07:58:49 +00:00
repl-completion = nixpkgsFor.${system}.native.callPackage ./tests/repl-completion.nix { };
} // (lib.optionalAttrs (builtins.elem system linux64BitSystems)) {
2021-11-24 08:19:29 +00:00
dockerImage = self.hydraJobs.dockerImage.${system};
fetch-git = self.hydraJobs.tests.fetch-git;
} // (lib.optionalAttrs (!(builtins.elem system linux32BitSystems))) {
# Some perl dependencies are broken on i686-linux.
# Since the support is only best-effort there, disable the perl
# bindings
# Temporarily disabled because GitHub Actions OOM issues. Once
# the old build system is gone and we are back to one build
# system, we should reenable this.
#perlBindings = self.hydraJobs.perlBindings.${system};
}
# Add "passthru" tests
// flatMapAttrs ({
"" = nixpkgsFor.${system}.native;
} // lib.optionalAttrs (! nixpkgsFor.${system}.native.stdenv.hostPlatform.isDarwin) {
# TODO: enable static builds for darwin, blocked on:
# https://github.com/NixOS/nixpkgs/issues/320448
# TODO: disabled to speed up GHA CI.
#"static-" = nixpkgsFor.${system}.static;
})
2024-06-27 21:28:31 +00:00
(nixpkgsPrefix: nixpkgs:
flatMapAttrs nixpkgs.nixComponents
(pkgName: pkg:
flatMapAttrs pkg.tests or {}
(testName: test: {
"${nixpkgsPrefix}${pkgName}-${testName}" = test;
})
)
// lib.optionalAttrs (nixpkgs.stdenv.hostPlatform == nixpkgs.stdenv.buildPlatform) {
"${nixpkgsPrefix}nix-functional-tests" = nixpkgs.nixComponents.nix-functional-tests;
}
)
// devFlake.checks.${system} or {}
);
packages = forAllSystems (system:
{ # Here we put attributes that map 1:1 into packages.<system>, ie
# for which we don't apply the full build matrix such as cross or static.
inherit (nixpkgsFor.${system}.native)
changelog-d;
2024-10-17 19:38:05 +00:00
# TODO probably should be `nix-cli`
default = self.packages.${system}.nix-everything;
nix-manual = nixpkgsFor.${system}.native.nixComponents.nix-manual;
nix-internal-api-docs = nixpkgsFor.${system}.native.nixComponents.nix-internal-api-docs;
nix-external-api-docs = nixpkgsFor.${system}.native.nixComponents.nix-external-api-docs;
Build `nix-util` with Meson The idea is two-fold: - Replace autotools with Meson - Build each library in its own derivation The interaction of these two features is that Meson's "subprojects" feature (https://mesonbuild.com/Subprojects) allows us to have single dev shell for building all libraries still, while also building things separately. This allows us to break up the build without a huge productivity lost. I tested the Linux native build, and NetBSD and Windows cross builds. Also do some clean ups of the Flake in the process of supporting new jobs. Special thanks to everyone that has worked on a Meson port so far, @p01arst0rm and @Qyriad in particular. Co-Authored-By: p01arst0rm <polar@ever3st.com> Co-Authored-By: Artemis Tosini <lix@artem.ist> Co-Authored-By: Artemis Tosini <me@artem.ist> Co-Authored-By: Felix Uhl <felix.uhl@outlook.com> Co-Authored-By: Jade Lovelace <lix@jade.fyi> Co-Authored-By: Lunaphied <lunaphied@lunaphied.me> Co-Authored-By: Maximilian Bosch <maximilian@mbosch.me> Co-Authored-By: Pierre Bourdon <delroth@gmail.com> Co-Authored-By: Qyriad <qyriad@qyriad.me> Co-Authored-By: Rebecca Turner <rbt@sent.as> Co-Authored-By: Winter <winter@winter.cafe> Co-Authored-By: eldritch horrors <pennae@lix.systems> Co-Authored-By: jade <lix@jade.fyi> Co-Authored-By: julia <midnight@trainwit.ch> Co-Authored-By: rebecca “wiggles” turner <rbt@sent.as> Co-Authored-By: wiggles dog <rbt@sent.as> Co-Authored-By: fricklerhandwerk <valentin@fricklerhandwerk.de> Co-authored-By: Eli Schwartz <eschwartz93@gmail.com> Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2024-06-04 13:28:27 +00:00
}
# We need to flatten recursive attribute sets of derivations to pass `flake check`.
// flatMapAttrs
{ # Components we'll iterate over in the upcoming lambda
"nix-util" = { };
"nix-util-c" = { };
"nix-util-test-support" = { };
"nix-util-tests" = { };
"nix-store" = { };
"nix-store-c" = { };
"nix-store-test-support" = { };
"nix-store-tests" = { };
"nix-fetchers" = { };
"nix-fetchers-tests" = { };
"nix-expr" = { };
"nix-expr-c" = { };
"nix-expr-test-support" = { };
"nix-expr-tests" = { };
"nix-flake" = { };
"nix-flake-tests" = { };
"nix-main" = { };
"nix-main-c" = { };
"nix-cmd" = { };
"nix-cli" = { };
2024-10-17 19:38:05 +00:00
"nix-everything" = { };
"nix-functional-tests" = { supportsCross = false; };
"nix-perl-bindings" = { supportsCross = false; };
}
(pkgName: { supportsCross ? true }: {
# These attributes go right into `packages.<system>`.
"${pkgName}" = nixpkgsFor.${system}.native.nixComponents.${pkgName};
"${pkgName}-static" = nixpkgsFor.${system}.static.nixComponents.${pkgName};
}
// lib.optionalAttrs supportsCross (flatMapAttrs (lib.genAttrs crossSystems (_: { })) (crossSystem: {}: {
# These attributes go right into `packages.<system>`.
"${pkgName}-${crossSystem}" = nixpkgsFor.${system}.cross.${crossSystem}.nixComponents.${pkgName};
}))
// flatMapAttrs (lib.genAttrs stdenvs (_: { })) (stdenvName: {}: {
# These attributes go right into `packages.<system>`.
"${pkgName}-${stdenvName}" = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".nixComponents.${pkgName};
})
)
Build `nix-util` with Meson The idea is two-fold: - Replace autotools with Meson - Build each library in its own derivation The interaction of these two features is that Meson's "subprojects" feature (https://mesonbuild.com/Subprojects) allows us to have single dev shell for building all libraries still, while also building things separately. This allows us to break up the build without a huge productivity lost. I tested the Linux native build, and NetBSD and Windows cross builds. Also do some clean ups of the Flake in the process of supporting new jobs. Special thanks to everyone that has worked on a Meson port so far, @p01arst0rm and @Qyriad in particular. Co-Authored-By: p01arst0rm <polar@ever3st.com> Co-Authored-By: Artemis Tosini <lix@artem.ist> Co-Authored-By: Artemis Tosini <me@artem.ist> Co-Authored-By: Felix Uhl <felix.uhl@outlook.com> Co-Authored-By: Jade Lovelace <lix@jade.fyi> Co-Authored-By: Lunaphied <lunaphied@lunaphied.me> Co-Authored-By: Maximilian Bosch <maximilian@mbosch.me> Co-Authored-By: Pierre Bourdon <delroth@gmail.com> Co-Authored-By: Qyriad <qyriad@qyriad.me> Co-Authored-By: Rebecca Turner <rbt@sent.as> Co-Authored-By: Winter <winter@winter.cafe> Co-Authored-By: eldritch horrors <pennae@lix.systems> Co-Authored-By: jade <lix@jade.fyi> Co-Authored-By: julia <midnight@trainwit.ch> Co-Authored-By: rebecca “wiggles” turner <rbt@sent.as> Co-Authored-By: wiggles dog <rbt@sent.as> Co-Authored-By: fricklerhandwerk <valentin@fricklerhandwerk.de> Co-authored-By: Eli Schwartz <eschwartz93@gmail.com> Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2024-06-04 13:28:27 +00:00
// lib.optionalAttrs (builtins.elem system linux64BitSystems) {
dockerImage =
let
pkgs = nixpkgsFor.${system}.native;
image = import ./docker.nix { inherit pkgs; tag = pkgs.nix.version; };
in
pkgs.runCommand
"docker-image-tarball-${pkgs.nix.version}"
{ meta.description = "Docker image with Nix for ${system}"; }
''
mkdir -p $out/nix-support
image=$out/image.tar.gz
ln -s ${image} $image
echo "file binary-dist $image" >> $out/nix-support/hydra-build-products
'';
Build `nix-util` with Meson The idea is two-fold: - Replace autotools with Meson - Build each library in its own derivation The interaction of these two features is that Meson's "subprojects" feature (https://mesonbuild.com/Subprojects) allows us to have single dev shell for building all libraries still, while also building things separately. This allows us to break up the build without a huge productivity lost. I tested the Linux native build, and NetBSD and Windows cross builds. Also do some clean ups of the Flake in the process of supporting new jobs. Special thanks to everyone that has worked on a Meson port so far, @p01arst0rm and @Qyriad in particular. Co-Authored-By: p01arst0rm <polar@ever3st.com> Co-Authored-By: Artemis Tosini <lix@artem.ist> Co-Authored-By: Artemis Tosini <me@artem.ist> Co-Authored-By: Felix Uhl <felix.uhl@outlook.com> Co-Authored-By: Jade Lovelace <lix@jade.fyi> Co-Authored-By: Lunaphied <lunaphied@lunaphied.me> Co-Authored-By: Maximilian Bosch <maximilian@mbosch.me> Co-Authored-By: Pierre Bourdon <delroth@gmail.com> Co-Authored-By: Qyriad <qyriad@qyriad.me> Co-Authored-By: Rebecca Turner <rbt@sent.as> Co-Authored-By: Winter <winter@winter.cafe> Co-Authored-By: eldritch horrors <pennae@lix.systems> Co-Authored-By: jade <lix@jade.fyi> Co-Authored-By: julia <midnight@trainwit.ch> Co-Authored-By: rebecca “wiggles” turner <rbt@sent.as> Co-Authored-By: wiggles dog <rbt@sent.as> Co-Authored-By: fricklerhandwerk <valentin@fricklerhandwerk.de> Co-authored-By: Eli Schwartz <eschwartz93@gmail.com> Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2024-06-04 13:28:27 +00:00
});
devShells = let
makeShell = import ./packaging/dev-shell.nix { inherit lib devFlake; };
prefixAttrs = prefix: lib.concatMapAttrs (k: v: { "${prefix}-${k}" = v; });
in
forAllSystems (system:
prefixAttrs "native" (forAllStdenvs (stdenvName: makeShell {
pkgs = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages";
})) //
lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.isDarwin) (
prefixAttrs "static" (forAllStdenvs (stdenvName: makeShell {
pkgs = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".pkgsStatic;
})) //
prefixAttrs "cross" (forAllCrossSystems (crossSystem: makeShell {
pkgs = nixpkgsFor.${system}.cross.${crossSystem};
}))
) //
{
default = self.devShells.${system}.native-stdenvPackages;
}
);
2019-04-08 15:28:05 +00:00
};
}