refactor(nix): switch to flake-parts

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2023-07-24 12:42:07 +02:00
parent 5cea5ef1e6
commit 63194d47e8
No known key found for this signature in database
GPG Key ID: E13DFD4B47127951
4 changed files with 118 additions and 43 deletions

78
flake.lock generated
View File

@ -16,13 +16,34 @@
"type": "github"
}
},
"flake-utils": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1676283394,
"narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
"lastModified": 1688466019,
"narHash": "sha256-VeM2akYrBYMsb4W/MmBo1zmaMfgbL4cH3Pu8PGyIwJ0=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "8e8d955c22df93dbe24f19ea04f47a74adbdc5ec",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1685518550,
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"type": "github"
},
"original": {
@ -54,11 +75,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1677229269,
"narHash": "sha256-awE2w6oi9rzQ8qj1lwKEDm6qIA0a239fiB+AyPjXR2w=",
"lastModified": 1690083312,
"narHash": "sha256-I3egwgNXavad1eIjWu1kYyi0u73di/sMmlnQIuzQASk=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "7d0ed7f2e5aea07ab22ccb338d27fbe347ed2f11",
"rev": "af8cd5ded7735ca1df1a1174864daab75feeb64a",
"type": "github"
},
"original": {
@ -68,18 +89,20 @@
"type": "github"
}
},
"nixpkgs-stable": {
"nixpkgs-lib": {
"locked": {
"lastModified": 1673800717,
"narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=",
"dir": "lib",
"lastModified": 1688049487,
"narHash": "sha256-100g4iaKC9MalDjUW9iN6Jl/OocTDtXdeAj7pEGIRh4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f",
"rev": "4bc72cae107788bf3f24f30db2e2f685c9298dc9",
"type": "github"
},
"original": {
"dir": "lib",
"owner": "NixOS",
"ref": "nixos-22.11",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
@ -87,21 +110,21 @@
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": [
"flake-utils"
],
"flake-utils": "flake-utils",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
"nixpkgs-stable": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1677160285,
"narHash": "sha256-tBzpCjMP+P3Y3nKLYvdBkXBg3KvTMo3gvi8tLQaqXVY=",
"lastModified": 1689668210,
"narHash": "sha256-XAATwDkaUxH958yXLs1lcEOmU6pSEIkatY3qjqk8X0E=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "2bd861ab81469428d9c823ef72c4bb08372dd2c4",
"rev": "eb433bff05b285258be76513add6f6c57b441775",
"type": "github"
},
"original": {
@ -112,10 +135,25 @@
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View File

@ -3,33 +3,16 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-parts.url = "github:hercules-ci/flake-parts";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs-stable.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, pre-commit-hooks, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pythonPackages = pkgs.python311Packages;
in {
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
black.enable = true;
nixfmt.enable = true;
};
};
};
devShells.default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
packages = (with pythonPackages; [ black ])
++ (with pkgs; [ nixfmt ]);
};
});
outputs = inputs:
inputs.flake-parts.lib.mkFlake
{inherit inputs;}
{imports = [./nix];};
}

11
nix/default.nix Normal file
View File

@ -0,0 +1,11 @@
{...}: {
imports = [
./dev.nix
];
# Supported systems.
systems = [
"x86_64-linux"
"aarch64-linux"
];
}

43
nix/dev.nix Normal file
View File

@ -0,0 +1,43 @@
{
inputs,
self,
...
}: {
perSystem = {
system,
pkgs,
...
}: {
checks = {
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
markdownlint.enable = true;
alejandra.enable = true;
deadnix.enable = true;
nil.enable = true;
black.enable = true;
};
};
};
devShells.default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
packages = [
(pkgs.python3.withPackages (ps:
with ps; [
cachecontrol
filelock
requests
packaging
pydantic
]))
];
};
formatter = pkgs.alejandra;
};
}