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

Allow custom location for nix/sources.json #159

Merged
merged 6 commits into from
Dec 8, 2019
Merged

Conversation

nmattia
Copy link
Owner

@nmattia nmattia commented Dec 8, 2019

Closes #148
Closes #134
Closes #102

To try this out, run

$ nix-env -iA niv -f https://github.com/nmattia/niv/tarball/nm-configure-sources

Closing #148 because the path to nix/sources.json is now configurable both on the CLI and from nix/sources.nix.
Closing #134 because technically sources.nix is now configurable, we'll need to create more specific tickets for particular configurations.
Closing #102 as well, although I suspect that niv init will create some funky sources.nix referencing a sources.json that's not the one provided by the user. @masaeedu can you confirm?

This turns `sources.nix` into a functor that acceps an argument:

``` nix
{ sourcesJson = <path/to/sources.json> ; }
```

The `sourcesJson` will be used instead of `./sources.json`.
The CLI was updated to allow for custom locations of the
`nix/sources.json`:

```

Usage: niv [-s|--sources-json FILE] COMMAND

Available options:
  -s,--sources-json FILE   Use FILE instead of nix/sources.json
  -h,--help                Show this help text
```
@nmattia nmattia merged commit 22e1f90 into master Dec 8, 2019
@nmattia nmattia deleted the nm-configure-sources branch December 8, 2019 20:06
@cprussin
Copy link
Contributor

cprussin commented Dec 8, 2019

@nmattia I was just playing with this, looks like there's some slight inaccuracy in the messaging. When you niv init --sources-json <something> you get this message:

Initializing
  Updating sources.nix
  Not creating ./sources.json
  INFO: You are using a custom path for sources.json.
    You need to configure the sources.nix to use ./sources.json:
        import sources.nix { sourcesJson = PATH ; }; 
    where PATH is the relative path from sources.nix to ./sources.json.
Done: Initializing

Which says to set sourcesJson. But from reading the code (and trying this) the option is actually sourcesFile right? Am I missing something?

@cprussin
Copy link
Contributor

cprussin commented Dec 8, 2019

Also I notice that I can now easily move sources.nix, but if I try to use niv --sources-file <foo> update or niv --sources-file <foo> init then niv still assumes the old location for sources.nix and acts accordingly. Which I guess makes sense, I guess you'd need a separate option to move sources.nix as well, but it's a bit of a strange workflow that sources.json is configurable but sources.nix isn't. Should I submit a separate ticket for that?

@cprussin
Copy link
Contributor

cprussin commented Dec 8, 2019

Also thank you so much for doing this, this PR makes me incredibly happy :D

@cprussin
Copy link
Contributor

cprussin commented Dec 8, 2019

Also (last also I promise) in case anyone is interested here's the commit where I changed my dotfiles to take advantage of this: cprussin/dotfiles@4fbdc79

@nmattia
Copy link
Owner Author

nmattia commented Dec 8, 2019

Which says to set sourcesJson. But from reading the code (and trying this) the option is actually sourcesFile right? Am I missing something?

Dang, you're absolutely right! Hackage went down right when I tried to publish the latest version, that was probably a sign. Feel like submitting a PR? :)

if I try to use niv --sources-file update

That shouldn't be a problem, right? update shouldn't touch sources.nix at all, although you might get a warning about the file not existing. As a very simple heuristics, maybe we should skip the warning if -s is set? Or was there more than just the warning?

niv --sources-file init then niv still assumes the old location for sources.nix [...]

Yeah, that's right. As a disclaimer I gave #132 a lot of thought this weekend, and the motivation for making the sources.json configurable was actually a first step towards pushing sources.nix out of the source tree and instead be fetched via fetchurl. So it'll be a bit awkward for a some time, until I manage to implement the fetchurl version and figure out what to do exactly in case the user wants to checkout sources.nix locally.

@nmattia
Copy link
Owner Author

nmattia commented Dec 8, 2019

cprussin/dotfiles@4fbdc79 nice! I'm curious, what's your plan for updating sources.nix? are you going to niv init and then just mv nix/sources.nix sources.nix; rmdir nix?

I was also thinking about an alternative to -s, namely --directory, which would default to ./nix. WDYT?

@nmattia
Copy link
Owner Author

nmattia commented Dec 8, 2019

Also (last also I promise), have you checked out https://github.com/nmattia/homies ? I used to keep my dotfiles around but then decided to make the whole shizzle actually reproducible, with some nice helpers for installing the packages.

@cprussin
Copy link
Contributor

cprussin commented Dec 9, 2019

Dang, you're absolutely right! Hackage went down right when I tried to publish the latest version, that was probably a sign. Feel like submitting a PR? :)

#160

That shouldn't be a problem, right? update shouldn't touch sources.nix at all, although you might get a warning about the file not existing. As a very simple heuristics, maybe we should skip the warning if -s is set? Or was there more than just the warning?

For update, it's just the warning, so not really a problem. For init (which must be called when the sources.nix file gets updated), it's a bit more of a problem, see below.

Yeah, that's right. As a disclaimer I gave #132 a lot of thought this weekend, and the motivation for making the sources.json configurable was actually a first step towards pushing sources.nix out of the source tree and instead be fetched via fetchurl. So it'll be a bit awkward for a some time, until I manage to implement the fetchurl version and figure out what to do exactly in case the user wants to checkout sources.nix locally.

That sounds like a much better approach. I'm certainly happy to live with some friction until that lands. If that's where things are going I wouldn't worry too much about this workflow in the meantime.

Out of curiosity, since I've started using niv and especially with that insight I've wondered why niv doesn't just generate a nix file instead of json. That would remove the need to even have a sources.nix that does anything special. Is it just about making it easier to read the sources back into the haskell code?

I'm curious, what's your plan for updating sources.nix? are you going to niv init and then just mv nix/sources.nix sources.nix; rmdir nix?

Yeah basically; that repo is 100% nix since it's my dotfiles and so it's really awkward to have a nix folder so I really wanted to avoid it. I figured the pain of nix init; mv ... is pretty slim to do occasionally so I'd just live with it.

I was also thinking about an alternative to -s, namely --directory, which would default to ./nix. WDYT?

I don't really have much of a strong opinion, but I tend to prefer not forcing names of things (it's not unreasonable to want to colocate niv files with other things that might happen to already have names like sources.nix) so for that reason I would typically reach for options to override the hardcoded names for each file, and if something like --directory exists it would just be a shortcut for setting all the relevant options.

Also (last also I promise), have you checked out https://github.com/nmattia/homies ?

This is super cool and I had not seen it before... I will be stealing some ideas :). I have some questions but I will post them over there to keep this thread on topic.

@cprussin
Copy link
Contributor

cprussin commented Dec 9, 2019

I just had an idea: could you distribute sources.nix in the package containing the niv binary? That way I could reference it in my code with something like:

import "${nivPkgs.niv}/share/sources.nix" {
  sourcesFile = ./lol_I_name_files_poorly.json;
}

@masaeedu
Copy link

Sorry, haven't had a chance to play around with my niv config recently, but I'll try to give this a spin this weekend. Thanks again for all the effort that went into implementing this 👍

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.

Make path to nix/* configurable Make sources.nix configurable Different folder for niv init
3 participants