From 683710c06871e4d20f4c1df470d6b94c612a4217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 21:37:09 +0200 Subject: [PATCH 01/10] chore(editorconfig): flesh out definitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit so it actually works. Signed-off-by: Thomas Mühlbacher --- .editorconfig | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 From 04a31f10e09ed7f5f375e1b75b9855c4fbbc3747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 20:14:54 +0200 Subject: [PATCH 02/10] build(flake.lock): update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nixpkgs': 'github:nixos/nixpkgs/fa804edfb7869c9fb230e174182a8a1a7e512c40' (2023-11-02) → 'github:nixos/nixpkgs/3eaeaeb6b1e08a016380c279f8846e0bd8808916' (2024-05-21) • Updated input 'utils': 'github:numtide/flake-utils/ff7b65b44d01cf9ba6a71320833626af21126384' (2023-09-12) → 'github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a' (2024-03-11) Signed-off-by: Thomas Mühlbacher --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 413959e4..d8db8db2 100644 --- a/flake.lock +++ b/flake.lock @@ -18,11 +18,11 @@ }, "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": { @@ -59,11 +59,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { From e94c985640bb10a1e8bf0a5a0004a9b582092951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 20:39:24 +0200 Subject: [PATCH 03/10] build(nix): switch to new RFC style nixfmt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Mühlbacher --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index b8f9ce58..01a79e7c 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,7 @@ default = pkgs.bcachefs; }; - formatter = pkgs.nixfmt; + formatter = pkgs.nixfmt-rfc-style; devShells.default = pkgs.callPackage ({ mkShell, rustc, cargo, gnumake , gcc, clang, pkg-config, libuuid, libsodium, keyutils, liburcu, zlib From b91647aab80701c5b462bdcdaefb2cc72821014a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 20:41:19 +0200 Subject: [PATCH 04/10] style(nix): run `nix fmt` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Mühlbacher --- build.nix | 37 +++++++++++++++++++++++++++++-------- default.nix | 15 +++++++++------ flake.nix | 48 +++++++++++++++++++++++++++++++++++++----------- 3 files changed, 75 insertions(+), 25 deletions(-) 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.nix b/flake.nix index 01a79e7c..aeef1392 100644 --- a/flake.nix +++ b/flake.nix @@ -9,18 +9,25 @@ flake = false; }; - outputs = { self, nixpkgs, utils, ... }: + outputs = { - overlays.default = final: prev: { - bcachefs = final.callPackage ./build.nix { }; - }; - } // utils.lib.eachDefaultSystem (system: + 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 { + in + { packages = { inherit (pkgs) bcachefs; bcachefs-fuse = pkgs.bcachefs.override { fuseSupport = true; }; @@ -29,12 +36,31 @@ formatter = pkgs.nixfmt-rfc-style; - devShells.default = pkgs.callPackage ({ mkShell, rustc, cargo, gnumake - , gcc, clang, pkg-config, libuuid, libsodium, keyutils, liburcu, zlib - , libaio, zstd, lz4, udev, bcachefs }: + 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; - }) { }; - }); + } + ) { }; + } + ); } From eccefb381d8b3fe12d1d2142d2dd04543546d44d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 20:43:43 +0200 Subject: [PATCH 05/10] style(nix): group together inputs attr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Mühlbacher --- flake.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index aeef1392..591d325e 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,15 @@ { 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"; + + utils.url = "github:numtide/flake-utils"; + + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; }; outputs = From 5e9d1953a2b36f1cd93af3638698d80266b2b623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 20:51:00 +0200 Subject: [PATCH 06/10] build(nix): simplify devShell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit much more DRY. Signed-off-by: Thomas Mühlbacher --- flake.nix | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/flake.nix b/flake.nix index 591d325e..d903bea8 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,7 @@ overlays = [ self.overlays.default ]; }; in - { + rec { packages = { inherit (pkgs) bcachefs; bcachefs-fuse = pkgs.bcachefs.override { fuseSupport = true; }; @@ -39,31 +39,11 @@ formatter = pkgs.nixfmt-rfc-style; - 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; - } - ) { }; + devShells.default = pkgs.mkShell { + inputsFrom = [ packages.default ]; + + LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib"; + }; } ); } From 0fcdd67bf0fcd38a61a2eda647b9b7342b558ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 20:57:20 +0200 Subject: [PATCH 07/10] build(nix): rm nixpkgs overlay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit it shouldn't really be our job to define an overlay. it doesn't do anything for us, afaict, and is trivial to implement for downstream users of the flake if they so desire. also the overlay doesn't even overlay anything, there is no package called `bcachefs` in nixpkgs. Signed-off-by: Thomas Mühlbacher --- flake.nix | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/flake.nix b/flake.nix index d903bea8..dba647fe 100644 --- a/flake.nix +++ b/flake.nix @@ -13,29 +13,16 @@ }; outputs = - { - self, - nixpkgs, - utils, - ... - }: - { - overlays.default = final: prev: { bcachefs = final.callPackage ./build.nix { }; }; - } - // utils.lib.eachDefaultSystem ( + { nixpkgs, utils, ... }: + utils.lib.eachDefaultSystem ( system: let - pkgs = import nixpkgs { - inherit system; - overlays = [ self.overlays.default ]; - }; + pkgs = import nixpkgs { inherit system; }; in rec { - packages = { - inherit (pkgs) bcachefs; - bcachefs-fuse = pkgs.bcachefs.override { fuseSupport = true; }; - default = pkgs.bcachefs; - }; + packages.default = packages.bcachefs-tools; + packages.bcachefs-tools = pkgs.callPackage ./build.nix { }; + packages.bcachefs-tools-fuse = packages.bcachefs-tools.override { fuseSupport = true; }; formatter = pkgs.nixfmt-rfc-style; From cc16402e4f31a63ab415043da06f0445fe55765c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 21:08:09 +0200 Subject: [PATCH 08/10] build(nix): replace flake-utils with flake-parts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit it also provides a way for abstracting `system` and provides optional modules, like treefmt-nix. Signed-off-by: Thomas Mühlbacher --- flake.lock | 67 ++++++++++++++++++++++++++---------------------------- flake.nix | 51 +++++++++++++++++++++++++++-------------- 2 files changed, 66 insertions(+), 52 deletions(-) diff --git a/flake.lock b/flake.lock index d8db8db2..2b883b6e 100644 --- a/flake.lock +++ b/flake.lock @@ -16,6 +16,24 @@ "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": 1716293225, @@ -32,44 +50,23 @@ "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", - "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" - } - }, - "utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index dba647fe..4a2d3c4c 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - utils.url = "github:numtide/flake-utils"; + flake-parts.url = "github:hercules-ci/flake-parts"; flake-compat = { url = "github:edolstra/flake-compat"; @@ -13,24 +13,41 @@ }; outputs = - { nixpkgs, utils, ... }: - utils.lib.eachDefaultSystem ( - system: - let - pkgs = import nixpkgs { inherit system; }; - in - rec { - packages.default = packages.bcachefs-tools; - packages.bcachefs-tools = pkgs.callPackage ./build.nix { }; - packages.bcachefs-tools-fuse = packages.bcachefs-tools.override { fuseSupport = true; }; + inputs@{ + self, + nixpkgs, + flake-parts, + flake-compat, + ... + }: + flake-parts.lib.mkFlake { inherit inputs; } { + # can be extended, but these have proper binary cache support in nixpkgs + # as of writing. + systems = [ + "aarch64-linux" + "x86_64-linux" + ]; - formatter = pkgs.nixfmt-rfc-style; + perSystem = + { + self', + config, + pkgs, + ... + }: + { + packages.default = config.packages.bcachefs-tools; + packages.bcachefs-tools = pkgs.callPackage ./build.nix { }; - devShells.default = pkgs.mkShell { - inputsFrom = [ packages.default ]; + packages.bcachefs-tools-fuse = config.packages.bcachefs-tools.override { fuseSupport = true; }; - LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib"; + formatter = pkgs.nixfmt-rfc-style; + + devShells.default = pkgs.mkShell { + inputsFrom = [ config.packages.default ]; + + LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib"; + }; }; - } - ); + }; } From 2e316499df35053c140ee46819185da8b6fa9d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 21:35:41 +0200 Subject: [PATCH 09/10] build(nix): add treefmt-nix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit currently still bare but can be extended with a number of different formatters (rustfmt, clang-format, ...). For full list see https://flake.parts/options/treefmt-nix Signed-off-by: Thomas Mühlbacher --- flake.lock | 23 ++++++++++++++++++++++- flake.nix | 23 ++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index 2b883b6e..58b8eeb5 100644 --- a/flake.lock +++ b/flake.lock @@ -66,7 +66,28 @@ "inputs": { "flake-compat": "flake-compat", "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1715940852, + "narHash": "sha256-wJqHMg/K6X3JGAE9YLM0LsuKrKb4XiBeVaoeMNlReZg=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "2fba33a182602b9d49f0b2440513e5ee091d838b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 4a2d3c4c..1070466e 100644 --- a/flake.nix +++ b/flake.nix @@ -6,6 +6,11 @@ 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; @@ -17,10 +22,13 @@ 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 = [ @@ -41,13 +49,22 @@ packages.bcachefs-tools-fuse = config.packages.bcachefs-tools.override { fuseSupport = true; }; - formatter = pkgs.nixfmt-rfc-style; - devShells.default = pkgs.mkShell { - inputsFrom = [ config.packages.default ]; + inputsFrom = [ + config.packages.default + config.treefmt.build.devShell + ]; LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib"; }; + + treefmt.config = { + projectRootFile = "flake.nix"; + + programs = { + nixfmt-rfc-style.enable = true; + }; + }; }; }; } From 56a9580aeb88c4945d0c6dfa23b5051a5b5c520b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 21:42:26 +0200 Subject: [PATCH 10/10] build(nix): add some packages to the dev shell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Mühlbacher --- flake.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/flake.nix b/flake.nix index 1070466e..111f7d7f 100644 --- a/flake.nix +++ b/flake.nix @@ -56,6 +56,17 @@ ]; 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 = {