Skip to content

Commit

Permalink
Merge pull request #231 from NixOS/feat/version-file
Browse files Browse the repository at this point in the history
Allow overwriting the version with a .version file
  • Loading branch information
infinisil authored Aug 7, 2024
2 parents 08144b4 + c37f999 commit 7dfd3f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions MAINTENANCE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Maintainer documentation

Writing to .version in the root of the project causes this version to be returned by `nixfmt --version`
rather than the version from the cabalfile.

## Making a new release

- Check the commit log if anything is missing from the change log.
Expand Down
8 changes: 7 additions & 1 deletion main/Main.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Control.Concurrent (Chan, forkIO, newChan, readChan, writeChan)
import Data.ByteString.Char8 (unpack)
import Data.Either (lefts)
import Data.FileEmbed
import Data.List (isSuffixOf)
import Data.Text (Text)
import qualified Data.Text.IO as TextIO (getContents, hPutStr, putStr)
Expand Down Expand Up @@ -46,6 +49,9 @@ data Nixfmt = Nixfmt
}
deriving (Show, Data, Typeable)

versionFromFile :: String
versionFromFile = maybe (showVersion version) unpack $(embedFileIfExists ".version")

options :: Nixfmt
options =
let defaultWidth = 100
Expand All @@ -67,7 +73,7 @@ options =
&= help
"Pretty print the internal AST, only for debugging"
}
&= summary ("nixfmt v" ++ showVersion version)
&= summary ("nixfmt " ++ versionFromFile)
&= help "Format Nix source code"

data Target = Target
Expand Down
2 changes: 2 additions & 0 deletions nixfmt.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ executable nixfmt
hs-source-dirs: main
build-depends:
base >= 4.12.0 && < 4.19
, bytestring
, cmdargs >= 0.10.20 && < 0.11
, file-embed
, nixfmt
, unix >= 2.7.2 && < 2.9
, text >= 1.2.3 && < 2.2
Expand Down

0 comments on commit 7dfd3f0

Please sign in to comment.