From e94bc36a0125c8aebdadb67cb0efca927bcc36e0 Mon Sep 17 00:00:00 2001 From: Sebastian Wendel Date: Tue, 7 May 2024 17:20:50 +0200 Subject: [PATCH] added hydra jobs and flakes cleanup --- flake.lock | 52 +++++++++++++++++++++++++++++++++++++++--------- flake.nix | 37 +++++++++++++++------------------- nix/devshell.nix | 12 +++++++++-- nix/hooks.nix | 15 ++++++++------ nix/package.nix | 20 +++++-------------- 5 files changed, 83 insertions(+), 53 deletions(-) diff --git a/flake.lock b/flake.lock index 7a45821..d893ddb 100644 --- a/flake.lock +++ b/flake.lock @@ -90,18 +90,17 @@ }, "nixpkgs": { "locked": { - "lastModified": 1713805509, - "narHash": "sha256-YgSEan4CcrjivCNO5ZNzhg7/8ViLkZ4CB/GrGBVSudo=", - "owner": "nixos", + "lastModified": 1714906307, + "narHash": "sha256-UlRZtrCnhPFSJlDQE7M0eyhgvuuHBTe1eJ9N9AQlJQ0=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "1e1dc66fe68972a76679644a5577828b6a7e8be4", + "rev": "25865a40d14b3f9cf19f19b924e2ab4069b09588", "type": "github" }, "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" } }, "nixpkgs-lib": { @@ -154,6 +153,22 @@ "type": "github" } }, + "nixpkgs_3": { + "locked": { + "lastModified": 1708475490, + "narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0e74ca98a74bc7270d28838369593635a5db3260", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "pre-commit": { "inputs": { "flake-compat": "flake-compat", @@ -181,7 +196,8 @@ "flake-parts": "flake-parts", "nix-filter": "nix-filter", "nixpkgs": "nixpkgs", - "pre-commit": "pre-commit" + "pre-commit": "pre-commit", + "treefmt-nix": "treefmt-nix" } }, "systems": { @@ -198,6 +214,24 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1714058656, + "narHash": "sha256-Qv4RBm4LKuO4fNOfx9wl40W2rBbv5u5m+whxRYUMiaA=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "c6aaf729f34a36c445618580a9f95a48f5e4e03f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index f5c91df..7ac7054 100644 --- a/flake.nix +++ b/flake.nix @@ -2,48 +2,43 @@ description = "srx.digital - Website"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable"; + nixpkgs.url = "nixpkgs/nixos-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; + treefmt-nix.url = "github:numtide/treefmt-nix"; nix-filter.url = "github:numtide/nix-filter"; pre-commit.url = "github:cachix/pre-commit-hooks.nix"; }; - outputs = { - flake-parts, - nix-filter, - pre-commit, - ... - } @ inputs: let - systems = ["x86_64-linux" "aarch64-linux"]; - in - flake-parts.lib.mkFlake {inherit inputs;} { + outputs = { self, flake-parts, treefmt-nix, pre-commit, ... }@inputs: + let systems = [ "x86_64-linux" "aarch64-linux" ]; + in flake-parts.lib.mkFlake { inherit inputs; } { inherit systems; imports = [ pre-commit.flakeModule + treefmt-nix.flakeModule ./nix/hooks.nix ./nix/devshell.nix ./nix/package.nix ]; - - perSystem = { - config, - pkgs, - self', - inputs', - system, - ... - }: { + perSystem = { config, pkgs, self', ... }: { apps = { serve.program = "${pkgs.writeShellScript "serve" '' ${pkgs.miniserve}/bin/miniserve -p 3001 --index index.html ${self'.packages.default} ''}"; }; - packages = { - default = self'.packages.srx-digital; + packages.default = self'.packages.srx-digital; + + treefmt.config = { + projectRootFile = "flake.nix"; + programs.nixpkgs-fmt.enable = true; }; + + formatter = config.treefmt.build.wrapper; }; + + flake.hydraJobs = { inherit (self) packages; }; }; } diff --git a/nix/devshell.nix b/nix/devshell.nix index 4d984d5..701943d 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -1,6 +1,8 @@ { perSystem = { pkgs, config, ... }: { devShells.default = pkgs.mkShell { + inputsFrom = [ config.treefmt.build.devShell ]; + nativeBuildInputs = with pkgs; [ # ide (vscode-with-extensions.override { @@ -17,7 +19,7 @@ }) # formater - nixfmt + nixpkgs-fmt nodePackages_latest.prettier # lsp @@ -27,6 +29,10 @@ nodePackages_latest.vscode-html-languageserver-bin tailwindcss-language-server + # nix + deadnix + statix + # node nodePackages_latest.nodejs nodePackages_latest.typescript @@ -36,7 +42,9 @@ # html html5validator ]; - shellHook = config.pre-commit.installationScript; + shellHook = '' + ${config.pre-commit.installationScript} + ''; }; }; } diff --git a/nix/hooks.nix b/nix/hooks.nix index 06319f4..d72da68 100644 --- a/nix/hooks.nix +++ b/nix/hooks.nix @@ -1,10 +1,13 @@ { - perSystem = {pkgs, ...}: { - pre-commit = { - check.enable = true; - settings = { - hooks = {}; - }; + perSystem.pre-commit = { + check.enable = true; + settings.hooks = { + markdownlint.enable = true; + shellcheck.enable = true; + nixpkgs-fmt.enable = true; + deadnix.enable = true; + statix.enable = true; + eslint.enable = true; }; }; } diff --git a/nix/package.nix b/nix/package.nix index 1dc8a4b..12407ff 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -1,12 +1,7 @@ -{inputs, ...}: let - inherit (inputs.nix-filter.lib) filter inDirectory matchExt; +{ inputs, ... }: +let inherit (inputs.nix-filter.lib) filter inDirectory matchExt; in { - perSystem = { - config, - pkgs, - inputs', - ... - }: { + perSystem = { pkgs, ... }: { packages.srx-digital = pkgs.mkYarnPackage rec { name = "srx-digital"; @@ -30,10 +25,7 @@ in { packageJSON = ../package.json; yarnLock = ../yarn.lock; - yarnFlags = [ - "--offline" - "--production=true" - ]; + yarnFlags = [ "--offline" "--production=true" ]; pkgConfig.sharp = { nativeBuildInputs = with pkgs; [ @@ -42,9 +34,7 @@ in { nodePackages.node-gyp ]; - buildInputs = with pkgs; [ - vips.dev - ]; + buildInputs = with pkgs; [ vips.dev ]; postInstall = '' ${pkgs.nodePackages.node-gyp}/bin/node-gyp --node-dir=${pkgs.nodePackages.nodejs}/include/node rebuild