Major overhaul of the nix side of things, part II.
This commit is contained in:
parent
9759c2da12
commit
ce4cf7149d
7 changed files with 371 additions and 303 deletions
240
flake.nix
240
flake.nix
|
|
@ -1,6 +1,12 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
# We re-use the systemd lib from NixOS, this input allows to import the needed modules.
|
||||
# TODO: is there a better way to do this?
|
||||
nixpkgs-nonflake = {
|
||||
url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake = false;
|
||||
};
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
devshell = {
|
||||
url = "github:numtide/devshell";
|
||||
|
|
@ -41,6 +47,7 @@
|
|||
outputs =
|
||||
{ self
|
||||
, nixpkgs
|
||||
, nixpkgs-nonflake
|
||||
, flake-utils
|
||||
, rust-overlay
|
||||
, crane
|
||||
|
|
@ -49,137 +56,140 @@
|
|||
, pre-commit-hooks
|
||||
,
|
||||
}:
|
||||
(flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ (import rust-overlay) devshell.overlays.default ];
|
||||
};
|
||||
# TODO Pin the version for release
|
||||
rust = pkgs.rust-bin.stable.latest;
|
||||
llvm = pkgs.llvmPackages_latest;
|
||||
(flake-utils.lib.eachSystem
|
||||
(with flake-utils.lib.system; [ x86_64-linux aarch64-linux ])
|
||||
(system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ (import rust-overlay) devshell.overlays.default ];
|
||||
};
|
||||
# TODO Pin the version for release
|
||||
rust = pkgs.rust-bin.stable.latest;
|
||||
llvm = pkgs.llvmPackages_latest;
|
||||
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain rust.default;
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain rust.default;
|
||||
|
||||
# Common derivation arguments used for all builds
|
||||
commonArgs = {
|
||||
src = craneLib.cleanCargoSource ./.;
|
||||
buildInputs = with pkgs; [
|
||||
dbus
|
||||
];
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkg-config
|
||||
];
|
||||
};
|
||||
# Common derivation arguments used for all builds
|
||||
commonArgs = {
|
||||
src = craneLib.cleanCargoSource ./.;
|
||||
buildInputs = with pkgs; [
|
||||
dbus
|
||||
];
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkg-config
|
||||
];
|
||||
};
|
||||
|
||||
# Build only the cargo dependencies
|
||||
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
|
||||
pname = "system-manager";
|
||||
});
|
||||
# Build only the cargo dependencies
|
||||
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
|
||||
pname = "system-manager";
|
||||
});
|
||||
|
||||
system-manager = craneLib.buildPackage (commonArgs // {
|
||||
pname = "system-manager";
|
||||
inherit cargoArtifacts;
|
||||
});
|
||||
system-manager = craneLib.buildPackage (commonArgs // {
|
||||
pname = "system-manager";
|
||||
inherit cargoArtifacts;
|
||||
});
|
||||
|
||||
system-manager-clippy = craneLib.cargoClippy (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
});
|
||||
system-manager-clippy = craneLib.cargoClippy (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
});
|
||||
|
||||
# treefmt-nix configuration
|
||||
treefmt.config = {
|
||||
projectRootFile = "flake.nix";
|
||||
programs = {
|
||||
nixpkgs-fmt.enable = true;
|
||||
rustfmt = {
|
||||
enable = true;
|
||||
package = rust.rustfmt;
|
||||
# treefmt-nix configuration
|
||||
treefmt.config = {
|
||||
projectRootFile = "flake.nix";
|
||||
programs = {
|
||||
nixpkgs-fmt.enable = true;
|
||||
rustfmt = {
|
||||
enable = true;
|
||||
package = rust.rustfmt;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
packages = {
|
||||
inherit system-manager;
|
||||
default = self.packages.${system}.system-manager;
|
||||
};
|
||||
in
|
||||
{
|
||||
packages = {
|
||||
inherit system-manager;
|
||||
default = self.packages.${system}.system-manager;
|
||||
};
|
||||
|
||||
devShells.default = pkgs.devshell.mkShell {
|
||||
packages = with pkgs; [
|
||||
llvm.clang
|
||||
openssl
|
||||
pkg-config
|
||||
(rust.default.override {
|
||||
extensions = [ "rust-src" ];
|
||||
})
|
||||
(treefmt-nix.lib.mkWrapper pkgs treefmt.config)
|
||||
];
|
||||
env = [
|
||||
{
|
||||
name = "PKG_CONFIG_PATH";
|
||||
value = pkgs.lib.makeSearchPath "lib/pkgconfig" [
|
||||
pkgs.dbus.dev
|
||||
pkgs.systemdMinimal.dev
|
||||
];
|
||||
}
|
||||
{
|
||||
name = "LIBCLANG_PATH";
|
||||
value = "${llvm.libclang}/lib";
|
||||
}
|
||||
{
|
||||
# for rust-analyzer
|
||||
name = "RUST_SRC_PATH";
|
||||
value = "${rust.rust-src}";
|
||||
}
|
||||
{
|
||||
name = "RUST_BACKTRACE";
|
||||
value = "1";
|
||||
}
|
||||
{
|
||||
name = "RUSTFLAGS";
|
||||
value =
|
||||
let
|
||||
getLib = pkg: "${pkgs.lib.getLib pkg}/lib";
|
||||
in
|
||||
pkgs.lib.concatStringsSep " " [
|
||||
"-L${getLib pkgs.systemdMinimal} -lsystemd"
|
||||
devShells.default = pkgs.devshell.mkShell {
|
||||
packages = with pkgs; [
|
||||
llvm.clang
|
||||
openssl
|
||||
pkg-config
|
||||
(rust.default.override {
|
||||
extensions = [ "rust-src" ];
|
||||
})
|
||||
(treefmt-nix.lib.mkWrapper pkgs treefmt.config)
|
||||
];
|
||||
env = [
|
||||
{
|
||||
name = "PKG_CONFIG_PATH";
|
||||
value = pkgs.lib.makeSearchPath "lib/pkgconfig" [
|
||||
pkgs.dbus.dev
|
||||
pkgs.systemdMinimal.dev
|
||||
];
|
||||
}
|
||||
{
|
||||
name = "DEVSHELL_NO_MOTD";
|
||||
value = "1";
|
||||
}
|
||||
];
|
||||
devshell.startup.pre-commit.text = (pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
check-format = {
|
||||
enable = true;
|
||||
entry = "treefmt --fail-on-change";
|
||||
}
|
||||
{
|
||||
name = "LIBCLANG_PATH";
|
||||
value = "${llvm.libclang}/lib";
|
||||
}
|
||||
{
|
||||
# for rust-analyzer
|
||||
name = "RUST_SRC_PATH";
|
||||
value = "${rust.rust-src}";
|
||||
}
|
||||
{
|
||||
name = "RUST_BACKTRACE";
|
||||
value = "1";
|
||||
}
|
||||
{
|
||||
name = "RUSTFLAGS";
|
||||
value =
|
||||
let
|
||||
getLib = pkg: "${pkgs.lib.getLib pkg}/lib";
|
||||
in
|
||||
pkgs.lib.concatStringsSep " " [
|
||||
"-L${getLib pkgs.systemdMinimal} -lsystemd"
|
||||
];
|
||||
}
|
||||
{
|
||||
name = "DEVSHELL_NO_MOTD";
|
||||
value = "1";
|
||||
}
|
||||
];
|
||||
devshell.startup.pre-commit.text = (pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
check-format = {
|
||||
enable = true;
|
||||
entry = "treefmt --fail-on-change";
|
||||
};
|
||||
cargo-clippy = {
|
||||
enable = true;
|
||||
description = "Lint Rust code.";
|
||||
entry = "cargo-clippy --workspace -- -D warnings";
|
||||
files = "\\.rs$";
|
||||
pass_filenames = false;
|
||||
};
|
||||
};
|
||||
cargo-clippy = {
|
||||
enable = true;
|
||||
description = "Lint Rust code.";
|
||||
entry = "cargo-clippy --workspace -- -D warnings";
|
||||
files = "\\.rs$";
|
||||
pass_filenames = false;
|
||||
};
|
||||
};
|
||||
}).shellHook;
|
||||
};
|
||||
}).shellHook;
|
||||
};
|
||||
|
||||
checks = {
|
||||
inherit
|
||||
# Build the crate as part of `nix flake check` for convenience
|
||||
system-manager
|
||||
system-manager-clippy;
|
||||
};
|
||||
}))
|
||||
checks = {
|
||||
inherit
|
||||
# Build the crate as part of `nix flake check` for convenience
|
||||
system-manager
|
||||
system-manager-clippy;
|
||||
};
|
||||
}))
|
||||
//
|
||||
{
|
||||
lib = import ./nix/lib.nix {
|
||||
inherit nixpkgs self;
|
||||
nixosModules = "${nixpkgs-nonflake}/nixos";
|
||||
};
|
||||
|
||||
systemConfigs.default = self.lib.makeSystemConfig {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue