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

Use without devshell #8

Open
adrian-gierakowski opened this issue Feb 13, 2023 · 10 comments
Open

Use without devshell #8

adrian-gierakowski opened this issue Feb 13, 2023 · 10 comments

Comments

@adrian-gierakowski
Copy link

I’d like to use your modules in a project which doesn’t use devshell (nor flakes). Could this be easily done? I’d like to simply be able to manually invoke a command to generate the files using given PRJ_ROOT

If any changes would be needed, I’d be happy to to contribute if you could point me in the right direction. Thanks!

@hugosenari
Copy link
Contributor

Maybe I could figure it out when doing #6
It can be done for sure, but would mean basically copy mostly all devshell to this project, I mean, TODO:

  1. evaluate modules (like devshell does) maybe using flake-parts?
  2. remove any dependency of devshell 'interface' or implement it in another way (it should be done for Integrate with devenv.sh #6 too)
  3. map every 'files.alias.{name}' to 'packages.{system}.{name}'
  4. map 'files.alias.devshell-files' to 'packages.{system}.default'

This second task will be the hardest one.

@hugosenari
Copy link
Contributor

This would not resolve this issue, but I found it interesting.
Basically is, add a subfolder with a flake using devshell, then you can run nix develop --build in that folder.
Example: https://github.com/TinHead/nixos-firehol his docs generates gh-pages

@hugosenari
Copy link
Contributor

hugosenari commented Feb 17, 2023

You can recreate files of a repository directly to your local machine by running nix develop <flake-uri> --build, example:

# copy all my dogfood ot your current folder
nix develop github:cruel-intentions/devshell-files --build

Maybe it works with absolute paths: path:/path/to/repo

@adrian-gierakowski
Copy link
Author

thanks @hugosenari

I have studied the sources code of devshell and devshell-files in the meantime, and here's what I've got so far.

An example of how this could be used (with flakes) in this repo. You can either checkout the repo and do: nix run inside, or the following from anywhere:

nix run github:rhinofi/devshell-files-test

Uses pwd to set PRJ_ROOT if not already set.

Note that I'm still using devshell.eval but this could be easily replaced as under the hood it's simply lib.evalModules.

The next step would be to extract the devshell specific configuration into a separate module which could simply be omitted if one doesn't use this in the context of devshell (or maybe we could add an option. We should be able to then use the devshell free modules within devenv. Just need to figure out how to pass custom modules so that they get evaluated with everything else. Probably need to add a devenv specific modules (similar to the devshell one) to set any required devenv options.

@adrian-gierakowski
Copy link
Author

The next step would be to extract the devshell specific configuration into a separate module

actually, we could simply hide them behind something like files.devshell.enable, and similarly for devenv

@adrian-gierakowski
Copy link
Author

Would also be good to add default.nix using flake-compat to the repo so that all of this could be consumed by people who are not using flakes

@hugosenari
Copy link
Contributor

hugosenari commented Feb 18, 2023

The next step would be to extract the devshell specific configuration into a separate module

let's play OO game here.

  • create a iface directory
  • copy all existing modules to there
  • remove all config of them
  • create a devshell directory
  • move all existing modules to there
  • remove all options from them
  • update the flake module list with new paths

@hugosenari
Copy link
Contributor

Sorry wrong button

@hugosenari
Copy link
Contributor

actually, we could simply hide them behind something like files.devshell.enable, and similarly for devenv

Looks like every day we have a new devshell alternative

numtide/devshell/issues/242

@adrian-gierakowski
Copy link
Author

The next step would be to extract the devshell specific configuration into a separate module

let's play OO game here.

  • create a iface directory
  • copy all existing modules to there
  • remove all config of them
  • create a devshell directory
  • move all existing modules to there
  • remove all options from them
  • update the flake module list with new paths

sound like a plan

btw. my idea form above:

actually, we could simply hide them behind something like files.devshell.enable, and similarly for devenv

didn't quite work, since if we don't import devshell modules we'll get errors about non existent options, event though the value is behind mkIf (same as described here.

So here's what I've tried: check if options.devshell exists and skip setting config when it doesn't. This allows to keep existing file structure. That same commit has a standalone implementation of eval and examples of evaluation with and without devshell.

I do think that splitting the code into separate files would be cleaner though. Maybe the module containing devshell config could also importing devshell modules, so that user doesn't have to do this manually? Or the integration could be moved to devshell repo itself?

Looks like every day we have a new devshell alternative

numtide/devshell/issues/242

Yeah, given the proliferation of projects which start to leverage nixos module system outside nixos itself, it would do good for the ecosystem to promote a pattern of standalone module (which can be used outside of the "mother" project) + adaptors.

Btw. maybe we should try to push for unification between file creation functionality from this repo and the effort at devenv? Maybe even extract relevant code to a new repo at: https://github.com/nix-community? nix-community/files?

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

No branches or pull requests

2 participants