Skip to content

Commit

Permalink
Replace nixpkgs-fmt with nixfmt (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeme-wana authored Nov 21, 2024
1 parent 621cb9d commit c1beb94
Show file tree
Hide file tree
Showing 39 changed files with 833 additions and 1,013 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Changelog for IOGX

## 19 Nov 2024

- Removed now-archived `nixpkgs-fmt` in favor of `nixfmt-classic`.

To migrate, replace:
```
# shell.nix
{ repoRoot, inputs, pkgs, lib, system }:
lib.iogx.mkShell {
tools.nixpkgs-fmt.enable = true;
}
```
With:
```
# shell.nix
{ repoRoot, inputs, pkgs, lib, system }:
lib.iogx.mkShell {
tools.nixfmt-classic.enable = true;
}
```

12 changes: 6 additions & 6 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1650,8 +1650,8 @@ lib.iogx.mkShell {
editorconfig-checker.enable = false;
editorconfig-checker.extraOptions = "";
nixpkgs-fmt.enable = false;
nixpkgs-fmt.extraOptions = "";
nixfmt-classic.enable = false;
nixfmt-classic.extraOptions = "";
optipng.enable = false;
optipng.extraOptions = "";
Expand Down Expand Up @@ -1703,7 +1703,7 @@ The list of pre-configured hooks is presented below:
- `shellcheck`
- `prettier`
- `editorconfig-checker`
- `nixpkgs-fmt`
- `nixfmt-classic`
- `optipng`
- `fourmolu`
- `hlint`
Expand Down Expand Up @@ -2188,7 +2188,7 @@ If unset or `null`, [`mkShell.<in>.tools.haskellCompilerVersion`](#mkshellintool

---

### `mkShell.<in>.tools.nixpkgs-fmt`
### `mkShell.<in>.tools.nixfmt-classic`

**Type**: null or package

Expand All @@ -2200,13 +2200,13 @@ If unset or `null`, [`mkShell.<in>.tools.haskellCompilerVersion`](#mkshellintool
# shell.nix
{ repoRoot, inputs, pkgs, lib, system }:
lib.iogx.mkShell {
tools.nixpkgs-fmt = repoRoot.nix.patched-nixpkgs-fmt;
tools.nixfmt-classic = repoRoot.nix.patched-nixfmt-classic;
}
```


A package that provides the `nixpkgs-fmt` executable.
A package that provides the `nixfmt-classic` executable.

If unset or `null`, the most recent version available will be used.

Expand Down
92 changes: 43 additions & 49 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
description = "Flake Templates for Projects at IOG";


inputs = {

haskell-nix = {
Expand All @@ -12,7 +11,8 @@
nixpkgs.follows = "haskell-nix/nixpkgs";

# We use this to replace broken packages in haskell-nix/nixpkgs.
nixpkgs-stable.url = "github:NixOS/nixpkgs/b81af66deb21f73a70c67e5ea189568af53b1e8c";
nixpkgs-stable.url =
"github:NixOS/nixpkgs/b81af66deb21f73a70c67e5ea189568af53b1e8c";

hackage = {
url = "github:input-output-hk/hackage.nix";
Expand Down Expand Up @@ -48,43 +48,44 @@
flake-compat.url = "github:edolstra/flake-compat";
};


outputs = inputs:
let
mkFlake = import ./src/mkFlake.nix inputs;

mkTestShell = lib: ghc: lib.iogx.mkShell {
tools.haskellCompilerVersion = ghc;
preCommit = {
cabal-fmt.enable = true;
stylish-haskell.enable = true;
fourmolu.enable = true;
hlint.enable = true;
shellcheck.enable = true;
prettier.enable = true;
editorconfig-checker.enable = true;
nixpkgs-fmt.enable = true;
optipng.enable = true;
purs-tidy.enable = true;
rustfmt.enable = true;
custom-hook = {
enable = true;
entry = "echo 'Running custom hook' ; exit 1";
pass_filenames = false;
language = "fail";
mkTestShell = lib: ghc:
lib.iogx.mkShell {
tools.haskellCompilerVersion = ghc;
preCommit = {
cabal-fmt.enable = true;
stylish-haskell.enable = true;
fourmolu.enable = true;
hlint.enable = true;
shellcheck.enable = true;
prettier.enable = true;
editorconfig-checker.enable = true;
nixfmt-classic.enable = true;
optipng.enable = true;
purs-tidy.enable = true;
rustfmt.enable = true;
custom-hook = {
enable = true;
entry = "echo 'Running custom hook' ; exit 1";
pass_filenames = false;
language = "fail";
};
};
};
};

mkTemplateOutputs = system:
let
vanilla = (import inputs.flake-compat { src = ./templates/vanilla; }).defaultNix;
haskell = (import inputs.flake-compat { src = ./templates/haskell; }).defaultNix;
in
{
vanilla = {
devShells = vanilla.devShells.${system};
};
vanilla = (import inputs.flake-compat {
src = ./templates/vanilla;
}).defaultNix;
haskell = (import inputs.flake-compat {
src = ./templates/haskell;
}).defaultNix;
in {
vanilla = { devShells = vanilla.devShells.${system}; };

haskell = {
devShells = haskell.devShells.${system};
Expand All @@ -94,14 +95,13 @@
};
};

in

mkFlake rec {
in mkFlake rec {
inherit inputs;

repoRoot = ./.;

systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
systems =
[ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];

flake = { repoRoot, inputs }: rec {

Expand Down Expand Up @@ -137,33 +137,31 @@

__debug = { inherit repoRoot pkgs; };

inherit repoRoot pkgs; # For debugging
inherit repoRoot pkgs; # For debugging

packages.rendered-iogx-api-reference = repoRoot.src.core.mkRenderedIogxApiReference;
packages.rendered-iogx-api-reference =
repoRoot.src.core.mkRenderedIogxApiReference;

hydraJobs = {
ghc810-shell = mkTestShell lib "ghc810";
ghc92-shell = mkTestShell lib "ghc92";
ghc96-shell = mkTestShell lib "ghc96";
ghc98-shell = mkTestShell lib "ghc98";
ghc910-shell = mkTestShell lib "ghc910";
rendered-iogx-api-reference = repoRoot.src.core.mkRenderedIogxApiReference;
rendered-iogx-api-reference =
repoRoot.src.core.mkRenderedIogxApiReference;
devShells.default = inputs.self.devShells.default;
templates = mkTemplateOutputs system;
required = lib.iogx.mkHydraRequiredJob { };
};

devShells.default = lib.iogx.mkShell {
name = "iogx";
packages = [
pkgs.jq
pkgs.github-cli
pkgs.python39
pkgs.nix-prefetch-github
];
packages =
[ pkgs.jq pkgs.github-cli pkgs.python39 pkgs.nix-prefetch-github ];
preCommit = {
editorconfig-checker.enable = true;
nixpkgs-fmt.enable = true;
nixfmt-classic.enable = true;
rustfmt.enable = true;
};
scripts.render-iogx-api-reference = {
Expand All @@ -185,12 +183,8 @@
}];
};


nixConfig = {
extra-substituters = [
"https://cache.iog.io"
"https://cache.zw3rk.com"
];
extra-substituters = [ "https://cache.iog.io" "https://cache.zw3rk.com" ];
extra-trusted-public-keys = [
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
"loony-tools:pr9m4BkM/5/eSTZlkQyRt57Jz7OMBxNSUiMC4FkcNfk="
Expand Down
41 changes: 14 additions & 27 deletions src/core/mkCombinedHaddock.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,20 @@ let
# Haskell packages to make documentation for. Only those with a "doc" output will be used.
# Note: we do not provide arbitrary additional Haddock options, as these would not be
# applied consistently, since we're reusing the already built Haddock for the packages.
hsPkgs =
lib.attrValues (
pkgs.haskell-nix.haskellLib.collectComponents' "library" (
pkgs.haskell-nix.haskellLib.selectProjectPackages cabalProject.hsPkgs // (
lib.filterAttrs
(name: _: lib.elem name combinedHaddock.packages)
cabalProject.hsPkgs
)
)
);

hsPkgs = lib.attrValues
(pkgs.haskell-nix.haskellLib.collectComponents' "library"
(pkgs.haskell-nix.haskellLib.selectProjectPackages cabalProject.hsPkgs
// (lib.filterAttrs (name: _: lib.elem name combinedHaddock.packages)
cabalProject.hsPkgs)));

# Optionally, a file to be used for the Haddock "--prologue" option.
prologue =
pkgs.writeTextFile {
name = "prologue";
text = combinedHaddock.prologue;
};

prologue = pkgs.writeTextFile {
name = "prologue";
text = combinedHaddock.prologue;
};

hsPkgs-docs = map (x: x.doc) (lib.filter (x: x ? doc) hsPkgs);


the-mighty-command = ''
hsdocsRec="$(cat graph* | grep -F /nix/store | sort | uniq)"
Expand Down Expand Up @@ -118,7 +109,6 @@ let
echo "Done Combining Haddock"
'';


command-args = {
buildInputs = [ hsPkgs-docs ];

Expand All @@ -127,19 +117,16 @@ let
# us to resolve hyperlinks to haddocks elsewhere in the store.
#
# See also https://nixos.org/manual/nix/stable/expressions/advanced-attributes.html#adv-attr-exportReferencesGraph # editorconfig-checker-disable-line
exportReferencesGraph =
lib.concatLists
(lib.imap0 (i: pkg: [ "graph-${toString i}" pkg ]) hsPkgs-docs);
exportReferencesGraph = lib.concatLists
(lib.imap0 (i: pkg: [ "graph-${toString i}" pkg ]) hsPkgs-docs);
};


combined-haddock = pkgs.runCommand "combine-haddock" command-args the-mighty-command;

combined-haddock =
pkgs.runCommand "combine-haddock" command-args the-mighty-command;

dummy-combined-haddock = pkgs.runCommand "dummy-combined-haddock" { } ''
mkdir -p $out/share/doc
echo "No packages to combine." > $out/share/doc/index.html
'';
in

if combinedHaddock.enable then combined-haddock else dummy-combined-haddock
in if combinedHaddock.enable then combined-haddock else dummy-combined-haddock
Loading

0 comments on commit c1beb94

Please sign in to comment.