Skip to content

Commit

Permalink
Merge pull request #167 from NixOS/nix-refactor
Browse files Browse the repository at this point in the history
Nix improvements
  • Loading branch information
infinisil authored Mar 19, 2024
2 parents 136005f + 43c3857 commit 7f9a820
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
- uses: cachix/install-nix-action@v26

- name: reuse lint
run: nix shell .#packages.x86_64-linux.reuse -c reuse lint
run: nix-build -A packages.reuse && result/bin/reuse lint

- name: build nixfmt
run: nix build -L .#nixfmt-static
run: nix-build
if: success() || failure()
59 changes: 24 additions & 35 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,50 +30,39 @@ let

inherit (pkgs) haskell lib;

regexes = [
".*.cabal$"
"^src.*"
"^main.*"
"^Setup.hs$"
"^js.*"
"LICENSE"
];
src = builtins.path {
path = ./.;
name = "nixfmt-src";
filter =
path: type:
let
relPath = lib.removePrefix (toString ./. + "/") (toString path);
in
lib.any (re: builtins.match re relPath != null) regexes;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./nixfmt.cabal
./src
./main
./LICENSE
];
};

build = pkgs.haskellPackages.nixfmt;
build = lib.pipe pkgs.haskellPackages.nixfmt [
haskell.lib.justStaticExecutables
haskell.lib.dontHaddock
(drv: lib.lazyDerivation { derivation = drv; })
];
in
build
// rec {
// {
packages = {
nixfmt = build;
nixfmt-static = haskell.lib.justStaticExecutables packages.nixfmt;
nixfmt-deriver = packages.nixfmt-static.cabal2nixDeriver;

nixfmt-shell = packages.nixfmt.env.overrideAttrs (oldAttrs: {
buildInputs =
oldAttrs.buildInputs
++ (with pkgs; [
# nixfmt: expand
cabal-install
stylish-haskell
shellcheck
npins
]);
});

inherit (pkgs) reuse;
};

shell = packages.nixfmt-shell;
shell = pkgs.haskellPackages.shellFor {
packages = p: [ p.nixfmt ];
nativeBuildInputs = with pkgs; [
cabal-install
stylish-haskell
haskellPackages.haskell-language-server
shellcheck
npins
];
};

checks = {
hlint = pkgs.build.haskell.hlint ./.;
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

apps.default = {
type = "app";
program = "${self.packages.${system}.nixfmt-static}/bin/nixfmt";
program = "${result}/bin/nixfmt";
};

checks = result.checks;
Expand Down

0 comments on commit 7f9a820

Please sign in to comment.