diff --git a/.envrc b/.envrc index 57b77334..e66afc9e 100644 --- a/.envrc +++ b/.envrc @@ -1,4 +1,5 @@ +# shellcheck shell=bash strict_env source ./direnvrc -watch_file direnvrc *.nix +watch_file direnvrc ./*.nix use flake diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 10791b87..b2c9def0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,17 +10,16 @@ jobs: tests: strategy: matrix: - os: [ ubuntu-latest ] + os: [ubuntu-latest] # FIXME macos garbage currently collect also nix-shell that runs the test #os: [ ubuntu-latest, macos-latest ] - variants: [ stable, latest, bash4 ] + variants: [stable, latest, bash4] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@V27 - with: - nix_path: nixpkgs=channel:nixpkgs-unstable - extra_nix_config: | - experimental-features = nix-command flakes - - run: - "nix run --accept-flake-config .#test-runner-${{ matrix.variants }}" + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@V27 + with: + nix_path: nixpkgs=channel:nixpkgs-unstable + extra_nix_config: | + experimental-features = nix-command flakes + - run: "nix run --accept-flake-config .#test-runner-${{ matrix.variants }}" diff --git a/.github/workflows/update-flake-lock.yml b/.github/workflows/update-flake-lock.yml index f26f25fb..29b40884 100644 --- a/.github/workflows/update-flake-lock.yml +++ b/.github/workflows/update-flake-lock.yml @@ -24,5 +24,5 @@ jobs: ``` {{ env.GIT_COMMIT_MESSAGE }} ``` - pr-labels: | # Labels to be set on the PR + pr-labels: | # Labels to be set on the PR merge-queue diff --git a/default.nix b/default.nix index 5657e52c..5c1beeba 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,10 @@ -{ resholve, lib, coreutils, direnv, nix }: +{ + resholve, + lib, + coreutils, + direnv, + nix, +}: # resholve does not yet support `finalAttrs` call pattern hence `rec` # https://github.com/abathur/resholve/issues/107 @@ -24,7 +30,10 @@ resholve.mkDerivation rec { default = { scripts = [ "share/${pname}/direnvrc" ]; interpreter = "none"; - inputs = [ coreutils nix ]; + inputs = [ + coreutils + nix + ]; fake = { builtin = [ "PATH_add" diff --git a/flake.lock b/flake.lock index 781a82a4..5e42df1c 100644 --- a/flake.lock +++ b/flake.lock @@ -22,11 +22,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1720368505, - "narHash": "sha256-5r0pInVo5d6Enti0YwUSQK4TebITypB42bWy5su3MrQ=", + "lastModified": 1720955038, + "narHash": "sha256-GaliJqfFwyYxReFywxAa8orCO+EnDq2NK2F+5aSc8vo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ab82a9612aa45284d4adf69ee81871a389669a9e", + "rev": "aa247c0c90ecf4ae7a032c54fdc21b91ca274062", "type": "github" }, "original": { @@ -50,11 +50,11 @@ ] }, "locked": { - "lastModified": 1720374026, - "narHash": "sha256-ludjqxhR/5lXwJ1H6zHmZqp+4e8dFPHE9FIZ2eBh2G4=", + "lastModified": 1720930114, + "narHash": "sha256-VZK73b5hG5bSeAn97TTcnPjXUXtV7j/AtS4KN8ggCS0=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "e1d7bd5ec6fc389eb3a90e232c4150338bf6a508", + "rev": "b92afa1501ac73f1d745526adc4f89b527595f14", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index b1cdfb48..caa9e052 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,9 @@ description = "A faster, persistent implementation of `direnv`'s `use_nix`, to replace the built-in one."; nixConfig.extra-substituters = [ "https://cache.thalheim.io" ]; - nixConfig.extra-trusted-public-keys = [ "cache.thalheim.io-1:R7msbosLEZKrxk/lKxf9BTjOOH7Ax3H0Qj0/6wiHOgc=" ]; + nixConfig.extra-trusted-public-keys = [ + "cache.thalheim.io-1:R7msbosLEZKrxk/lKxf9BTjOOH7Ax3H0Qj0/6wiHOgc=" + ]; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; @@ -16,9 +18,11 @@ }; }; - outputs = inputs @ { flake-parts, ... }: - flake-parts.lib.mkFlake { inherit inputs; } - ({ lib, ... }: { + outputs = + inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } ( + { lib, ... }: + { imports = [ ./treefmt.nix ./pkgs/bash4/flake-module.nix @@ -30,37 +34,42 @@ "x86_64-darwin" "aarch64-darwin" ]; - perSystem = { config, pkgs, self', ... }: { - packages = { - nix-direnv = pkgs.callPackage ./default.nix { }; - default = config.packages.nix-direnv; - test-runner-stable = pkgs.callPackage ./test-runner.nix { - nixVersion = "stable"; + perSystem = + { + config, + pkgs, + self', + ... + }: + { + packages = { + nix-direnv = pkgs.callPackage ./default.nix { }; + default = config.packages.nix-direnv; + test-runner-stable = pkgs.callPackage ./test-runner.nix { nixVersion = "stable"; }; + test-runner-latest = pkgs.callPackage ./test-runner.nix { nixVersion = "latest"; }; }; - test-runner-latest = pkgs.callPackage ./test-runner.nix { - nixVersion = "latest"; + + devShells.default = pkgs.callPackage ./shell.nix { + packages = [ + config.treefmt.build.wrapper + pkgs.shellcheck + ]; }; - }; - devShells.default = pkgs.callPackage ./shell.nix { - packages = [ config.treefmt.build.wrapper pkgs.shellcheck ]; + checks = + let + packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self'.packages; + devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self'.devShells; + in + packages // devShells; }; - - checks = - let - packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self'.packages; - devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self'.devShells; - in - packages // devShells; - }; flake = { - overlays.default = final: _prev: { - nix-direnv = final.callPackage ./default.nix { }; - }; + overlays.default = final: _prev: { nix-direnv = final.callPackage ./default.nix { }; }; templates.default = { path = ./templates/flake; description = "nix flake new -t github:Mic92/nix-direnv ."; }; }; - }); + } + ); } diff --git a/pkgs/bash4/default.nix b/pkgs/bash4/default.nix index a3376e94..7e1ddf30 100644 --- a/pkgs/bash4/default.nix +++ b/pkgs/bash4/default.nix @@ -8,8 +8,11 @@ bash.overrideAttrs (_old: { }; # generated with update-patch-set.sh from nixpkgs/pkgs/shells/bash - patches = import ./bash-4.4-patches.nix (nr: sha256: fetchurl { - url = "mirror://gnu/bash/bash-4.4-patches/bash44-${nr}"; - inherit sha256; - }); + patches = import ./bash-4.4-patches.nix ( + nr: sha256: + fetchurl { + url = "mirror://gnu/bash/bash-4.4-patches/bash44-${nr}"; + inherit sha256; + } + ); }) diff --git a/pkgs/bash4/flake-module.nix b/pkgs/bash4/flake-module.nix index 3d3683ed..be2180ed 100644 --- a/pkgs/bash4/flake-module.nix +++ b/pkgs/bash4/flake-module.nix @@ -1,13 +1,14 @@ -{ self, withSystem, ... }: { - flake.packages.x86_64-linux = withSystem "x86_64-linux" - ({ pkgs, ... }: { +{ self, withSystem, ... }: +{ + flake.packages.x86_64-linux = withSystem "x86_64-linux" ( + { pkgs, ... }: + { bash4 = pkgs.callPackage ./. { }; - direnv-bash4 = pkgs.direnv.override { - bash = self.packages.x86_64-linux.bash4; - }; + direnv-bash4 = pkgs.direnv.override { bash = self.packages.x86_64-linux.bash4; }; test-runner-bash4 = pkgs.callPackage ../../test-runner.nix { nixVersion = "stable"; direnv = self.packages.x86_64-linux.direnv-bash4; }; - }); + } + ); } diff --git a/shell.nix b/shell.nix index d32920a1..da9bc2d2 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,7 @@ -{ pkgs ? import { }, packages ? [ ] }: +{ + pkgs ? import { }, + packages ? [ ], +}: with pkgs; mkShell { diff --git a/templates/flake/.envrc b/templates/flake/.envrc index 9ee556b1..1faf1bb0 100644 --- a/templates/flake/.envrc +++ b/templates/flake/.envrc @@ -1,4 +1,5 @@ +# shellcheck shell=bash if ! has nix_direnv_version || ! nix_direnv_version 3.0.5; then - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.5/direnvrc" "sha256-RuwIS+QKFj/T9M2TFXScjBsLR6V3A17YVoEW/Q6AZ1w=" + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.5/direnvrc" "sha256-RuwIS+QKFj/T9M2TFXScjBsLR6V3A17YVoEW/Q6AZ1w=" fi use flake diff --git a/templates/flake/flake.nix b/templates/flake/flake.nix index 6a518689..f7b7e5f1 100644 --- a/templates/flake/flake.nix +++ b/templates/flake/flake.nix @@ -3,14 +3,15 @@ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; inputs.flake-utils.url = "github:numtide/flake-utils"; - outputs = { nixpkgs, flake-utils, ... }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + { nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = nixpkgs.legacyPackages.${system}; in { - devShells.default = pkgs.mkShell { - packages = [ pkgs.bashInteractive ]; - }; - }); + devShells.default = pkgs.mkShell { packages = [ pkgs.bashInteractive ]; }; + } + ); } diff --git a/test-runner.nix b/test-runner.nix index f25e2960..5ff22da0 100644 --- a/test-runner.nix +++ b/test-runner.nix @@ -1,15 +1,23 @@ -{ writeShellScriptBin -, direnv -, python3 -, lib -, coreutils -, gnugrep -, nixVersions -, nixVersion +{ + writeShellScriptBin, + direnv, + python3, + lib, + coreutils, + gnugrep, + nixVersions, + nixVersion, }: writeShellScriptBin "test-runner-${nixVersion}" '' set -e - export PATH=${lib.makeBinPath [ direnv nixVersions.${nixVersion} coreutils gnugrep ]} + export PATH=${ + lib.makeBinPath [ + direnv + nixVersions.${nixVersion} + coreutils + gnugrep + ] + } echo run unittest ${lib.getExe' python3.pkgs.pytest "pytest"} . diff --git a/tests/testenv/flake.nix b/tests/testenv/flake.nix index 516e6ba8..fb67fa1a 100644 --- a/tests/testenv/flake.nix +++ b/tests/testenv/flake.nix @@ -4,10 +4,9 @@ inputs.flake-utils.url = "github:numtide/flake-utils"; # deadnix: skip - outputs = { self, nixpkgs, flake-utils }: + outputs = + { nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: { - devShell = import ./shell.nix { - pkgs = nixpkgs.legacyPackages.${system}; - }; + devShell = import ./shell.nix { pkgs = nixpkgs.legacyPackages.${system}; }; }); } diff --git a/tests/testenv/shell.nix b/tests/testenv/shell.nix index ebd6af50..1ee82c1f 100644 --- a/tests/testenv/shell.nix +++ b/tests/testenv/shell.nix @@ -1,8 +1,9 @@ -{ pkgs ? import (builtins.getFlake (toString ./.)).inputs.nixpkgs { } -, someArg ? null -, shellHook ? '' +{ + pkgs ? import (builtins.getFlake (toString ./.)).inputs.nixpkgs { }, + someArg ? null, + shellHook ? '' echo "Executing shellHook." - '' + '', }: pkgs.mkShellNoCC { inherit shellHook; @@ -10,5 +11,7 @@ pkgs.mkShellNoCC { nativeBuildInputs = [ pkgs.hello ]; SHOULD_BE_SET = someArg; - passthru = { subshell = pkgs.mkShellNoCC { THIS_IS_A_SUBSHELL = "OK"; }; }; + passthru = { + subshell = pkgs.mkShellNoCC { THIS_IS_A_SUBSHELL = "OK"; }; + }; } diff --git a/treefmt.nix b/treefmt.nix index 66167a0a..415c2051 100644 --- a/treefmt.nix +++ b/treefmt.nix @@ -1,33 +1,32 @@ -{ inputs, ... }: { - imports = [ - inputs.treefmt-nix.flakeModule - ]; +{ inputs, ... }: +{ + imports = [ inputs.treefmt-nix.flakeModule ]; - perSystem = { - treefmt = { - # Used to find the project root - projectRootFile = ".git/config"; + perSystem = + { pkgs, ... }: + { + treefmt = { + # Used to find the project root + projectRootFile = ".git/config"; - programs = { - deadnix.enable = true; - deno.enable = true; - mypy.enable = true; - ruff.check = true; - ruff.format = true; - nixpkgs-fmt.enable = true; - shellcheck.enable = true; - shfmt.enable = true; - statix.enable = true; - }; + programs = { + deadnix.enable = true; + deno.enable = true; + mypy.enable = true; + ruff.check = true; + ruff.format = true; + nixfmt.enable = true; + nixfmt.package = pkgs.nixfmt-rfc-style; + shellcheck.enable = true; + shfmt.enable = true; + statix.enable = true; + yamlfmt.enable = true; + }; - settings.formatter = - let - shellIncludes = [ "*.sh" "direnvrc" ]; - in - { - shellcheck.includes = shellIncludes; - shfmt.includes = shellIncludes; + settings.formatter = { + shellcheck.includes = [ "direnvrc" ]; + shfmt.includes = [ "direnvrc" ]; }; + }; }; - }; }