Skip to content

Commit

Permalink
replace nixpkgs-fmt with nixfmt-rfc-style
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Aug 15, 2024
1 parent a51bd67 commit 5f8bbf7
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 89 deletions.
13 changes: 11 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,7 +30,10 @@ resholve.mkDerivation rec {
default = {
scripts = [ "share/${pname}/direnvrc" ];
interpreter = "none";
inputs = [ coreutils nix ];
inputs = [
coreutils
nix
];
fake = {
builtin = [
"PATH_add"
Expand Down
63 changes: 36 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand All @@ -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 .";
};
};
});
}
);
}
11 changes: 7 additions & 4 deletions pkgs/bash4/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
})
15 changes: 8 additions & 7 deletions pkgs/bash4/flake-module.nix
Original file line number Diff line number Diff line change
@@ -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;
};
});
}
);
}
5 changes: 4 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{ pkgs ? import <nixpkgs> { }, packages ? [ ] }:
{
pkgs ? import <nixpkgs> { },
packages ? [ ],
}:

with pkgs;
mkShell {
Expand Down
13 changes: 7 additions & 6 deletions templates/flake/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]; };
}
);
}
26 changes: 17 additions & 9 deletions test-runner.nix
Original file line number Diff line number Diff line change
@@ -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"} .
Expand Down
7 changes: 3 additions & 4 deletions tests/testenv/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}; };
});
}
13 changes: 8 additions & 5 deletions tests/testenv/shell.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{ 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;

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"; };
};
}
50 changes: 26 additions & 24 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -1,30 +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;
yamlfmt.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 = {
shellcheck.includes = [ "direnvrc" ];
shfmt.includes = [ "direnvrc" ];
settings.formatter = {
shellcheck.includes = [ "direnvrc" ];
shfmt.includes = [ "direnvrc" ];
};
};
};
};
}

0 comments on commit 5f8bbf7

Please sign in to comment.