From 83b7372da2fea5ccc3cb6d586609b36ebe9c21df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20He=C3=9F?= Date: Tue, 26 Nov 2024 20:57:58 +0100 Subject: [PATCH] nixfmt-classic: Stop using the hackage package Removes dependency on the hackage package so we can finally fix https://github.com/NixOS/nixfmt/issues/161 and also moves the entire package to pkgs/by-name. --- .../ni/nixfmt-classic/generated-package.nix | 50 +++++++++++++++++++ pkgs/by-name/ni/nixfmt-classic/package.nix | 11 ++++ pkgs/by-name/ni/nixfmt-classic/update.sh | 25 ++++++++++ .../haskell-modules/configuration-common.nix | 2 +- pkgs/top-level/all-packages.nix | 2 - 5 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 pkgs/by-name/ni/nixfmt-classic/generated-package.nix create mode 100644 pkgs/by-name/ni/nixfmt-classic/package.nix create mode 100755 pkgs/by-name/ni/nixfmt-classic/update.sh diff --git a/pkgs/by-name/ni/nixfmt-classic/generated-package.nix b/pkgs/by-name/ni/nixfmt-classic/generated-package.nix new file mode 100644 index 00000000000000..3507faa6e2ffc3 --- /dev/null +++ b/pkgs/by-name/ni/nixfmt-classic/generated-package.nix @@ -0,0 +1,50 @@ +# This file has been autogenerate with cabal2nix. +# Update via ./update.sh +{ + mkDerivation, + base, + cmdargs, + directory, + fetchgit, + filepath, + lib, + megaparsec, + parser-combinators, + safe-exceptions, + scientific, + text, + unix, +}: +mkDerivation { + pname = "nixfmt"; + version = "0.6.0"; + src = fetchgit { + url = "https://github.com/NixOS/nixfmt.git"; + sha256 = "0yh1baanifnv5fl3d7ixkgaki7ka1big0kxkiv4h5rik6zkqfyqz"; + rev = "7e9e06eefed52d6d698b828ee83b83ea5c163f3b"; + fetchSubmodules = true; + }; + isLibrary = true; + isExecutable = true; + libraryHaskellDepends = [ + base + megaparsec + parser-combinators + scientific + text + ]; + executableHaskellDepends = [ + base + cmdargs + directory + filepath + safe-exceptions + text + unix + ]; + jailbreak = true; + homepage = "https://github.com/serokell/nixfmt"; + description = "An opinionated formatter for Nix"; + license = lib.licenses.mpl20; + mainProgram = "nixfmt"; +} diff --git a/pkgs/by-name/ni/nixfmt-classic/package.nix b/pkgs/by-name/ni/nixfmt-classic/package.nix new file mode 100644 index 00000000000000..00050cc955e815 --- /dev/null +++ b/pkgs/by-name/ni/nixfmt-classic/package.nix @@ -0,0 +1,11 @@ +{ haskell, haskellPackages, lib, }: +let + inherit (haskell.lib.compose) overrideCabal justStaticExecutables; + + overrides.passthru.updateScript = ./update.sh; + raw-pkg = haskellPackages.callPackage ./generated-package.nix { }; +in +lib.pipe raw-pkg [ + (overrideCabal overrides) + justStaticExecutables +] diff --git a/pkgs/by-name/ni/nixfmt-classic/update.sh b/pkgs/by-name/ni/nixfmt-classic/update.sh new file mode 100755 index 00000000000000..8fcdbd289beba1 --- /dev/null +++ b/pkgs/by-name/ni/nixfmt-classic/update.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p cabal2nix curl jq +# +# This script will update the nixfmt-classic derivation to the latest version using +# cabal2nix. + +set -eo pipefail + +# This is the directory of this update.sh script. +script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +derivation_file="${script_dir}/generated-package.nix" +latest_version="$(curl --silent 'https://api.github.com/repos/NixOS/nixfmt/releases/latest' | jq --raw-output '.tag_name')" + +echo "Updating nixfmt-classic to version $new_date." +echo "Running cabal2nix and outputting to ${derivation_file}..." + +cat > "$derivation_file" << EOF +# This file has been autogenerate with cabal2nix. +# Update via ./update.sh +EOF + +cabal2nix 'https://github.com/NixOS/nixfmt.git' --revision "${latest_version}" --jailbreak >> "${derivation_file}" +nixfmt "${derivation_file}" + +echo "Finished." diff --git a/pkgs/development/haskell-modules/configuration-common.nix b/pkgs/development/haskell-modules/configuration-common.nix index bd174babd549fa..8178ae7eebfd38 100644 --- a/pkgs/development/haskell-modules/configuration-common.nix +++ b/pkgs/development/haskell-modules/configuration-common.nix @@ -435,7 +435,7 @@ self: super: { postPatch = "sed -i s/home/tmp/ test/Spec.hs"; }) super.shell-conduit; - # https://github.com/serokell/nixfmt/issues/130 + # https://github.com/NixOS/nixfmt/issues/130 nixfmt = doJailbreak super.nixfmt; # Too strict upper bounds on turtle and text diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 4f7ebf911a04e5..9e0badbc79b83b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -18497,8 +18497,6 @@ with pkgs; inherit (darwin.apple_sdk.frameworks) Security SystemConfiguration IOKit; }; - nixfmt-classic = haskellPackages.nixfmt.bin; - nixpkgs-manual = callPackage ../../doc/doc-support/package.nix { }; nixos-artwork = callPackage ../data/misc/nixos-artwork { };