-
Notifications
You must be signed in to change notification settings - Fork 330
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
flake.nix: Add flakeModule #360
Conversation
`devenv` can be used without the `devenv` CLI by integrating into [Nix Flakes](https://www.tweag.io/blog/2020-05-25-flakes/), if you're more familiar with the Nix language/ecosystem. | ||
|
||
Some usecases for using devenv configuration inside flakes is for projects that want to define other Nix flake features, apart from the development shell. | ||
These include a Nix package for the project, NixOS and home-manager modules related to the project. | ||
Usually you want to use the same lock file for the development shell as well as the Nix package and others, so that everything is based on the same nixpkgs. | ||
|
||
A Nix flake includes the inputs from `devenv.yaml` as well as the devenv configuration that you'd usually find in `devenv.nix`. `flake.lock` is the lock file for Nix flakes, the equivalent to `devenv.lock`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using devenv
via the flake module, assuming that the devenv
CLI isn't available, how would I run processes/services defined in configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On that note, it would be pretty amazing to expose the process runners and/or the direct commands they execute via flake.apps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assuming that the
devenv
CLI isn't available
Bad assumption -- I just checked out this branch (after rebasing onto main
) and I see that the CLI is available. However, when I run devenv up
:
✦ ❯ devenv up
File devenv.nix does not exist. To get started, run:
$ devenv init
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I accidentally shadowed the shim by adding the whole devenv package to the packages. That was old code from before the shim existed. Now the module is on par with the existing flake integration.
How to propagate the {
perSystem = {config, ...}: {
devenv.shells.default = {
pre-commit = {
inherit (config.pre-commit.settings) hooks settings;
};
};
};
} But all the settings end up being repeated/merged, e.g. the generated YAML file: ...
{
"entry": "/nix/store/d1x69xig1bwbk8xpn35zw6lcizdwnyhh-statix-0.5.6/bin/statix check -o errfmt /nix/store/d1x69xig1bwbk8xpn35zw6lcizdwnyhh-statix-0.5.6/bin/statix check -o errfmt ",
"exclude": "^$^$",
"files": "\\.nix$\\.nix$",
"id": "statix",
"language": "systemsystem",
"name": "statixstatix",
"pass_filenames": false,
"stages": [
"commit",
"commit"
],
"types": [
"file",
"file"
],
"types_or": []
},
... |
For now my workaround was to not use the integration, but instead just add the hook via a script: {
perSystem = {config, ...}: {
devenv.shells.default = {
enterShell = config.pre-commit.installationScript;
};
};
} |
e82dccf
to
2cae5ec
Compare
Just did a trivial rebase to update the CI config and hopefully fix the CI, but looks like it needs to be approved. |
nix flake --impure | ||
``` | ||
|
||
In normal `nix flake` projects, `--impure` is not needed. When using `devenv` in your flake, you _do_ need this option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why does devenv
require --impure
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also been curiously wondering about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related: #330
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear to me too, but this is just inherited from the existing flake integration.
I'm getting same error as reported in #495 with latest commit of this PR, here is my complete
{
description = "Description for the project";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# devenv.url = "github:cachix/devenv/latest";
# see https://github.com/cachix/devenv/pull/360
devenv.url = "github:cachix/devenv/9f761946802870fcbfd5710cd722b568971e057a";
};
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.devenv.flakeModule
];
systems = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }: {
# Per-system attributes can be defined here. The self' and inputs'
# module parameters provide easy access to attributes of the same
# system.
# Equivalent to inputs'.nixpkgs.legacyPackages.hello;
packages.default = pkgs.hello;
devenv.shells.default = {
# https://devenv.sh/reference/options/
packages = [ config.packages.default ];
enterShell = ''
hello
'';
};
};
flake = {
# The usual flake attributes can be defined here, including system-
# agnostic ones like nixosModule and system-enumerating ones, although
# those are more easily expressed in perSystem.
};
};
} |
@nazarewk How did you invoke it?
|
Rebased, tests pass locally (workflow needs approval), added the containers as packages. @domenkozar wdyt? |
Makes devenv usable for flake-parts users.