Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to run MonadNixThunk to make the library easier to use #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* [#45] Add runMonadNixThunk to make it easier to run the actions defined in the library.
* [#42](https://github.com/obsidiansystems/nix-thunk/pull/42) Thunk read errors are now presented in a more informative manner.
* [#43](https://github.com/obsidiansystems/nix-thunk/pull/43) `nix-thunk` will now ensure that any `git` processes invoked during its execution have a clean configuration.
This prevents `nix-thunk` crashing when e.g. the user's configuration `git` is valid only in a version newer than what `nix-thunk` links against, and works towards making thunks more reproducible by ensuring that thunk URIs are resolvable independently of the user's environment.
Expand Down
2 changes: 1 addition & 1 deletion nix-thunk.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: >=1.10
name: nix-thunk
version: 0.6.1.0
version: 0.6.2.0
license: BSD3
license-file: LICENSE
copyright: Obsidian Systems LLC 2020-2022
Expand Down
4 changes: 3 additions & 1 deletion src/Nix/Thunk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
module Nix.Thunk
( ThunkSource (..)
( runMonadNixThunk
, ThunkSource (..)
, GitHubSource (..)
, ThunkRev (..)
, getLatestRev
Expand Down
8 changes: 8 additions & 0 deletions src/Nix/Thunk/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
Expand Down Expand Up @@ -73,6 +74,7 @@ import Data.Yaml (parseMaybe)
import GitHub
import GitHub.Data.Name
import System.Directory
import System.Environment (getArgs)
import System.Exit
import System.FilePath
import System.IO.Error (isDoesNotExistError)
Expand All @@ -97,6 +99,12 @@ type MonadNixThunk m =
, MonadFail m
)

-- | Runs MonadNixThunk actions with relatively sensible options for non-interactive use.
runMonadNixThunk :: forall a. (forall m. MonadNixThunk m => m a) -> IO a
runMonadNixThunk x = do
cliConf <- newCliConfig Error False False (\e -> (prettyNixThunkError e, ExitFailure 1))
runCli cliConf x

data NixThunkError
= NixThunkError_ProcessFailure ProcessFailure
| NixThunkError_Unstructured Text
Expand Down