grapevine/flake.nix
Olivia Lee 1b06a1842c
add nixos module test
This is very basic for now, just ensures that the grapevine systemd unit
is able to start. Config validation plus the federation self-test should
hopefully still be able to catch some issues this way.
2025-04-27 15:50:26 -07:00

141 lines
4.7 KiB
Nix

{
# Keep sorted
inputs = {
attic.url = "github:zhaofengli/attic?ref=main";
crane.url = "github:ipetkov/crane?ref=master";
fenix = { url = "github:nix-community/fenix?ref=main"; inputs.nixpkgs.follows = "nixpkgs"; };
flake-compat = { url = "github:edolstra/flake-compat?ref=master"; flake = false; };
flake-utils.url = "github:numtide/flake-utils?ref=main";
nix-filter.url = "github:numtide/nix-filter?ref=main";
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
rocksdb = { url = "github:facebook/rocksdb?ref=v9.10.0"; flake = false; };
};
outputs = inputs:
let
rust-manifest = builtins.fetchurl {
# Keep version in sync with rust-toolchain.toml
url = "https://static.rust-lang.org/dist/channel-rust-1.84.0.toml";
sha256 = "sha256-lMLAupxng4Fd9F1oDw8gx+qA0RuF7ou7xhNU8wgs0PU=";
};
# Keep sorted
mkScope = pkgs: pkgs.lib.makeScope pkgs.newScope (self: {
craneLib =
(inputs.crane.mkLib pkgs).overrideToolchain (_: self.toolchain);
default = self.callPackage ./nix/pkgs/default {};
inherit inputs;
# Return a new scope with overrides applied to the 'default' package
overrideDefaultPackage = args: self.overrideScope (final: prev: {
default = prev.default.override args;
});
rocksdb = self.callPackage ./nix/pkgs/rocksdb {
inherit (pkgs) rocksdb;
};
rust-jemalloc-sys = self.callPackage ./nix/pkgs/rust-jemalloc-sys {
inherit (pkgs) rust-jemalloc-sys;
};
shell = self.callPackage ./nix/shell.nix {};
# The Rust toolchain to use
# Using fromManifestFile and parsing the toolchain file with importTOML
# instead of fromToolchainFile to avoid IFD
toolchain = let
toolchainFile = pkgs.lib.importTOML ./rust-toolchain.toml;
defaultProfileComponents = [
"rustc"
"cargo"
"rust-docs"
"rustfmt"
"clippy"
];
components = defaultProfileComponents ++
toolchainFile.toolchain.components;
targets = toolchainFile.toolchain.targets;
fenix = inputs.fenix.packages.${pkgs.stdenv.buildPlatform.system};
nativeToolchain = (fenix.fromManifestFile rust-manifest)
.withComponents components;
crossComponents = builtins.map
(target:
(fenix.targets.${target}.fromManifestFile rust-manifest)
.rust-std)
targets;
in
fenix.combine ([nativeToolchain] ++ crossComponents);
website-root = self.callPackage ./nix/pkgs/website-root {};
});
in
inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import inputs.nixpkgs {
inherit system;
# Some users find it useful to set this on their Nixpkgs instance and
# we want to support that use case, so we set it here too to help us
# test/ensure that this works.
config.allowAliases = false;
};
in
{
packages = {
default = (mkScope pkgs).default;
website-root = (mkScope pkgs).website-root;
}
//
builtins.listToAttrs
(builtins.concatLists
(builtins.map
(crossSystem:
let
binaryName = "static-${crossSystem}";
pkgsCrossStatic =
(import inputs.nixpkgs {
inherit system;
crossSystem = {
config = crossSystem;
};
# Some users find it useful to set this on their Nixpkgs
# instance and we want to support that use case, so we set
# it here too to help us test/ensure that this works.
config.allowAliases = false;
}).pkgsStatic;
in
[
# An output for a statically-linked binary
{
name = binaryName;
value = (mkScope pkgsCrossStatic).default;
}
]
)
[
"x86_64-unknown-linux-musl"
"aarch64-unknown-linux-musl"
]
)
);
devShells.default = (mkScope pkgs).shell;
devShells.all-features = ((mkScope pkgs).overrideDefaultPackage {
all-features = true;
}).shell;
checks.nixosModule = pkgs.testers.runNixOSTest {
imports = [ (import ./nix/tests/default.nix inputs) ];
};
}
)
//
{
nixosModules.default = import ./nix/modules/default inputs;
};
}