Skip to content

Conversation

@flandweber
Copy link
Contributor

fixes #229

@flandweber
Copy link
Contributor Author

My biggest trouble with this is to make the gitUpdate function only update/write the hash attribute if builtin = false.

To realize this I'd require something like an IfThenElse :: Update a b -> Update a b -> Update (Bool, a) b.

I tried implementing this in multiple ways but always failed because of the limited abilities that runUpdate' exposes, which don't seem to enable (lazy) control flows.
I'm at the point where I'm beginning to doubt this can be fixed without overhauling the whole Update Arrow.

@nmattia maybe you have some idea to fix this?

@nmattia
Copy link
Owner

nmattia commented Jun 25, 2024

@flandweber to clarify, the hash is only needed in the pkgs version because it's a fixed output derivation, though not needed in the builtin = true case, right?

I don't 100% remember how arrows work and to be honest I haven't written Haskell in years! But I seem to recall that while you can't change the structure (for some definition of structure) you should be able to update the value. This means you'd always write a hash value, but it may be null:

getHash :: IO T.Text

foo :: Update (Box Bool) (Box Aeson.Value)
foo = arr $ \builtin ->
  Box
    { boxNew = boxNew builtin,
      boxOp = do
        useBuiltin <- boxOp builtin
        if useBuiltin then pure Aeson.Null else Aeson.String <$> getHash
    }

This somewhat typechecks, maybe that's something to investigate?

@flandweber
Copy link
Contributor Author

flandweber commented Jun 25, 2024

@flandweber to clarify, the hash is only needed in the pkgs version because it's a fixed output derivation, though not needed in the builtin = true case, right?

yes, correct

I don't 100% remember how arrows work and to be honest I haven't written Haskell in years! But I seem to recall that while you can't change the structure (for some definition of structure) you should be able to update the value. This means you'd always write a hash value, but it may be null:

getHash :: IO T.Text

foo :: Update (Box Bool) (Box Aeson.Value)
foo = arr $ \builtin ->
  Box
    { boxNew = boxNew builtin,
      boxOp = do
        useBuiltin <- boxOp builtin
        if useBuiltin then pure Aeson.Null else Aeson.String <$> getHash
    }

You're right, I forgot there were null values.
However, from my understanding this would result in a hash attribute being added to sources.json even if buitlin = true.
I think it'd be much cleaner not to add any attributes that aren't needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fetching a github repo with submodules and checksum

2 participants