Skip to content

Commit 3995ce7

Browse files
authored
Merge pull request #87 from numtide/initial_docs
Added initial document files
2 parents 09a2c2c + 83817ce commit 3995ce7

File tree

15 files changed

+716
-3
lines changed

15 files changed

+716
-3
lines changed

.github/workflows/gh-pages.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Deploy docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "v*"
9+
10+
# Allows you to run this workflow manually from the Actions tab
11+
workflow_dispatch:
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-24.04
16+
permissions:
17+
contents: write
18+
concurrency:
19+
group: ${{ github.workflow }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
- uses: cachix/install-nix-action@V27
25+
with:
26+
extra_nix_config: |
27+
accept-flake-config = true
28+
experimental-features = nix-command flakes
29+
- name: Configure Git user
30+
run: |
31+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
32+
git config --local user.name "github-actions[bot]"
33+
- name: Deploy main
34+
if: ${{ github.ref_name == 'main' }}
35+
run: |
36+
nix develop .#docs --command bash -c "mike deploy -p main"
37+
- name: Deploy version
38+
if: startsWith(github.ref, 'refs/tags/v')
39+
run: |
40+
REF_NAME=${{ github.ref_name }}
41+
MAJOR_MINOR=${REF_NAME%.*}
42+
# strip the leading v from the ref_name
43+
# update the latest alias
44+
nix develop .#docs --command bash -c "mike deploy -p -u ${MAJOR_MINOR} latest"

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
site/

docs/content/assets/images/logo.png

2.33 KB
Loading

docs/content/contributing/code.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Contributing
2+
3+
Coming soon!

docs/content/examples/examples.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Examples
2+
3+
# TODO
4+
5+
Adding new inputs to the top flake.nix file
6+
7+
# TODO
8+
9+
Building a starter template / boilerplate for future projects
10+
11+
If you tend to use the same toolset...
12+
13+
14+
+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
*[todo: We need to put together a short style guide for consistency, including*
2+
* Nix (not nix)
3+
* NixOS (not NixOs etc.)
4+
* Should we say "folder" or "directory"? Younger people seem to prefer "folder" ]
5+
6+
# Installing Blueprint
7+
8+
Let's create a small project with Nix, and you'll see how to add Blueprint to your project.
9+
10+
1. Install [Nix](https://nix.dev/install-nix).
11+
2. Run `mkdir my-project && cd my-project`
12+
3. Run `nix flake init -t github:numtide/blueprint`.
13+
14+
Note: After you install Nix, you'll need to enable "experimental features." Find out how here.
15+
16+
This will give you a barebone project structure with a single `flake.nix` file and a single `devshell.nix` file. (It also provides a basic .envrc, which [TODO] and a starter .gitignore file. Make sure you're aware of this .gitignore file before you accidentally overwrite it.)
17+
18+
Normally, without Blueprint, you would typically include a devShell section inside your flake.nix file. In that scenario, when you want to start a new project with a similar toolset, you'll likely need to copy over the devShell section of your flake.nix file to the new project's flake.nix file. But by using Blueprint, we've split out the devShell into its own file, allowing you to simply copy the file over.
19+
20+
Here's the starting point of your devShell.nix file:
21+
22+
```nix
23+
{ pkgs }:
24+
pkgs.mkShell {
25+
# Add build dependencies
26+
packages = [ ];
27+
28+
# Add environment variables
29+
env = { };
30+
31+
# Load custom bash code
32+
shellHook = ''
33+
34+
'';
35+
}
36+
```
37+
38+
In a moment we'll look at what you can do with this file. Meanwhile, here's the flake.nix file:
39+
40+
```
41+
{
42+
description = "Simple flake with a devshell";
43+
44+
# Add all your dependencies here
45+
inputs = {
46+
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
47+
blueprint.url = "github:numtide/blueprint";
48+
blueprint.inputs.nixpkgs.follows = "nixpkgs";
49+
};
50+
51+
# Load the blueprint
52+
outputs = inputs: inputs.blueprint { inherit inputs; };
53+
}
54+
```
55+
56+
You generally shouldn't have to modify this file (unless you're adding new inputs).
57+
58+
When you run a nix command (such as `nix develop`), this flake.nix file is evaluated and Nix loads the Blueprint into the Nix store and makes it available to your current session. Blueprint in turn allows you to read .nix files from multiple locations within your project, including:
59+
60+
* The devShell.nix file in the root of your project
61+
* A folder structure
62+
63+
You create the folder structure based on the available list of folders (found here).
64+
65+
# A Sample Environment
66+
67+
Let's set up a development environment that includes:
68+
69+
* Python
70+
* Python's numpy package
71+
72+
Open up the devshell.nix file in your favorite editor, and update it to look like this:
73+
74+
```nix
75+
{ pkgs }:
76+
pkgs.mkShell {
77+
# Add build dependencies
78+
packages = [
79+
pkgs.python3
80+
pkgs.python3Packages.numpy
81+
];
82+
83+
# Add environment variables
84+
env = { };
85+
86+
# Load custom bash code
87+
shellHook = ''
88+
export PS1="(python numpy) $PS1"
89+
'';
90+
}
91+
```
92+
93+
Notice we added two packages, Python and the NumPy Python package.
94+
95+
We also added a line inside shellHook. (This line is not required, but it's handy, as it updates the prompt to let you know when you're inside a nix shell.)
96+
97+
Now let's hop into the developer shell by typing:
98+
99+
```bash
100+
nix develop
101+
```
102+
103+
After a short moment where Nix downloads the packages, you'll be inside the shell. To verify the packages were installed, type:
104+
105+
```bash
106+
python
107+
```
108+
109+
Then, inside python type:
110+
111+
```
112+
import numpy
113+
```
114+
115+
You shouldn't see any error.
116+
117+
That's it; go ahead and exit python by typing
118+
119+
```bash
120+
quit()
121+
```
122+
123+
When you're ready to exit the development shell, you can simply type:
124+
125+
```bash
126+
exit
127+
```
128+
129+
## What did this demonstrate?
130+
131+
The above demonstrated that the devshell.nix file is now self-contained and can be used without having to add devshell code inside your flake.nix file.
132+
133+
There's much more, however, that you can do.
134+
135+
Check out:
136+
137+
* Examples (including the rest of our Python/NumPy example)
138+
* Guides
139+
* Contributing
140+
141+
# (Optional) Configuring direnv
142+
143+
Included in the initial files created by Blueprint is a filed called .envrc. This file contains code to configure direnv, which allows you to enter a devshell simply by switching to the folder containing your project. That means you don't need to type `nix develop` after entering the folder. Then when you move up and out of the folder, you'll automatically exit the environment.
144+
145+
For more information on configuring this feature, check out our guide at [Configuring Direnv](../guides/configuring_direnv.md)
146+
147+
148+
## Creating a root folder
149+
150+
151+
152+
153+
154+
## Adding a host
155+
156+
TODO
157+
158+
## Adding a package
159+
160+
TODO
+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Configuring Direnv to speed up loading developer environments
2+
3+
Included in the initial files created by Blueprint is a filed called .envrc. This file contains code to configure direnv, which allows you to enter a devshell simply by switching to the folder containing your project. That means you don't need to type `nix develop` after entering the folder. Then when you move up and out of the folder, you'll automatically exit the environment.
4+
5+
## 1. Install direnv. If you're using NixOS:
6+
7+
In the bash shell, type:
8+
9+
```bash
10+
cd /etc/nixos
11+
```
12+
13+
Then open the file called `configuration.nix` using sudo in conjunction with your favorite editor. For example, if you're using vim:
14+
15+
```bash
16+
sudo vi configuration.nix
17+
```
18+
19+
Locate the line starting with `environment.systemPackages` and add the direnv package, similar to the following:
20+
21+
```bash
22+
environment.systemPackages = with pkgs; [ vim git direnv ];
23+
```
24+
25+
(In this example, I already had vim and git installed.)
26+
27+
## 2. Add a shell hook
28+
29+
Now return to your home folder and open .envrc:
30+
31+
```
32+
cd ~
33+
vi .bashrc
34+
```
35+
36+
Add the following line to the end of the file:
37+
38+
```bash
39+
eval "$(direnv hook bash)"
40+
```
41+
42+
Save the file and exit. Then either:
43+
* Log out and log back in or
44+
* Run the same eval command manually to activate it
45+
46+
Now direnv is running. Switch to a folder containing a Flake/Blueprint project you previously created. For this example we'll use the one we created in the install page, which includes Python and Python's NumPy package.
47+
48+
```bash
49+
cd python_numpy
50+
```
51+
52+
Note that the first time you do this, you will encounter an error:
53+
54+
```bashrc
55+
direnv: error /home/nixos/dev/python_numpy/.envrc is blocked. Run `direnv allow` to approve its content
56+
```
57+
58+
Go ahead and type:
59+
60+
```bash
61+
direnv allow
62+
```
63+
64+
Then direnv will automatically launch the devshell for you. Try it! In this case, because we have Python and NumPy installed, type:
65+
66+
```bash
67+
python
68+
```
69+
70+
and a Python shell should open. Then type:
71+
72+
```python
73+
import numpy
74+
```
75+
76+
Press Enter and you'll see it loaded without an error. Type
77+
78+
```python
79+
exit()
80+
```
81+
82+
## 3. Updating devshell.nix
83+
84+
Direnv will automatically reload and relaunch your developer environemnt quietly behind the scenes if you update your devshell.nix file. Let's try it out. Let's add in the pandas library.
85+
86+
First, verify that pandas is *not* installed. From within Python, try to import pandas; after the error message, exit out of Python:
87+
88+
```python
89+
>>> import pandas
90+
Traceback (most recent call last):
91+
File "<stdin>", line 1, in <module>
92+
ModuleNotFoundError: No module named 'pandas'
93+
>>>
94+
>>> exit()
95+
```
96+
97+
Now open devshell.nix in your favorite editor, and add the pandas package:
98+
99+
```nix
100+
{ pkgs }:
101+
pkgs.mkShell {
102+
# Add build dependencies
103+
packages = [
104+
pkgs.python3
105+
pkgs.python3Packages.numpy
106+
pkgs.python3Packages.pandas
107+
];
108+
109+
# Add environment variables
110+
env = { };
111+
112+
# Load custom bash code
113+
shellHook = ''
114+
115+
'';
116+
}
117+
```
118+
Save it, and you'll briefly see direnv kick in and display some messages. Now return to Python and you'll see that you now have the Pandas package available.
119+
120+
```python
121+
>>> import pandas
122+
>>>
123+
>>> exit()
124+
```
125+
126+
## 4. Exiting the development shell
127+
128+
Finally Now cd up and out of the current folder:
129+
130+
```bash
131+
cd ...
132+
```
133+
134+
You'll see the message:
135+
136+
```bash
137+
direnv: unloading
138+
```
139+
140+
And now to see that you've left the developer environment, try typing ```python``` again and you should see a ```command not found``` error.
141+

docs/content/index.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
template: home.html
3+
search:
4+
exclude: true
5+
---
6+
7+
# Home

0 commit comments

Comments
 (0)