Use crane to build faster.

This commit is contained in:
R-VdP 2023-02-09 16:26:23 +00:00
parent 7a8fe92371
commit 49f92dd6b8
No known key found for this signature in database
3 changed files with 123 additions and 56 deletions

72
flake.lock generated
View file

@ -1,5 +1,35 @@
{
"nodes": {
"crane": {
"inputs": {
"flake-compat": [
"pre-commit-hooks",
"flake-compat"
],
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
],
"rust-overlay": [
"rust-overlay"
]
},
"locked": {
"lastModified": 1675902425,
"narHash": "sha256-ASv/7bZIoP/2FON+RNFYYUlmpleZAjKKb4XF1Pmhu4g=",
"owner": "ipetkov",
"repo": "crane",
"rev": "8c34e5ecadc691dd64b31b9317eb35d7cdaa636b",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"devshell": {
"inputs": {
"flake-utils": [
@ -10,11 +40,11 @@
]
},
"locked": {
"lastModified": 1671489820,
"narHash": "sha256-qoei5HDJ8psd1YUPD7DhbHdhLIT9L2nadscp4Qk37uk=",
"lastModified": 1675790942,
"narHash": "sha256-UfXATFXxACtdMQmwRZIdOc6CT4mwgbZBAnGxiUkgUM4=",
"owner": "numtide",
"repo": "devshell",
"rev": "5aa3a8039c68b4bf869327446590f4cdf90bb634",
"rev": "6fe837bb4f540a1832522ec54604c453757836b2",
"type": "github"
},
"original": {
@ -77,11 +107,11 @@
},
"nix-filter": {
"locked": {
"lastModified": 1666547822,
"narHash": "sha256-razwnAybPHyoAyhkKCwXdxihIqJi1G6e1XP4FQOJTEs=",
"lastModified": 1675361037,
"narHash": "sha256-CTbDuDxFD3U3g/dWUB+r+B/snIe+qqP1R+1myuFGe2I=",
"owner": "numtide",
"repo": "nix-filter",
"rev": "1a3b735e13e90a8d2fd5629f2f8363bd7ffbbec7",
"rev": "e1b2f96c2a31415f362268bc48c3fccf47dff6eb",
"type": "github"
},
"original": {
@ -92,11 +122,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1675115703,
"narHash": "sha256-4zetAPSyY0D77x+Ww9QBe8RHn1akvIvHJ/kgg8kGDbk=",
"lastModified": 1675763311,
"narHash": "sha256-bz0Q2H3mxsF1CUfk26Sl9Uzi8/HFjGFD/moZHz1HebU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2caf4ef5005ecc68141ecb4aac271079f7371c44",
"rev": "fab09085df1b60d6a0870c8a89ce26d5a4a708c2",
"type": "github"
},
"original": {
@ -135,11 +165,11 @@
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1675169698,
"narHash": "sha256-C1wFiyJ+4SRvIsFkdMIN1Fa+58APmyTGKWpX9EKOehM=",
"lastModified": 1675688762,
"narHash": "sha256-oit/SxMk0B380ASuztBGQLe8TttO1GJiXF8aZY9AYEc=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "ce4efeec34c6eb35ba07b8fceaae87d6b46c1c5f",
"rev": "ab608394886fb04b8a5df3cb0bab2598400e3634",
"type": "github"
},
"original": {
@ -150,6 +180,7 @@
},
"root": {
"inputs": {
"crane": "crane",
"devshell": "devshell",
"flake-utils": "flake-utils",
"nix-filter": "nix-filter",
@ -169,11 +200,11 @@
]
},
"locked": {
"lastModified": 1675218841,
"narHash": "sha256-/aARbO0v7XlyFaG6vzYKp9ImG6pX5a8Ss4McQ4u9BJs=",
"lastModified": 1675909822,
"narHash": "sha256-DnyjGN0R7Vx/1a9Th9yBp+9tG2QGrh+cZ9j4e3cg3PI=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "b86e094432c5576867b75a2834babf06aafd6c49",
"rev": "50ee0fa4d0eeadd97c63be57e14b01d531e79ed7",
"type": "github"
},
"original": {
@ -183,12 +214,17 @@
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1674470002,
"narHash": "sha256-Tk1VaMeBTMMGEZeqv3TEwrTAdR9fYb3EH/TPI27AdKk=",
"lastModified": 1675939481,
"narHash": "sha256-LwwcWeyExA02GGn8QCQfZjft+blg101OXBQWglCqPVA=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "d5ed9a1e6793f99b2e179d5dec9639e48ef22db7",
"rev": "e9033eca3d7139fd499f310023ddc3bb5abff515",
"type": "github"
},
"original": {

100
flake.nix
View file

@ -4,21 +4,39 @@
flake-utils.url = "github:numtide/flake-utils";
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
nix-filter.url = "github:numtide/nix-filter";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
crane = {
url = "github:ipetkov/crane";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
rust-overlay.follows = "rust-overlay";
flake-compat.follows = "pre-commit-hooks/flake-compat";
};
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs =
@ -27,6 +45,7 @@
, flake-utils
, nix-filter
, rust-overlay
, crane
, devshell
, treefmt-nix
, pre-commit-hooks
@ -40,6 +59,34 @@
};
rust = pkgs.rust-bin.stable."1.66.0";
llvm = pkgs.llvmPackages_latest;
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
];
};
# Build only the cargo dependencies
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
pname = "system-manager";
});
system-manager = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});
system-manager-clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
# treefmt-nix configuration
treefmt.config = {
projectRootFile = "flake.nix";
@ -58,31 +105,12 @@
modules = [
./nix/modules
];
inherit (self.packages.${system}) service-manager;
inherit (self.packages.${system}) system-manager;
};
packages = {
service-manager =
pkgs.rustPlatform.buildRustPackage
{
pname = "service-manager";
version = (pkgs.lib.importTOML ./Cargo.toml).package.version;
src = nix-filter.lib {
root = ./.;
include = [ "Cargo.toml" "Cargo.lock" (nix-filter.lib.inDirectory "src") ];
};
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
dbus
];
};
default = self.packages.${system}.service-manager;
inherit system-manager;
default = self.packages.${system}.system-manager;
};
devShells.default = pkgs.devshell.mkShell {
packages = with pkgs; [
@ -93,6 +121,7 @@
extensions = [ "rust-src" ];
})
(treefmt-nix.lib.mkWrapper pkgs treefmt.config)
self.packages.${system}.system-manager
];
env = [
{
@ -117,10 +146,7 @@
value = "1";
}
];
devshell.startup.pre-commit.text = self.checks.${system}.pre-commit-check.shellHook;
};
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
devshell.startup.pre-commit.text = (pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
check-format = {
@ -135,7 +161,13 @@
pass_filenames = false;
};
};
};
}).shellHook;
};
checks = {
inherit
# Build the crate as part of `nix flake check` for convenience
system-manager
system-manager-clippy;
};
}))
//

View file

@ -95,14 +95,13 @@ fn link_services(services: Services) -> Result<LinkedServices> {
name.to_owned(),
LinkedServiceConfig::new(service_config.to_owned(), linked_path)?,
);
Ok(linked_services)
}
e @ Err(_) => {
log::error!("Error linking service {}, skipping.", name);
log::error!("{:?}", e);
Ok(linked_services)
}
}
};
Ok(linked_services)
},
)
}
@ -190,7 +189,7 @@ where
}
Err(e) => {
log::error!(
"Service {}: Error {}, please consult the logs",
"Service {}: error {}, please consult the logs",
service,
log_action
);