Skip to content

Commit

Permalink
cli
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Aug 4, 2023
1 parent 83706a8 commit 74a6809
Show file tree
Hide file tree
Showing 22 changed files with 318 additions and 97 deletions.
12 changes: 6 additions & 6 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1689261696,
"narHash": "sha256-LzfUtFs9MQRvIoQ3MfgSuipBVMXslMPH/vZ+nM40LkA=",
"lastModified": 1690952720,
"narHash": "sha256-fPsiQHARfhVxXpWgcuSKvkYwSco8K13K7XevBpdIfPg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "df1eee2aa65052a18121ed4971081576b25d6b5c",
"rev": "96112a3ed5d12bb1758b42c63b924c004b6c0bc9",
"type": "github"
},
"original": {
Expand Down Expand Up @@ -164,11 +164,11 @@
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1688596063,
"narHash": "sha256-9t7RxBiKWHygsqXtiNATTJt4lim/oSYZV3RG8OjDDng=",
"lastModified": 1690743255,
"narHash": "sha256-dsJzQsyJGWCym1+LMyj2rbYmvjYmzeOrk7ypPrSFOPo=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "c8d18ba345730019c3faf412c96a045ade171895",
"rev": "fcbf4705d98398d084e6cb1c826a0b90a91d22d7",
"type": "github"
},
"original": {
Expand Down
5 changes: 4 additions & 1 deletion devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
pkgs.cairo
pkgs.xorg.libxcb
pkgs.yaml2json
pkgs.tesh
];

languages.nix.enable = true;
Expand Down Expand Up @@ -42,6 +43,7 @@
tmp="$(mktemp -d)"
devenv init "$tmp"
pushd "$tmp"
devenv version
devenv ci
popd
rm -rf "$tmp"
Expand Down Expand Up @@ -124,5 +126,6 @@
MD034 = false;
};

tests = config.lib.mkTests [ "devenv" ] ./examples;
tests = config.lib.mkTests ./examples
// config.lib.mkTests ./tests;
}
4 changes: 2 additions & 2 deletions devenv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ inputs:
url: github:domenkozar/nix/relaxed-flakes
inputs:
nixpkgs:
follows: "nixpkgs"
follows: nixpkgs
devenv:
url: path:./src/modules
pre-commit-hooks:
url: github:cachix/pre-commit-hooks.nix
inputs:
nixpkgs:
follows: "nixpkgs"
follows: nixpkgs
34 changes: 34 additions & 0 deletions docs/binary-caching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Typically [packages](./packages.md) come prebuilt with binaries provided by [the official binary cache](https://cache.nixos.org).

If you're modifying a package or using a package that's not built upstream,
Nix will build it from source instead of downloading a binary.

To prevent packages from being built more than once, there's seamless integration with
binary caches using [Cachix](https://cachix.org).

## Setup

If you'd like to push binaries to your own cache, you'll need [to create one](https://app.cachix.org/cache).

After that you'll need to set `cachix authtoken XXX` with either [a personal auth token](https://app.cachix.org/personal-auth-tokens) or a cache token (that you can create in cache settings).

## devenv.nix

To specify `pre-commit-hooks` as a cache to pull from and `mycache` to pull from and push to:

```nix title="devenv.nix"
{
cachix.pull = [ "pre-commit-hooks" ];
cachix.push = "mycache";
}
```

# Pushing only in specific cases

You'll likely not want every user to push to the cache.

It's usually convenient to push [explicitly](./files-and-variables/#devenvlocalnix), for example as part of CI run:

```shell-session
$ echo '{ cachix.push = "mycache"; }' > devenv.local.nix
```
17 changes: 6 additions & 11 deletions docs/community/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@ We have a rule that new features need to come with documentation and tests (`dev

## Preparing the `devenv` development environment

1. Follow the [installation instructions for Nix and Cachix](../../getting-started/#installation).
1. Follow the [installation instructions for Nix and Cachix](../../getting-started/#installation) and [install direnv](../../automatic-shell-activation/).

2. `git clone https://github.com/cachix/devenv.git`

3. `cd devenv`

4. To build the project, run `nix-build`.

5. `./result/bin/devenv shell`

6. Once you have made changes, run `./result/bin/devenv shell` again.

To automate this workflow, [install and use direnv](../../automatic-shell-activation/).
4. To build the project, run `direnv allow .`.

## Repository structure

- The `devenv` CLI is in `src/devenv.nix`.
- The `flake.nix` auto-generation logic lies in `src/flake.nix`.
- The `devenv` CLI is in `src/devenv/cli.py`.
- The `flake.nix` auto-generation logic lies in `src/modules/flake.tmpl.nix`.
- All modules related to `devenv.nix` are in `src/modules/`.
- Examples are automatically tested on CI and are the best way to work on developing new modules, see `examples/`.
- Examples are automatically tested on CI and are the best way to work on developing new modules, see `examples/` and `tests/`
- Documentation is in `docs/`.
- To run a development server, run `devenv up`.
- To run a test, run `devnenv test <example-name>`.

## Contributing language improvements

Expand Down
55 changes: 55 additions & 0 deletions docs/tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
To ease testing of your environments,
we provide a way to define the tests and to run them.

## Writing devenv tests

A simple test would look like:

```nix title="devenv.nix"
{ pkgs, ... }: {
tests.basic = {
nix = ''
{ pkgs, ... }: {
packages = [ pkgs.ncdu ];
}
'';
test = ''
ncdu --version | grep "ncdu 2.2"
'';
};
}
```

```shell-session
$ devenv test
✔ Gathering tests in 0.3s.
• Found 1 test(s), running 1:
• Testing basic ...
• Running $ devenv ci
• Running .test.sh.
✔ Running basic in 16.7s.
```

## Defining tests in a folder

A simple test with a tesh script:

```shell-session
$ ls tests/mytest/
.test.sh devenv.nix devenv.yaml
```

And define it:

```nix title="devenv.nix"
{ config, ... }: {
tests = config.lib.mkTests ./tests;
}
```

Run tests:

```shell-session
$ devenv test
...
```
8 changes: 6 additions & 2 deletions examples/overlays/devenv.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{ pkgs, ... }:

{
packages = [ pkgs.rust-bin.stable.latest.default ];
packages = [
# from the rust-overlay
pkgs.rust-bin.stable.latest.default

services.blackfire.enable = true;
# from subflake
pkgs.hello2
];
}
4 changes: 4 additions & 0 deletions examples/overlays/devenv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ allowUnfree: true
inputs:
nixpkgs:
url: github:NixOS/nixpkgs/nixpkgs-unstable
subflake:
url: path:./subflake
overlays:
- default
rust-overlay:
url: github:oxalica/rust-overlay
overlays:
Expand Down
7 changes: 7 additions & 0 deletions examples/overlays/subflake/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
outputs = { ... }: {
overlays.default = self: super: {
hello2 = self.hello;
};
};
}
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ nav:
- Processes: processes.md
- Services: services.md
- Containers: containers.md
- Binary Caching: binary-caching.md
- Pre-Commit Hooks: pre-commit-hooks.md
- Tests: tests.md
- Common Patterns: common-patterns.md
- Writing devenv.yaml:
- Inputs: inputs.md
Expand Down
32 changes: 16 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ click = "^8.1.4"
strictyaml = "^1.7.3"
terminaltables = "^3.1.10"
filelock = "^3.12.0"
requests = "^2.31.0"

[tool.poetry.group.docs]
optional = true
Expand Down
Loading

0 comments on commit 74a6809

Please sign in to comment.