refactor(flake): use flake-parts
Some checks failed
/ check (push) Failing after 2s
/ build (push) Failing after 1s

This makes it easier to split up the flake in the future.
This commit is contained in:
Jalil David Salamé Messina 2024-10-12 22:29:38 +02:00
parent 2a18f6bedb
commit 2970e7d12b
Signed by: jalil
GPG key ID: F016B9E770737A0B
2 changed files with 80 additions and 67 deletions

View file

@ -1,5 +1,25 @@
{ {
"nodes": { "nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1727826117,
"narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1727348695, "lastModified": 1727348695,
@ -17,6 +37,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"systems": "systems" "systems": "systems"
} }

View file

@ -3,49 +3,26 @@
inputs = { inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable"; nixpkgs.url = "nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default"; systems.url = "github:nix-systems/default";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
}; };
outputs = outputs =
inputs:
inputs.flake-parts.mkFlake {
systems = import inputs.system;
perSystem =
{ {
self, lib,
nixpkgs, pkgs,
systems, self',
...
}: }:
let
forEachSupportedSystem = nixpkgs.lib.genAttrs (import systems);
in
{ {
checks = forEachSupportedSystem ( packages =
system:
let let
pkgs = nixpkgs.legacyPackages.${system};
inherit (nixpkgs) lib;
in
{
fmtRust = pkgs.callPackage ./run-cmd.nix {
src = self;
name = "fmt-rust";
extraNativeBuildInputs = [ pkgs.rustfmt ];
cmd = "${lib.getExe pkgs.cargo} fmt --all --check --verbose";
};
fmtNix = pkgs.callPackage ./run-cmd.nix {
src = self;
name = "fmt-nix";
cmd = "${lib.getExe self.formatter.${system}} --check .";
};
lintNix = pkgs.callPackage ./run-cmd.nix {
src = self;
name = "lint-nix";
cmd = "${lib.getExe pkgs.statix} check .";
};
}
);
formatter = forEachSupportedSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
packages = forEachSupportedSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
webnsupdate = pkgs.callPackage ./default.nix { }; webnsupdate = pkgs.callPackage ./default.nix { };
in in
{ {
@ -61,27 +38,42 @@
CARGO_TERM_COLOR=never cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log CARGO_TERM_COLOR=never cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
''; '';
}; };
} };
);
overlays.default = final: prev: { webnsupdate = final.callPackage ./default.nix { }; }; formatter = pkgs.nixfmt-rfc-style;
nixosModules.default = ./module.nix; checks = {
fmtRust = pkgs.callPackage ./run-cmd.nix {
src = inputs.self;
name = "fmt-rust";
extraNativeBuildInputs = [ pkgs.rustfmt ];
cmd = "${lib.getExe pkgs.cargo} fmt --all --check --verbose";
};
fmtNix = pkgs.callPackage ./run-cmd.nix {
src = inputs.self;
name = "fmt-nix";
cmd = "${lib.getExe self'.formatter} --check .";
};
lintNix = pkgs.callPackage ./run-cmd.nix {
src = inputs.self;
name = "lint-nix";
cmd = "${lib.getExe pkgs.statix} check .";
};
};
devShells = forEachSupportedSystem ( devShells.default = pkgs.mkShell {
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
default = pkgs.mkShell {
packages = [ packages = [
pkgs.cargo-insta pkgs.cargo-insta
pkgs.cargo-udeps pkgs.cargo-udeps
pkgs.mold pkgs.mold
]; ];
}; };
} };
);
flake = {
overlays.default = final: prev: { webnsupdate = final.callPackage ./default.nix { }; };
nixosModules.default = ./module.nix;
};
}; };
} }