diff options
| -rw-r--r-- | .github/workflows/ci.yml | 2 | ||||
| -rw-r--r-- | flake.lock | 59 | ||||
| -rw-r--r-- | flake.nix | 147 | ||||
| -rw-r--r-- | justfile | 22 |
4 files changed, 70 insertions, 160 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31327ce..69d9e69 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,5 @@ jobs: steps: - uses: actions/checkout@v4 - uses: DeterminateSystems/nix-installer-action@v16 - - name: check formatting - run: nix develop --command treefmt - name: check configuration run: nix flake check --all-systems @@ -21,26 +21,6 @@ "type": "github" } }, - "devshell": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1741473158, - "narHash": "sha256-kWNaq6wQUbUMlPgw8Y+9/9wP0F8SHkjy24/mN3UAppg=", - "owner": "numtide", - "repo": "devshell", - "rev": "7c9e793ebe66bcba8292989a68c0419b737a22a0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, "flake-compat": { "flake": false, "locked": { @@ -57,24 +37,6 @@ "type": "github" } }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "gitignore": { "inputs": { "nixpkgs": [ @@ -145,42 +107,25 @@ "lastModified": 1742649964, "narHash": "sha256-DwOTp7nvfi8mRfuL1escHDXabVXFGT1VlPD1JHrtrco=", "owner": "cachix", - "repo": "pre-commit-hooks.nix", + "repo": "git-hooks.nix", "rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82", "type": "github" }, "original": { "owner": "cachix", - "repo": "pre-commit-hooks.nix", + "repo": "git-hooks.nix", "type": "github" } }, "root": { "inputs": { "darwin": "darwin", - "devshell": "devshell", - "flake-utils": "flake-utils", "home-manager": "home-manager", "nixpkgs": "nixpkgs", "pre-commit-hooks": "pre-commit-hooks", "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": [ @@ -19,15 +19,8 @@ inputs.nixpkgs.follows = "nixpkgs"; }; - flake-utils.url = "github:numtide/flake-utils"; - pre-commit-hooks = { - url = "github:cachix/pre-commit-hooks.nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - - devshell = { - url = "github:numtide/devshell"; + url = "github:cachix/git-hooks.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; }; @@ -35,87 +28,83 @@ # Output config, or config for NixOS system outputs = { - self, nixpkgs, darwin, - flake-utils, - pre-commit-hooks, - devshell, treefmt-nix, + pre-commit-hooks, ... }@inputs: - flake-utils.lib.eachDefaultSystem ( - system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ devshell.overlays.default ]; + let + system = "aarch64-darwin"; + pkgs = import nixpkgs { inherit system; }; + mkSystem = import ./nix/lib/mkSystem.nix { inherit nixpkgs inputs; }; + treefmtEval = treefmt-nix.lib.evalModule pkgs { + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + actionlint.enable = true; + deadnix.enable = true; }; - treefmt = ( - treefmt-nix.lib.mkWrapper pkgs { - projectRootFile = "flake.nix"; - programs = { - nixfmt.enable = true; - actionlint.enable = true; - deadnix.enable = true; - just.enable = true; - }; - } - ); - in - { - checks = { - pre-commit-check = pre-commit-hooks.lib.${system}.run { - src = ./.; - hooks = { - check-merge-conflicts.enable = true; - end-of-file-fixer.enable = true; - treefmt-check = { - enable = true; - entry = "${treefmt}/bin/treefmt --fail-on-change"; - pass_filenames = false; - }; + }; + in + { + # nix fmt + formatter.${system} = treefmtEval.config.build.wrapper; + + # nix flake check + checks.${system} = { + pre-commit-check = inputs.pre-commit-hooks.lib.${pkgs.system}.run { + src = ./.; + hooks = { + actionlint.enable = true; + check-merge-conflicts.enable = true; + deadnix.enable = true; + detect-private-keys.enable = true; + end-of-file-fixer.enable = true; + mixed-line-endings.enable = true; + shellcheck.enable = true; + treefmt = { + enable = true; + entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --ci"; }; + trim-trailing-whitespace.enable = true; }; }; + }; - formatter = treefmt; + # my personal MacBook Air + darwinConfigurations.mba-m2 = mkSystem "mba-m2" { + system = "aarch64-darwin"; + user = "fcuny"; + darwin = true; + }; - devShells.default = pkgs.devshell.mkShell { - packages = with pkgs; [ - just - treefmt - ]; - devshell.startup.pre-commit.text = self.checks.${system}.pre-commit-check.shellHook; - env = [ - { - name = "DEVSHELL_NO_MOTD"; - value = "1"; - } - ]; - }; + # work laptop + darwinConfigurations.hq-kwny2vh41p = mkSystem "hq-kwny2vh41p" { + system = "aarch64-darwin"; + user = "fcuny"; + darwin = true; + }; - } - ) - // (flake-utils.lib.eachDefaultSystemPassThrough ( - system: - let - mkSystem = import ./nix/lib/mkSystem.nix { inherit nixpkgs inputs; }; - in - { - # my personal MacBook Air - darwinConfigurations.mba-m2 = mkSystem "mba-m2" { - system = "aarch64-darwin"; - user = "fcuny"; - darwin = true; - }; - - # work laptop - darwinConfigurations.hq-kwny2vh41p = mkSystem "hq-kwny2vh41p" { - system = "aarch64-darwin"; - user = "fcuny"; - darwin = true; - }; - } - )); + devShells.${system}.default = pkgs.mkShellNoCC { + packages = with pkgs; [ + git + (writeScriptBin "build" '' + set -e + echo "> Running darwin-rebuild switch..." + ${inputs.darwin.packages.${system}.darwin-rebuild}/bin/darwin-rebuild build --flake . + echo "> darwin-rebuild build was successful ✅" + echo "> macOS config was successfully applied 🚀" + '') + (writeScriptBin "switch" '' + set -e + echo "> Running darwin-rebuild switch..." + ${inputs.darwin.packages.${system}.darwin-rebuild}/bin/darwin-rebuild switch --flake . + echo "> darwin-rebuild build was successful ✅" + echo "> macOS config was successfully applied 🚀" + '') + (writeScriptBin "update-deps" "nix flake update --commit-lock-file") + ]; + }; + }; } @@ -6,22 +6,12 @@ hostname := lowercase(`hostname -s`) default: @just --list -[doc('update dependencies')] -[group('nix')] -update-deps: - nix flake update --commit-lock-file - [doc('a simple check to ensure the nix configuration is OK')] [group('nix')] test-nix: nix flake check nix develop -c echo OK -[doc('run various formatting tools')] -[group('nix')] -fmt: - nix fmt - # Nix Store can contains corrupted entries if the nix store object has been modified unexpectedly. # This command will verify all the store entries, @@ -51,18 +41,6 @@ gcroot: [doc('build the configuration for the current host')] [group('machines')] -[macos] -build: - darwin-rebuild build --flake .#{{ hostname }} - -[doc('switch the configuration for the current host')] -[group('machines')] -[macos] -switch: - darwin-rebuild switch --flake .#{{ hostname }} - -[doc('build the configuration for the current host')] -[group('machines')] [linux] build: nixos-rebuild build --flake .#{{ hostname }} |
