Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
nixfmt-rfc-style: init at 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vlinkz committed May 14, 2024
1 parent 8148c3e commit f31f6ac
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkgs/by-name/ni/nixfmt-rfc-style/date.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-03-01
40 changes: 40 additions & 0 deletions pkgs/by-name/ni/nixfmt-rfc-style/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
haskell,
haskellPackages,
lib,
runCommand,
nixfmt-rfc-style,
fetchpatch,
}:
let
inherit (haskell.lib.compose) overrideCabal justStaticExecutables;

overrides = {
version = "unstable-${lib.fileContents ./date.txt}";

passthru.updateScript = ./update.sh;

patches = [
(fetchpatch {
url = "https://github.com/serokell/nixfmt/commit/ca9c8975ed671112fdfce94f2e9e2ad3de480c9a.patch";
hash = "sha256-UOSAYahSKBsqPMVcQJ3H26Eg2xpPAsNOjYMI6g+WTYU=";
})
];

maintainers = [ ];

# These tests can be run with the following command.
#
# $ nix-build -A nixfmt-rfc-style.tests
passthru.tests =
runCommand "nixfmt-rfc-style-tests" { nativeBuildInputs = [ nixfmt-rfc-style ]; }
''
nixfmt --version > $out
'';
};
raw-pkg = haskellPackages.callPackage ./generated-package.nix { };
in
lib.pipe raw-pkg [
(overrideCabal overrides)
justStaticExecutables
]
27 changes: 27 additions & 0 deletions pkgs/by-name/ni/nixfmt-rfc-style/generated-package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file has been autogenerate with cabal2nix.
# Update via ./update.sh
{ mkDerivation, base, cmdargs, directory, fetchzip, filepath, lib
, megaparsec, mtl, parser-combinators, safe-exceptions, scientific
, text, transformers, unix
}:
mkDerivation {
pname = "nixfmt";
version = "0.5.0";
src = fetchzip {
url = "https://github.com/piegamesde/nixfmt/archive/2b5ee820690bae64cb4003e46917ae43541e3e0b.tar.gz";
sha256 = "1i1jbc1q4gd7fpilwy6s3a583yl5l8d8rlmipygj61mpclg9ihqg";
};
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
base megaparsec mtl parser-combinators scientific text transformers
];
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";
}
33 changes: 33 additions & 0 deletions pkgs/by-name/ni/nixfmt-rfc-style/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p cabal2nix curl jq
#
# This script will update the nixfmt-rfc-style 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"
date_file="${script_dir}/date.txt"

# This is the latest version of nixfmt-rfc-style branch on GitHub.
new_version=$(curl --silent https://api.github.com/repos/piegamesde/nixfmt/git/refs/heads/rfc101-style | jq '.object.sha' --raw-output)
new_date=$(curl --silent https://api.github.com/repos/piegamesde/nixfmt/git/commits/"$new_version" | jq '.committer.date' --raw-output)

echo "Updating nixfmt-rfc-style 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 --jailbreak \
"https://github.com/piegamesde/nixfmt/archive/${new_version}.tar.gz" \
>> "$derivation_file"

date --date="$new_date" -I > "$date_file"

echo "Finished."

0 comments on commit f31f6ac

Please sign in to comment.