Skip to content

Add Nix to the tools section #255

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions content/tools/standalone/environments/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Environments",
"position": 3
}
45 changes: 45 additions & 0 deletions content/tools/standalone/environments/nix.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: "Preface"
description: "Using C and C++ with Nix: Preface"
hide_title: true
---

# Using C and C++ with Nix

When it comes to using C++ with Nix, one may want to do several things:
1. Create a development shell with tools and libraries which is then used in the development loop
2. Package a new/existing project for other Nix and non-Nix users to use
3. Contribute to nixpkgs, so that the packaged project is readily available from the centralized repository
4. Create a CI/CD environment to evaluate the correctness of the project

This series of articles explains all of these in detail, with focus on good practices.

On top of that, we will show how to achieve each of those with flake and non-flake configurations and
how the code may differ when contributed to nixpkgs.

:::caution
This series is **not** by any means a Nix tutorial, each section assumes the reader has a certain knowledge
acquired beforehand. We will be explaining some patterns and concepts, but you won't probably wont understand
much without having some decent understanding.

If you are unsure about your Nix basics this is what I would recommend:

1. Get familiar with the Nix language first:
- https://learnxinyminutes.com/docs/nix/
- https://nix.dev/tutorials/nix-language#reading-nix-language
- https://nixcloud.io/tour/?id=introduction/nix

2. Go through nix.dev to have a better grasp about Nix concepts and good practices:
- https://nix.dev

3. You may want to read up on flakes as well, as they are ubiquitous in the community:
- https://nixos.wiki/wiki/Flakes
- https://nix.dev/concepts/flakes.html
- https://www.tweag.io/blog/2020-05-25-flakes/
- https://jvns.ca/blog/2023/11/11/notes-on-nix-flakes/

4. For lower level knowledge, go through Nix pills:
- https://nixos.org/guides/nix-pills/

5. Toy with and explore the ecosystem - most knowledge is gained through first-hand experience.
:::
17 changes: 17 additions & 0 deletions content/tools/standalone/environments/nix/shells.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
sidebar_position: 1
title: Nix C++ development shell
sidebar_label: Development shell
description: Learn how to setup a development shell with Nix
tags: [environemnt, tools, nix, nixos]
hide_title: true
---

import NotFinished from '@site/i18n/en/presets/NotFinished.mdx';
import ImproveSection from '@site/i18n/en/presets/ImproveSection.mdx';

<NotFinished />

# Setting up a C++ development shell with Nix


5 changes: 4 additions & 1 deletion sidebars/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export function cat(name: string): SidebarItemConfig {
return separatorBase(`<span>${name}</span>`, "sidebar-separator sidebar-category");
}

export const lessonsSeparator = cat("Lessons:");
export const additionalSeparator = cat("Additional:");

export function parseClassItemShorthand(id: string, e, flags: Flags = []): SidebarItemConfig {
if (typeof e !== "string") {
if (Array.isArray(e))
Expand Down Expand Up @@ -87,4 +90,4 @@ export function docsClassCat(label: string, id: string, flags: Flags, contents):
link: { type: "doc", id: id },
items: contents.map(e => parseClassItemShorthand(id, e))
};
}
}
7 changes: 2 additions & 5 deletions sidebars/learn.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import type { SidebarItemConfig, SidebarsConfig } from "./types";
import { cat } from "./common";
import { lessonsSeparator, additionalSeparator } from "./common";

function doc(sidebarLabel: string, docId: string): SidebarItemConfig {
return { type: "doc", label: sidebarLabel, id: docId };
}

const lessonsSeparator = cat("Lessons:");
const additionalSeparator = cat("Additional:");

const sidebars: SidebarsConfig = {
defaultSidebar: [
"index",
Expand Down Expand Up @@ -305,4 +302,4 @@ const sidebars: SidebarsConfig = {
],
};

export default sidebars;
export default sidebars;
18 changes: 17 additions & 1 deletion sidebars/tools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { SidebarsConfig } from "./types";
import { lessonsSeparator } from "./common";

const sidebars: SidebarsConfig = {
defaultSidebar: [
Expand Down Expand Up @@ -51,9 +52,24 @@ const sidebars: SidebarsConfig = {
"standalone/compilers/setup-clang-macos",
]
},
{
type: "category",
label: "Environments",
items: [
{
type: "category",
label: "Nix",
link: { type: "doc", id: "standalone/environments/nix" },
items: [
lessonsSeparator,
"standalone/environments/nix/shells",
]
}
]
},
]
}
],
};

export default sidebars;
export default sidebars;