You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Where I'd like to have guidance with respect to flake nixos config for user provided devshells (analogue to what Cole does): Incorporate ./shells divnix/digga#38
I would like to seek structural guidance (later on: eg. examples / templates) on how to combine those ideas in a proper way.
I'm also wondering, how user provided devshells would / could / should interact with project provided devshells.
note, I don't expose mine in my flake yet - I've recently been thinking about this too. I have lots of lofty ideas with fuzzy handwaving around devshells and it intersects with a lot of the questions you prompt here @blaggacao. I don't have much to contribute right now, I have too many other things I really need to finish first.
I'd love to hear of those lofty handwaving thoughts. 😉 If only for the pure joy of waving back at them, or — in fact — trying to broker the hearsay through the graph.
Since devshell uses the nix module system, I think we should take advantage of that more. There is already one project that uses it successfully.
Potentially flakes could export a devshellModules attribute that is a list of modules to load. This would then allow composing the module definitions into the current shell.
I think this refers to the way a numtide/devshell is configured and read. I understand that those devshell configurations can be made composable modules.
nix develop <flake-id>#<shell-name>. Hypothetical example: nix develop github:nix-community/nix-environments#arduino. In this case we provide a fixed shell environment that is dedicated for a purpose. The nix-community/nix-environments repo really exists and could be converted into flakes. The nice thing about this approach is that the invocation is direct, and the downside is that it's not tunable without forking the repo.
The other way, that would work with the devshell project is to export some nix modules. Since devshell is extensible using the same module system as NixOS, extensions could be written and exported out of a flake attribute. In that scenario, the setup is a bit more complicated. First, there is a flake that exports the modules.
{outputs=inputs: {# A module that generates per-project TLS certificates.devshellModules.certificates={config,lib, ... }: {options.certificates={enable=lib.mkEnableOption"certificates";# TODO: add real config here};config=lib.optionalAttrsconfig.certificiates.enable{# TODO: set some devshell config here, like add a new command};};};}
Then on the consumer side:
{inputs.flake-utils.url="github:numtide/flake-utils";inputs.devshell.url="github:numtide/devshell";inputs.devshell-modules.uri="github:numtide/devshell-modules";# does not existoutputs={self,flake-utils,devshell,devshell-modules,nixpkgs}:
flake-utils.lib.simpleFlake{inheritnixpkgs;name="my-project";preOverlays=[(importdevshell.overlay)];shell={pkgs}:
pkgs.mkDevShell{imports=[(importdevshell-modules.devshellModules.certificates)];# Now the certificates options are availablecertificates.enable=true;};};}
Something like that. As you can see it's much more complicated to use. But it allows changing the behavior of devshell.
Playing around with this idea: https://github.com/nrdxp/nixflk/pull/39/files done so in nixflk to encourage sharing by default, but any community curated devshells should probably live in github:nix-community/nix-environments@colemickens I hope its helpful to see how this could play out. I have skill deficits from here on.
After some thought, for the first sharing use case mentioned, I think nix should be amended to provide for devshells and defaultDevshell analogous to templates & defaultTemplate, etc.
A simple project-proper use case:
A project provides two or three devshells:
backend
frontend
combined
Quid: when the frontend team evolves, they don't force a shell rebuild on the backend team each time.
The use case can be projected onto a different division of project shells managed (and evolved!) by different teams within the project (at different speeds!)
How should this be proposed / approached for most chances of success and effectiveness?
Sorry for necroposting here, but in case anyone stumbles upon this and tries to use the module method described in #52 (comment) (notably lib.optionalAttrs caused a confusing "infinite recursion" error here)
These are working snippets (atm) that should get you going:
flake.nix that exports the module:
{
outputs = inputs: {
# A module that generates per-project TLS certificates.
devshellModules.certificates = { config, lib, ... }: {
options.certificates = {
enable = lib.mkEnableOption "Great certificates option description";
# TODO: add real config here
};
config = lib.mkIf config.certificiates.enable {
# TODO: set some devshell config here, like add a new command
};
};
};
}
flake.nix consumer side:
{
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.devshell.url = "github:numtide/devshell";
inputs.devshell-modules.url = "github:numtide/devshell-modules"; # does not exist
outputs = { self, flake-utils, devshell, devshell-modules, nixpkgs }:
flake-utils.lib.simpleFlake {
inherit self nixpkgs;
name = "my-project";
preOverlays = [ devshell.overlay ];
shell = { pkgs }:
pkgs.devshell.mkShell {
imports = [ devshell-modules.devshellModules.certificates ];
# Now the certificates options are available
certificates.enable = true;
};
};
}
Activity
colemickens commentedon Dec 25, 2020
note, I don't expose mine in my flake yet - I've recently been thinking about this too. I have lots of lofty ideas with fuzzy handwaving around devshells and it intersects with a lot of the questions you prompt here @blaggacao. I don't have much to contribute right now, I have too many other things I really need to finish first.
blaggacao commentedon Dec 26, 2020
I'd love to hear of those lofty handwaving thoughts. 😉 If only for the pure joy of waving back at them, or — in fact — trying to broker the hearsay through the graph.
zimbatm commentedon Dec 26, 2020
Since devshell uses the nix module system, I think we should take advantage of that more. There is already one project that uses it successfully.
Potentially flakes could export a devshellModules attribute that is a list of modules to load. This would then allow composing the module definitions into the current shell.
blaggacao commentedon Dec 27, 2020
Thank you! Sounds like a good idea, I'll adapt my exploratory draft PR over at nixflk accordingly.
nrdxp commentedon Dec 29, 2020
@zimbatm, could you expand on this more. What do mean by nix modules? Surely you don't mean NixOS modules 😜
blaggacao commentedon Dec 29, 2020
I think this refers to the way a numtide/devshell is configured and read. I understand that those devshell configurations can be made composable modules.
nrdxp commentedon Dec 29, 2020
Thanks, makes perfect sense.
zimbatm commentedon Dec 29, 2020
There are actually two levels to share shells.
nix develop <flake-id>#<shell-name>. Hypothetical example:nix develop github:nix-community/nix-environments#arduino. In this case we provide a fixed shell environment that is dedicated for a purpose. The nix-community/nix-environments repo really exists and could be converted into flakes. The nice thing about this approach is that the invocation is direct, and the downside is that it's not tunable without forking the repo.The other way, that would work with the devshell project is to export some nix modules. Since devshell is extensible using the same module system as NixOS, extensions could be written and exported out of a flake attribute. In that scenario, the setup is a bit more complicated. First, there is a flake that exports the modules.
Then on the consumer side:
Something like that. As you can see it's much more complicated to use. But it allows changing the behavior of devshell.
blaggacao commentedon Dec 29, 2020
I would be opposite to opposed to
github:numtide/devshell-modules. Would you give birth to it? I take the cert example as a hint.blaggacao commentedon Dec 29, 2020
Playing around with this idea: https://github.com/nrdxp/nixflk/pull/39/files done so in nixflk to encourage sharing by default, but any community curated devshells should probably live in
github:nix-community/nix-environments@colemickens I hope its helpful to see how this could play out. I have skill deficits from here on.EDIT: also divnix/digga#55 for a more useful attempt.
blaggacao commentedon Dec 29, 2020
After some thought, for the first sharing use case mentioned, I think
nixshould be amended to provide fordevshellsanddefaultDevshellanalogous totemplates&defaultTemplate, etc.A simple project-proper use case:
How should this be proposed / approached for most chances of success and effectiveness?
[-]Provide a thought model for sharing devshells[/-][+]Document how to share devshell modules[/+]blaggacao commentedon May 21, 2021
One possible implementation / blueprint for docs: divnix/digga#24
(Exported as
self.devshellModules)blaggacao commentedon Jun 20, 2021
we just use
self.devshellModulesindigga. Closing.teutat3s commentedon Oct 12, 2022
Sorry for necroposting here, but in case anyone stumbles upon this and tries to use the module method described in #52 (comment) (notably
lib.optionalAttrscaused a confusing "infinite recursion" error here)These are working snippets (atm) that should get you going:
flake.nixthat exports the module:flake.nixconsumer side: