refactor(flake): use flake-parts #7

Merged
jalil merged 1 commit from use-flake-parts into main 2024-10-12 22:36:14 +02:00
2 changed files with 83 additions and 70 deletions
Showing only changes of commit 8242b83dd9 - Show all commits

View file

@ -1,12 +1,32 @@
{ {
"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": 1728492678,
"narHash": "sha256-J+PeFKSDV+pHL7ukkfpVzCOO7mBSrrpJ3svwBFABbhI=", "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "1925c603f17fc89f4c8f6bf6f631a802ad85d784", "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -17,6 +37,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"systems": "systems" "systems": "systems"
} }

126
flake.nix
View file

@ -3,85 +3,77 @@
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:
self, inputs.flake-parts.lib.mkFlake { inherit inputs; } {
nixpkgs, systems = import inputs.systems;
systems, perSystem =
}:
let
forEachSupportedSystem = nixpkgs.lib.genAttrs (import systems);
in
{
checks = forEachSupportedSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (nixpkgs) lib;
in
{ {
fmtRust = pkgs.callPackage ./run-cmd.nix { lib,
src = self; pkgs,
name = "fmt-rust"; self',
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 { };
in
{ {
inherit webnsupdate; packages =
default = webnsupdate; let
cargo-update = pkgs.writeShellApplication { webnsupdate = pkgs.callPackage ./default.nix { };
name = "cargo-update-lockfile"; in
runtimeInputs = with pkgs; [ {
cargo inherit webnsupdate;
gnused default = webnsupdate;
]; cargo-update = pkgs.writeShellApplication {
text = '' name = "cargo-update-lockfile";
CARGO_TERM_COLOR=never cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log runtimeInputs = with pkgs; [
''; cargo
gnused
];
text = ''
CARGO_TERM_COLOR=never cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
'';
};
};
formatter = pkgs.nixfmt-rfc-style;
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 .";
};
}; };
}
);
overlays.default = final: prev: { webnsupdate = final.callPackage ./default.nix { }; }; devShells.default = pkgs.mkShell {
nixosModules.default = ./module.nix;
devShells = forEachSupportedSystem (
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;
};
}; };
} }