knl / niv-updater-action

A GitHub Action that creates meaningful pull requests with updates to your niv-managed dependencies, so you don't have to do menial chores.
BSD 3-Clause "New" or "Revised" License
29 stars 11 forks source link

flakes? #60

Open nomeata opened 1 year ago

nomeata commented 1 year ago

I am quite fond of the niv / niv-update-action combination, but it seems that the Nix world is moving to flakes, which replaces niv.

So I wonder if there is a flake-update-action that is on-par with niv-update-action (e.g. the changelog handling etc)?

Opening this issue mostly as a place for me and others to find links to other projects; I’m not actually suggesting that niv-updater-action learns about flakes (although, why not?)

knl commented 1 year ago

Hi @nomeata that's a good question! I've been thinking of making a copy of this repo and adapting it to work with flakes, but I don't use flakes, so can't dedicate a lot of time to it. I saw that some people tried taking that path, but abandoned the project.

nomeata commented 1 year ago

Yes, if you don’t use them yourself, I wouldn’t expect you to create that project. Let’s see how long it takes until you don’t get around flakes anymore either :-D.

Or alternatively niv could become flake-aware and keep it's nice UI, but simply edit the flake.lock instead of the sources.json transparently – WDYT, @nmattia :-)

nmattia commented 1 year ago

Or alternatively niv could become flake-aware and keep its nice UI

PRs welcome :) might just be a matter of updating setSources and getSources in this file:

getSourcesEither :: FindSourcesJson -> IO (Either SourcesError Sources)
getSourcesEither fsj = do
  Dir.doesFileExist (pathNixSourcesJson fsj) >>= \case
    False -> pure $ Left SourcesDoesntExist
    True ->
      Aeson.decodeFileStrict (pathNixSourcesJson fsj) >>= \case
        Just value -> case valueToSources value of
          Nothing -> pure $ Left SpecIsntAMap
          Just srcs -> pure $ Right srcs
        Nothing -> pure $ Left SourceIsntJSON
  where
    valueToSources :: Aeson.Value -> Maybe Sources
    valueToSources = \case
      Aeson.Object obj ->
        fmap (Sources . mapKeys PackageName . KM.toHashMapText) $
          traverse
            ( \case
                Aeson.Object obj' -> Just (PackageSpec obj')
                _ -> Nothing
            )
            obj
      _ -> Nothing
    mapKeys :: (Eq k2, Hashable k2) => (k1 -> k2) -> HMS.HashMap k1 v -> HMS.HashMap k2 v
    mapKeys f = HMS.fromList . map (first f) . HMS.toList

if you can decode the flake lock in a way that maps to Sources, that should work seamlessly!

nomeata commented 1 year ago

There is also https://github.com/DeterminateSystems/update-flake-lock which might be an alternative. (I’ve opened https://github.com/DeterminateSystems/update-flake-lock/issues/65 to see if they would be interested in adding the changelog listing feature)