From 6a6bf622efe73b8683eb5c92f53fdc407827b424 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Sat, 4 Nov 2023 20:45:59 +0100 Subject: [PATCH] improve default shell --- .envrc | 2 +- flake.lock | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 43 ++++++++++++-- 3 files changed, 200 insertions(+), 7 deletions(-) diff --git a/.envrc b/.envrc index 6a9b262..3550a30 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use flake .#nix +use flake diff --git a/flake.lock b/flake.lock index 9734f7d..3c53f0a 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" @@ -18,6 +34,45 @@ "type": "github" } }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks-nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1699065553, @@ -52,10 +107,115 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1689261696, + "narHash": "sha256-LzfUtFs9MQRvIoQ3MfgSuipBVMXslMPH/vZ+nM40LkA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "df1eee2aa65052a18121ed4971081576b25d6b5c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1695644571, + "narHash": "sha256-asS9dCCdlt1lPq0DLwkVBbVoEKuEuz+Zi3DG7pR/RxA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6500b4580c2a1f3d0f980d32d285739d8e156d92", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks-nix": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1698852633, + "narHash": "sha256-Hsc/cCHud8ZXLvmm8pxrXpuaPEeNaaUttaCvtdX/Wug=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "dec10399e5b56aa95fcd530e0338be72ad6462a0", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "pre-commit-hooks-nix": "pre-commit-hooks-nix", + "treefmt-nix": "treefmt-nix" + } + }, + "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": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1698438538, + "narHash": "sha256-AWxaKTDL3MtxaVTVU5lYBvSnlspOS0Fjt8GxBgnU0Do=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "5deb8dc125a9f83b65ca86cf0c8167c46593e0b1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 6807645..468cef7 100644 --- a/flake.nix +++ b/flake.nix @@ -2,6 +2,8 @@ description = "All things development"; inputs.flake-parts.url = "github:hercules-ci/flake-parts"; inputs.nixpkgs.url = "github:NixOS/nixpkgs?ref=nixpkgs-unstable"; + inputs.pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix"; + inputs.treefmt-nix.url = "github:numtide/treefmt-nix"; nixConfig = { nix = ["http://cache.home"]; @@ -9,10 +11,16 @@ outputs = inputs @ { flake-parts, + pre-commit-hooks-nix, + treefmt-nix, self, ... }: flake-parts.lib.mkFlake {inherit inputs;} { + imports = [ + treefmt-nix.flakeModule + pre-commit-hooks-nix.flakeModule + ]; systems = ["x86_64-linux"]; perSystem = { config, @@ -114,11 +122,36 @@ }; }; in { - devShells = pkgs.lib.attrsets.mapAttrs (name: value: - pkgs.mkShell (pkgs.lib.recursiveUpdate value { - packages = value.packages ++ packagesSharedByAll; - })) - shells; + treefmt.projectRootFile = "flake.nix"; + treefmt.programs = { + alejandra.enable = true; + }; + treefmt.flakeFormatter = true; + + pre-commit.check.enable = true; + pre-commit.settings.hooks.markdownlint.enable = true; + pre-commit.settings.hooks.nil.enable = true; + pre-commit.settings.hooks.format = { + enable = true; + entry = "${self'.formatter}/bin/treefmt"; + pass_filenames = false; + }; + + devShells = + (pkgs.lib.attrsets.mapAttrs (name: value: + pkgs.mkShell (pkgs.lib.recursiveUpdate value { + packages = value.packages ++ packagesSharedByAll; + })) + shells) + // { + default = self'.devShells.nix.overrideAttrs (final: previous: { + name = "dev"; + shellHook = '' + echo -e 1>&2 "\n\n Welcome to the development shell!\n\n" + ${config.pre-commit.installationScript} + ''; + }); + }; packages = { inherit mdpls;