summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkoverstreet <kent.overstreet@gmail.com>2024-05-22 16:58:18 -0400
committerGitHub <noreply@github.com>2024-05-22 16:58:18 -0400
commit764031a4aa7ed74697ba231c3363f5bfc420aa8e (patch)
tree16dd3404af325aafb0f3f48a38b8347220e1f928
parent7d795ddb25a9533a6103a3ab00c8401ae8e1f35b (diff)
parent56a9580aeb88c4945d0c6dfa23b5051a5b5c520b (diff)
Merge pull request #272 from tmuehlbacher/flake-overhaul
Flake overhaul
-rw-r--r--.editorconfig22
-rw-r--r--build.nix37
-rw-r--r--default.nix15
-rw-r--r--flake.lock70
-rw-r--r--flake.nix105
5 files changed, 176 insertions, 73 deletions
diff --git a/.editorconfig b/.editorconfig
index 86ba2134..58738895 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,6 +1,26 @@
-indent_style = tab
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
indent_size = 8
+indent_style = tab
+insert_final_newline = true
+max_line_length = 80
+tab_width = 8
+trim_trailing_whitespace = true
+
+[.git/**]
+max_line_length = 72
[*.nix]
indent_style = space
indent_size = 2
+
+[Cargo.toml]
+indent_style = space
+indent_size = 4
+
+[*.rs]
+indent_style = space
+indent_size = 4
diff --git a/build.nix b/build.nix
index 4a4b7b06..4927519c 100644
--- a/build.nix
+++ b/build.nix
@@ -1,12 +1,31 @@
-{ lib, stdenv, pkg-config, attr, libuuid, libsodium, keyutils, liburcu, zlib
-, libaio, udev, zstd, lz4, nix-gitignore, rustPlatform, rustc, cargo, fuse3
-, fuseSupport ? false, }:
+{
+ lib,
+ stdenv,
+ pkg-config,
+ attr,
+ libuuid,
+ libsodium,
+ keyutils,
+ liburcu,
+ zlib,
+ libaio,
+ udev,
+ zstd,
+ lz4,
+ nix-gitignore,
+ rustPlatform,
+ rustc,
+ cargo,
+ fuse3,
+ fuseSupport ? false,
+}:
let
src = nix-gitignore.gitignoreSource [ ] ./.;
commit = lib.strings.substring 0 7 (builtins.readFile ./.bcachefs_revision);
version = "git-${commit}";
-in stdenv.mkDerivation {
+in
+stdenv.mkDerivation {
inherit src version;
pname = "bcachefs-tools";
@@ -39,11 +58,13 @@ in stdenv.mkDerivation {
# when git-based crates are updated, run:
# nix run github:Mic92/nix-update -- --version=skip --flake default
# to update the hashes
- cargoDeps = rustPlatform.importCargoLock {
- lockFile = "${src}/Cargo.lock";
- };
+ cargoDeps = rustPlatform.importCargoLock { lockFile = "${src}/Cargo.lock"; };
- makeFlags = [ "DESTDIR=${placeholder "out"}" "PREFIX=" "VERSION=${commit}" ];
+ makeFlags = [
+ "DESTDIR=${placeholder "out"}"
+ "PREFIX="
+ "VERSION=${commit}"
+ ];
dontStrip = true;
checkPhase = "./target/release/bcachefs version";
diff --git a/default.nix b/default.nix
index 80aeb433..6466507b 100644
--- a/default.nix
+++ b/default.nix
@@ -1,6 +1,9 @@
-(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
-in fetchTarball {
- url =
- "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
- sha256 = lock.nodes.flake-compat.locked.narHash;
-}) { src = ./.; }).defaultNix
+(import (
+ let
+ lock = builtins.fromJSON (builtins.readFile ./flake.lock);
+ in
+ fetchTarball {
+ url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
+ sha256 = lock.nodes.flake-compat.locked.narHash;
+ }
+) { src = ./.; }).defaultNix
diff --git a/flake.lock b/flake.lock
index 413959e4..58b8eeb5 100644
--- a/flake.lock
+++ b/flake.lock
@@ -16,13 +16,31 @@
"type": "github"
}
},
+ "flake-parts": {
+ "inputs": {
+ "nixpkgs-lib": "nixpkgs-lib"
+ },
+ "locked": {
+ "lastModified": 1715865404,
+ "narHash": "sha256-/GJvTdTpuDjNn84j82cU6bXztE0MSkdnTWClUCRub78=",
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "rev": "8dc45382d5206bd292f9c2768b8058a8fd8311d9",
+ "type": "github"
+ },
+ "original": {
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "type": "github"
+ }
+ },
"nixpkgs": {
"locked": {
- "lastModified": 1698924604,
- "narHash": "sha256-GCFbkl2tj8fEZBZCw3Tc0AkGo0v+YrQlohhEGJ/X4s0=",
+ "lastModified": 1716293225,
+ "narHash": "sha256-pU9ViBVE3XYb70xZx+jK6SEVphvt7xMTbm6yDIF4xPs=",
"owner": "nixos",
"repo": "nixpkgs",
- "rev": "fa804edfb7869c9fb230e174182a8a1a7e512c40",
+ "rev": "3eaeaeb6b1e08a016380c279f8846e0bd8808916",
"type": "github"
},
"original": {
@@ -32,43 +50,43 @@
"type": "github"
}
},
+ "nixpkgs-lib": {
+ "locked": {
+ "lastModified": 1714640452,
+ "narHash": "sha256-QBx10+k6JWz6u7VsohfSw8g8hjdBZEf8CFzXH1/1Z94=",
+ "type": "tarball",
+ "url": "https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz"
+ },
+ "original": {
+ "type": "tarball",
+ "url": "https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz"
+ }
+ },
"root": {
"inputs": {
"flake-compat": "flake-compat",
+ "flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
- "utils": "utils"
- }
- },
- "systems": {
- "locked": {
- "lastModified": 1681028828,
- "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
- "owner": "nix-systems",
- "repo": "default",
- "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
- "type": "github"
- },
- "original": {
- "owner": "nix-systems",
- "repo": "default",
- "type": "github"
+ "treefmt-nix": "treefmt-nix"
}
},
- "utils": {
+ "treefmt-nix": {
"inputs": {
- "systems": "systems"
+ "nixpkgs": [
+ "nixpkgs"
+ ]
},
"locked": {
- "lastModified": 1694529238,
- "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
+ "lastModified": 1715940852,
+ "narHash": "sha256-wJqHMg/K6X3JGAE9YLM0LsuKrKb4XiBeVaoeMNlReZg=",
"owner": "numtide",
- "repo": "flake-utils",
- "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
+ "repo": "treefmt-nix",
+ "rev": "2fba33a182602b9d49f0b2440513e5ee091d838b",
"type": "github"
},
"original": {
"owner": "numtide",
- "repo": "flake-utils",
+ "repo": "treefmt-nix",
"type": "github"
}
}
diff --git a/flake.nix b/flake.nix
index b8f9ce58..111f7d7f 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,40 +1,81 @@
{
description = "Userspace tools for bcachefs";
- # Nixpkgs / NixOS version to use.
- inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
- inputs.utils.url = "github:numtide/flake-utils";
- inputs.flake-compat = {
- url = "github:edolstra/flake-compat";
- flake = false;
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+
+ flake-parts.url = "github:hercules-ci/flake-parts";
+
+ treefmt-nix = {
+ url = "github:numtide/treefmt-nix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+
+ flake-compat = {
+ url = "github:edolstra/flake-compat";
+ flake = false;
+ };
};
- outputs = { self, nixpkgs, utils, ... }:
- {
- overlays.default = final: prev: {
- bcachefs = final.callPackage ./build.nix { };
- };
- } // utils.lib.eachDefaultSystem (system:
- let
- pkgs = import nixpkgs {
- inherit system;
- overlays = [ self.overlays.default ];
- };
- in {
- packages = {
- inherit (pkgs) bcachefs;
- bcachefs-fuse = pkgs.bcachefs.override { fuseSupport = true; };
- default = pkgs.bcachefs;
- };
+ outputs =
+ inputs@{
+ self,
+ nixpkgs,
+ flake-parts,
+ treefmt-nix,
+ flake-compat,
+ ...
+ }:
+ flake-parts.lib.mkFlake { inherit inputs; } {
+ imports = [ inputs.treefmt-nix.flakeModule ];
+
+ # can be extended, but these have proper binary cache support in nixpkgs
+ # as of writing.
+ systems = [
+ "aarch64-linux"
+ "x86_64-linux"
+ ];
- formatter = pkgs.nixfmt;
+ perSystem =
+ {
+ self',
+ config,
+ pkgs,
+ ...
+ }:
+ {
+ packages.default = config.packages.bcachefs-tools;
+ packages.bcachefs-tools = pkgs.callPackage ./build.nix { };
- devShells.default = pkgs.callPackage ({ mkShell, rustc, cargo, gnumake
- , gcc, clang, pkg-config, libuuid, libsodium, keyutils, liburcu, zlib
- , libaio, zstd, lz4, udev, bcachefs }:
- mkShell {
- LIBCLANG_PATH = "${clang.cc.lib}/lib";
- inherit (bcachefs) nativeBuildInputs buildInputs;
- }) { };
- });
+ packages.bcachefs-tools-fuse = config.packages.bcachefs-tools.override { fuseSupport = true; };
+
+ devShells.default = pkgs.mkShell {
+ inputsFrom = [
+ config.packages.default
+ config.treefmt.build.devShell
+ ];
+
+ LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib";
+
+ # here go packages that aren't required for builds but are used for
+ # development, and might need to be version matched with build
+ # dependencies (e.g. clippy or rust-analyzer).
+ packages = with pkgs; [
+ cargo-audit
+ cargo-outdated
+ clang-tools
+ clippy
+ rust-analyzer
+ ];
+ };
+
+ treefmt.config = {
+ projectRootFile = "flake.nix";
+
+ programs = {
+ nixfmt-rfc-style.enable = true;
+ };
+ };
+ };
+ };
}