├── .envrc ├── .gitattributes ├── .github ├── README.md └── workflows │ ├── code.yaml │ └── publish.yaml ├── .gitignore ├── .vscode ├── extensions.json └── settings.json ├── .zed └── settings.json ├── LICENSE ├── en ├── blog.md ├── blog │ └── replacing-docker-compose.md ├── buildRustPackage.md ├── cache.md ├── configuration-as-flake.md ├── dev.md ├── direnv.md ├── drv.md ├── event.md ├── event.yaml ├── event │ ├── nix-dev-home.md │ ├── services-flake-meetup.md │ └── srid-nix-dev.md ├── flake-parts.md ├── flake-url.md ├── flakes.md ├── git.md ├── gotchas.md ├── gotchas │ ├── macos-upgrade.md │ ├── nested-devshells.md │ ├── new-file.md │ └── sqlite-corruption.md ├── haskell-rust-ffi.md ├── haskell.md ├── hm-tutorial.md ├── home-manager.md ├── howto.md ├── howto │ ├── git-profiles.md │ ├── hm-fonts.md │ ├── local-flake-input.md │ ├── nix-package.md │ ├── remote-cp.md │ └── uninstall-nix.md ├── ifd.md ├── index.md ├── index.yaml ├── install.md ├── jobs.md ├── macos.md ├── modules.md ├── nix-darwin.md ├── nix-first.md ├── nix-modules.md ├── nix-rapid.md ├── nix-tutorial.md ├── nix.md ├── nixify-haskell-flake.md ├── nixify-haskell-nixpkgs.md ├── nixify-haskell-parts.md ├── nixify-haskell.md ├── nixify-services-flake.md ├── nixos-install-disko.md ├── nixos-install-flake.md ├── nixos-install-oneclick.md ├── nixos-tutorial.md ├── nixos.md ├── nixpkgs.md ├── process-compose-flake.md ├── registry.md ├── repl.md ├── rust.md ├── services-flake.md ├── shell.md ├── store-path.md ├── store.md ├── topics.md ├── traceVerbose.md ├── treefmt.md ├── tutorial.md ├── vscode.md ├── why-dev.md └── writeShellApplication.md ├── flake.lock ├── flake.nix ├── fr ├── index.md └── index.yaml ├── global ├── blog │ └── replacing-docker-compose │ │ ├── docker-to-nix.png │ │ └── ny-services-flake.png ├── event │ ├── nix-dev-home │ │ └── screenshot.png │ ├── services-flake-meetup │ │ └── screenshot.png │ └── srid-nix-dev │ │ └── vscode-haskell-template.png ├── haskell-rust-ffi │ ├── haskell-rust-ffi-banner.png │ ├── hs │ │ ├── Main.hs │ │ └── default.nix │ └── lib.rs ├── index.yaml ├── nix-modules │ ├── 1 │ │ ├── flake.lock │ │ └── flake.nix │ ├── 2 │ │ ├── flake.lock │ │ └── flake.nix │ ├── 3 │ │ ├── flake.lock │ │ ├── flake.nix │ │ └── lsd.nix │ ├── 4 │ │ ├── flake.lock │ │ ├── flake.nix │ │ └── lsd.nix │ └── 5 │ │ ├── flake.lock │ │ └── flake.nix ├── nix-tutorial │ ├── nix-first.png │ ├── nix-modules.png │ └── nix-rapid.png ├── nixos-install-disko │ ├── nixos-configuration-nix-with-disko-config.jpeg │ ├── nixos-disko-config.jpeg │ ├── nixos-disko-filesystems.jpeg │ ├── nixos-disko-post-partition.jpeg │ ├── nixos-flake-with-disko.jpeg │ ├── nixos-installer-cli.jpeg │ └── nixos-lsblk.jpeg ├── nixos-install-flake │ ├── nixos-install-flake.png │ ├── nixos-installer.png │ ├── nixos-pony.png │ ├── nixos-rebuild-switch-flake.png │ └── nixos-rebuild-switch.png ├── nixos-install-oneclick │ ├── disk-config.nix │ ├── flake.lock │ └── flake.nix ├── static │ ├── nixos-asia.png │ └── nixos-asia.svg └── templates │ ├── filters │ └── query-timeline.tpl │ └── hooks │ └── after-note.tpl ├── justfile └── om.yaml /.envrc: -------------------------------------------------------------------------------- 1 | source_url https://raw.githubusercontent.com/juspay/omnix/75ed48923835963e2f18baba08f54a8adc307ba2/omnixrc "sha256-8C2Jb5bHx/0cvm1+9gOlBEdWzbikCWT5UsJWewUAFt4=" 2 | watch_file om.yaml 3 | use omnix 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.md linguist-detectable 2 | *.md linguist-language=Markdown 3 | *.md linguist-documentation=false 4 | *.md text 5 | flake.lock linguist-generated=true 6 | *.tpl linguist-language=HTML 7 | -------------------------------------------------------------------------------- /.github/README.md: -------------------------------------------------------------------------------- 1 | # nixos.asia website 2 | 3 | This website is built using [Emanote](https://emanote.srid.ca/). 4 | 5 | To run the English site locally with live preview, 6 | 7 | ```sh 8 | nix run .#en # Or just: nix run 9 | ``` 10 | 11 | ## Goals 12 | 13 | On nixos.asia website, we will host our Nix weblog as well as wiki'esque content. Everyone is welcome to contribute content! 14 | 15 | ## How to edit 16 | 17 | Contents are stored in Markdown and can be edited using your favourite [text editor](https://emanote.srid.ca/start/resources/editors) (this repo comes with VSCode settings and extensions). Anyone with a GitHub account can edit this website by clicking the edit icon at the bottom of any page and thereby creating a pull request. 18 | 19 | ### Guidelines 20 | 21 | - When linking to a concept, see if there is an existing page for it. For eg., if you are linking to "nix flakes", use the wikilink `[[flakes]]` since the website already has a page, `flakes.md` for it. If there isn't one, you usually want to create such an [atomic](https://neuron.zettel.page/atomic) note for it. 22 | - Create parent-child ([folgezettel](https://neuron.zettel.page/folgezettel)) relationships as appropriate by using `#[[..]]` style of wikilinks such as to shape the [uplink tree](https://emanote.srid.ca/guide/html-template/uptree) of any page. 23 | 24 | ### PR guidelines 25 | 26 | To assist the reviewer, use `nix run github:nixos-asia/website/branch#preview` in the PR description to provide a handy command for previewing the changes in the PR. See example: https://github.com/nixos-asia/website/pull/12 27 | 28 | 29 | ### Content organization 30 | 31 | This site is made of multiple Emanote layers: 32 | 33 | - `./global`: Static files and HTML temlpates (common to all languages) 34 | - If a note uses images, you should put them here. 35 | - Language-specific content: 36 | - `./en`: English content 37 | - `./fr`: French content[^fr] 38 | 39 | [^fr]: This is just a placeholder. See https://github.com/nixos-asia/website/issues/18 40 | 41 | 42 | ## Discussion 43 | 44 | We hang out in [Zulip](https://nixos.zulipchat.com/) ― come say hi. 45 | -------------------------------------------------------------------------------- /.github/workflows/code.yaml: -------------------------------------------------------------------------------- 1 | name: "Code" 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | jobs: 8 | code: 9 | runs-on: aarch64-darwin 10 | steps: 11 | - uses: actions/checkout@v4 12 | - run: om ci 13 | -------------------------------------------------------------------------------- /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | name: "Build & Publish" 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | jobs: 8 | emanote: 9 | runs-on: x86_64-linux 10 | steps: 11 | - uses: actions/checkout@v4 12 | - name: Build the website (Nix) 🔧 13 | run: | 14 | nix build 15 | - name: Deploy to gh-pages 🚀 16 | uses: peaceiris/actions-gh-pages@v4 17 | if: github.ref == 'refs/heads/master' 18 | with: 19 | github_token: ${{ secrets.GITHUB_TOKEN }} 20 | publish_dir: ./result/ 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .direnv 2 | /result 3 | /.obsidian 4 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "yzhang.markdown-all-in-one", 6 | "svsool.markdown-memo", 7 | "bierner.markdown-checkbox", 8 | "houkanshan.vscode-markdown-footnote", 9 | "mdickin.markdown-shortcuts", 10 | "mushan.vscode-paste-image", 11 | "sean10.markless-sean10", 12 | "gruntfuggly.todo-tree", 13 | "bbenoist.nix" 14 | ] 15 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // Avoid having to explicitly save notes 3 | "files.autoSave": "afterDelay", 4 | // Minimap is not useful for Markdown notes 5 | "editor.minimap.enabled": false, 6 | // Generally note files are not opened in duplicate tabs. 7 | // This also enables you to navigate to already open note in other split pane 8 | "workbench.editor.revealIfOpen": true, 9 | // For those that use daily notes, via vscode-memo extension 10 | "autoSnippet.snippets": [ 11 | { 12 | "pattern": "**/\\d{4}-\\d{2}-\\d{2}.md", 13 | // To specify the body of this snippet, see 14 | // https://github.com/Microsoft/vscode/issues/8102#issuecomment-423476360 15 | "snippet": "daily", 16 | } 17 | ], 18 | "editor.formatOnSave": true, 19 | "editor.wordWrap": "on", 20 | "files.autoSaveDelay": 500, 21 | "files.associations": { 22 | "*.tpl": "html" 23 | }, 24 | "pasteImage.insertPattern": "![[${imageFilePath}]]", 25 | "search.exclude": { 26 | ".direnv": true 27 | } 28 | // If use Git, these might be interesting: 29 | // "git.autofetch": true, 30 | // "git.postCommitCommand": "push" 31 | } -------------------------------------------------------------------------------- /.zed/settings.json: -------------------------------------------------------------------------------- 1 | // Folder-specific settings 2 | // 3 | // For a full list of overridable settings, and general information on folder-specific settings, 4 | // see the documentation: https://zed.dev/docs/configuring-zed#settings-files 5 | { 6 | "soft_wrap": "editor_width" 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023 NixOS Asia. 2 | Permission is granted to copy, distribute and/or modify this document 3 | under the terms of the GNU Free Documentation License, Version 1.3 4 | or any later version published by the Free Software Foundation; 5 | with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. 6 | A copy of the license is included in the section entitled "GNU 7 | Free Documentation License". -------------------------------------------------------------------------------- /en/blog.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: -50 3 | feed: 4 | enable: true 5 | title: NixOS Asia Blog 6 | --- 7 | 8 | # Blog 9 | 10 | ```query {.timeline} 11 | path:./* 12 | ``` 13 | -------------------------------------------------------------------------------- /en/blog/replacing-docker-compose.md: -------------------------------------------------------------------------------- 1 | --- 2 | author: shivaraj 3 | date: 2023-03-05 4 | page: 5 | image: blog/replacing-docker-compose/docker-to-nix.png 6 | --- 7 | 8 | # Replacing docker-compose with Nix for development 9 | 10 | Ever since I first started using [[nix|Nix]] for #[[dev|development]], I have enjoyed the [[why-dev|simplicity of setup]]: `nix develop`, make the code change and see it work. That's all well and good, but when your project keeps growing, you need to depend on external services like databases, message brokers, etc. And then, a quick search will tell you that [docker](https://www.docker.com/) is the way to go. You include it, [add one more step](https://github.com/nammayatri/nammayatri/tree/f056bb994fbf9adefa454319032ca35c34ea65bc/Backend#other-tools) in the setup guide, increasing the barrier to entry for new contributors. Not to mention, eating up all the system resources[^native-macos] on my not so powerful, company-provided MacBook. 11 | 12 | This, along with the fact that we can provide one command to do more than just running external services (more about this at the end of the post), made us want to replace [docker-compose](https://docs.docker.com/compose/) with Nix in [Nammayatri](https://github.com/nammayatri/nammayatri) (Form now on, I'll use 'NY' as the reference for it). 13 | 14 | > [!note] Nammayatri 15 | > [NY](https://nammayatri.in) is an open-source auto rickshaw booking platform, based in India. 16 | 17 | ![[docker-to-nix.png]] 18 | 19 | [^native-macos]: The high resource consumption is due to docker running the containers on a VM, there is an [initiative to run containers natively on macOS](https://github.com/macOScontainers/homebrew-formula), but it is still in alpha and [requires a lot of additional steps](https://github.com/macOScontainers/homebrew-formula?tab=readme-ov-file#installation) to setup. One such step is [disabling SIP](https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection#3599244), which a lot of company monitored devices might not be allowed to do. 20 | 21 | {#what-does-it-take} 22 | 23 | ## What does it take? 24 | 25 | Turns out, there is not a lot of things that we need to do: we need to be able to run services natively, across platforms (so that my MacBook doesn't drain its battery running a database), and integrate with the existing [flake.nix](https://github.com/nammayatri/nammayatri/blob/main/flake.nix) (to avoid an extra step in the setup guide). 26 | 27 | If you've ever used [[nixos|NixOS]] before, you might be familiar with the way services are managed. Let's take a quick look at an example to understand if that will help us arrive at a solution for our problem. 28 | 29 | {#nixos-services} 30 | 31 | ## NixOS services 32 | 33 | Running services in [[nixos|NixOS]] is a breeze. For example, [running a PostgreSQL Database](https://nixos.wiki/wiki/PostgreSQL) is as simple as adding one line to your configuration: 34 | 35 | ```nix 36 | { 37 | services.postgresql.enable = true; 38 | } 39 | ``` 40 | 41 | This starts the database natively, with a global data directory, without the need for a container. That's great. What we need, however, is the same simplicity but with a project-specific data directory, applicable to macOS and other Linux distributions. 42 | 43 | {#nixos-like-services} 44 | 45 | ## Cross-platform NixOS-like services 46 | 47 | In the last section, we saw how easy it is to run services in [[nixos|NixOS]]. We are looking for something similar for our development environment that runs across platforms. Additionally, the solution should: 48 | 49 | - Allow for running multiple instances of the same service (NY uses multiple instances of PostgreSQL and Redis). 50 | - Ensure that services and their data are project-specific. 51 | 52 | These were the exact problems #[[services-flake]] was designed to solve. Along with running services natively, it also [integrates with your project's `flake.nix`](https://community.flake.parts/services-flake/start). 53 | 54 | {#services-flake} 55 | 56 | ## services-flake 57 | 58 | How does [[services-flake]] solve them? 59 | 60 | - It uses [[flake-parts]] for the [[modules|module system]] (that's the simplicity aspect), and [[process-compose-flake]] for managing services, along with providing a TUI app to monitor them. 61 | - To address the need for running multiple instances, services-flake exports a [`multiService` library function](https://github.com/juspay/services-flake/blob/e0a1074f8adb68c06b847d34b260454a18c0697c/nix/lib.nix#L7-L33). 62 | - By default, the data of each service is stored under `./data/`, where `./` refers to the path where the process-compose app, exported by the project [[flakes|flake]] is run (usually in the project root). 63 | 64 | {#start} 65 | 66 | ## Let's get started 67 | 68 | Now that we have all the answers, it's time to replace [docker-compose in NY](https://github.com/nammayatri/nammayatri/blob/f056bb994fbf9adefa454319032ca35c34ea65bc/Backend/nix/arion-configuration.nix) with [[services-flake]]. We will only focus on a few services to keep it simple; for more details, refer to the [PR](https://github.com/nammayatri/nammayatri/pull/3718). 69 | 70 | :::{.center} 71 | ![[ny-services-flake.png]] 72 | ::: 73 | 74 | {#postgresql} 75 | 76 | ### PostgreSQL 77 | 78 | NY uses about 3 instances of PostgreSQL databases. 79 | 80 | One of them is [exported by passetto](https://github.com/nammayatri/passetto/blob/nixify/process-compose.nix) (passetto is a Haskell application that encrypts data before storing it in postgres), and using it looks like: 81 | 82 | ```nix 83 | { 84 | services.passetto.enable = true; 85 | } 86 | ``` 87 | 88 | By leveraging the [[modules|module system]], we can hide the implementation details and only expose the `passetto` service to the user, enabling its use as shown above. 89 | 90 | The other two instances are configured by the [postgres-with-replica module](https://github.com/nammayatri/nammayatri/blob/ccab8da607cfd8d4e9f7d28b55b83e22eec1af9b/Backend/nix/services/postgres-with-replica.nix). This module starts two services (`primary` and `replica` databases) and a [pg-basebackup](https://www.postgresql.org/docs/current/app-pgbasebackup.html) process (to synchronize `replica` with `primary` during initialization). For the user, it appears as follows: 91 | 92 | ```nix 93 | { 94 | services.postgres-with-replica.enable = true; 95 | } 96 | ``` 97 | 98 | {#redis} 99 | 100 | ### Redis 101 | 102 | NY uses [Redis](https://redis.io/) as a cache and clustered version of it as a key-value database. Redis service comprises a single node, while the clustered version has 6 nodes (3 masters and 3 replicas). Adding them to the project is as simple as: 103 | 104 | ```nix 105 | { 106 | services.redis.enable = true; 107 | services.redis-cluster.enable = true; 108 | } 109 | ``` 110 | 111 | {#cool-things} 112 | 113 | ## Cool things 114 | 115 | By no longer depending on Docker, we can now run the entire NY backend with one command, and it's all defined in a [single place](https://github.com/nammayatri/nammayatri/blob/ccab8da607cfd8d4e9f7d28b55b83e22eec1af9b/Backend/nix/services/nammayatri.nix). 116 | 117 | That's not all; we can also share the NY backend module to do much more, such as defining [load-test](https://github.com/nammayatri/nammayatri/blob/ccab8da607cfd8d4e9f7d28b55b83e22eec1af9b/Backend/load-test/default.nix) configurations and running them in CI/local environments, again, with just one command. In this case, we take the module to run the entire NY stack and then extend it to add a bunch of load-test processes before bringing the whole thing to an end (as the load-test ends). 118 | 119 | This is what running them looks like: 120 | 121 | ```sh 122 | # Run load-test 123 | nix run github:nammayatri/nammayatri#load-test-dev 124 | 125 | # Run the entire backend 126 | nix run github:nammayatri/nammayatri#run-mobility-stack-nix 127 | ``` 128 | 129 | {#next} 130 | ## Up next 131 | 132 | Sharing [[services-flake]] modules deserves a separate post, so we will delve into this topic more in the next post. 133 | -------------------------------------------------------------------------------- /en/buildRustPackage.md: -------------------------------------------------------------------------------- 1 | # `buildRustPackage` 2 | 3 | See official documentation on this function [here](https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md). 4 | 5 | {#override} 6 | ## Overriding Rust derivation 7 | 8 | Due to the complexity of `buildRustPackage` you cannot *merely* use `overrideAttrs` to override a Rust derivation. For version changes in particular, you must also override the `cargoDeps` attribute ([see here](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/3)). 9 | 10 | For example, to override `pkgs.just` to [a later release][just-zulip], 11 | 12 | 13 | ```nix 14 | self: super: { 15 | just = super.just.overrideAttrs (oa: rec { 16 | name = "${oa.pname}-${version}"; 17 | version = "1.27.0"; 18 | src = super.fetchFromGitHub { 19 | owner = "casey"; 20 | repo = oa.pname; 21 | rev = "refs/tags/${version}"; 22 | hash = "sha256-xyiIAw8PGMgYPtnnzSExcOgwG64HqC9TbBMTKQVG97k="; 23 | }; 24 | # Overriding `cargoHash` has no effect; we must override the resultant 25 | # `cargoDeps` and set the hash in its `outputHash` attribute. 26 | cargoDeps = oa.cargoDeps.overrideAttrs (super.lib.const { 27 | name = "${name}-vendor.tar.gz"; 28 | inherit src; 29 | outputHash = "sha256-jMurOCr9On+sudgCzIBrPHF+6jCE/6dj5E106cAL2qw="; 30 | }); 31 | 32 | doCheck = false; 33 | }); 34 | } 35 | ``` 36 | 37 | 38 | [just-zulip]: https://nixos.zulipchat.com/#narrow/stream/420166-offtopic/topic/just.20recipe.20grouping/near/440732100 -------------------------------------------------------------------------------- /en/cache.md: -------------------------------------------------------------------------------- 1 | # Binary Cache 2 | 3 | A binary cache provides cached binaries of built #[[nix]] [[drv]]. 4 | 5 | https://nixos.wiki/wiki/Binary_Cache 6 | 7 | https://zero-to-nix.com/concepts/caching 8 | -------------------------------------------------------------------------------- /en/configuration-as-flake.md: -------------------------------------------------------------------------------- 1 | # Convert `configuration.nix` to be a flake 2 | 3 | A problem with the default NixOS `configuration.nix` generated by the official installer is that it is not "pure" and thus not reproducible (see [here](https://www.tweag.io/blog/2020-07-31-nixos-flakes/#what-problems-are-we-trying-to-solve)), as it still uses a mutable Nix channel (which is generally [discouraged](https://zero-to-nix.com/concepts/channels#the-problem-with-nix-channel)). For this reason (among others), it is recommended to immediately switch to using #[[flakes]] for our NixOS configuration. Doing this is pretty simple. Just add a `flake.nix` file in `/etc/nixos`: 4 | 5 | ```sh 6 | sudo nvim /etc/nixos/flake.nix 7 | ``` 8 | 9 | Add the following: 10 | 11 | ```nix 12 | # /etc/nixos/flake.nix 13 | { 14 | inputs = { 15 | # NOTE: Replace "nixos-23.11" with that which is in system.stateVersion of 16 | # configuration.nix. You can also use latter versions if you wish to 17 | # upgrade. 18 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; 19 | }; 20 | outputs = inputs@{ self, nixpkgs, ... }: { 21 | # NOTE: 'nixos' is the default hostname set by the installer 22 | nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { 23 | # NOTE: Change this to aarch64-linux if you are on ARM 24 | system = "x86_64-linux"; 25 | modules = [ ./configuration.nix ]; 26 | }; 27 | }; 28 | } 29 | ``` 30 | 31 | > [!note] Make sure to change a couple of things in the above snippet: 32 | > - Replace `nixos-23.11` with the version from [`system.stateVersion`](https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion) in your `/etc/nixos/configuration.nix`. If you wish to upgrade right away, you can also use latter versions, or use `nixos-unstable` for the bleeding edge. 33 | > - `x86_64-linux` should be `aarch64-linux` if you are on ARM 34 | 35 | Now, `/etc/nixos` is technically a [[flakes|flake]]. We can "inspect" this flake using the `nix flake show` command: 36 | 37 | ```sh 38 | $ nix flake show /etc/nixos 39 | error: experimental Nix feature 'nix-command' is disabled; use '--extra-experimental-features nix-command' to override 40 | ``` 41 | 42 | Oops, what happened here? As flakes is a so-called "experimental" feature, you must manually enable it. We'll _temporarily_ enable it for now, and then enable it _permanently_ latter. The `--extra-experimental-features` flag can be used to enable experimental features. Let's try again: 43 | 44 | ```sh 45 | $ nix --extra-experimental-features 'nix-command flakes' flake show /etc/nixos 46 | warning: creating lock file '/etc/nixos/flake.lock' 47 | error: 48 | … while updating the lock file of flake 'path:/etc/nixos?lastModified=1702156351&narHash=sha256-km4AQoP/ha066o7tALAzk4tV0HEE%2BNyd9SD%2BkxcoJDY%3D' 49 | 50 | error: opening file '/etc/nixos/flake.lock': Permission denied 51 | ``` 52 | 53 | Progress, but we hit another error---Nix understandably cannot write to root-owned directory (it tries to create the `flake.lock` file). One way to resolve this is to move the whole configuration to our home directory, which would also prepare the ground for storing it in [[git]]. We will do this in the next section. 54 | 55 | > [!info] `flake.lock` 56 | > Nix commands automatically generate a (or update the) `flake.lock` file. This file contains the exacted pinned version of the inputs of the flake, which is important for reproducibility. 57 | 58 | {#homedir} 59 | ## Move configuration to user directory 60 | 61 | Move the entire `/etc/nixos` directory to your home directory and gain control of it: 62 | 63 | ```sh 64 | $ sudo mv /etc/nixos ~/nixos-config && sudo chown -R $USER ~/nixos-config 65 | ``` 66 | 67 | Your configuration directory should now look like: 68 | 69 | ```sh 70 | $ ls -l ~/nixos-config/ 71 | total 12 72 | -rw-r--r-- 1 srid root 4001 Dec 9 16:03 configuration.nix 73 | -rw-r--r-- 1 srid root 224 Dec 9 16:12 flake.nix 74 | -rw-r--r-- 1 srid root 1317 Dec 9 15:43 hardware-configuration.nix 75 | ``` 76 | 77 | Now let's try `nix flake show` on it, and this time it should work: 78 | 79 | ```sh 80 | $ cd ~/nixos-config 81 | $ nix --extra-experimental-features 'nix-command flakes' flake show 82 | warning: creating lock file '/home/srid/nixos-config/flake.lock' 83 | path:/home/srid/nixos-config?lastModified=1702156518&narHash=sha256-nDtDyzk3fMfABicFuwqWitIkyUUw8BZ4SniPPyJNKjw%3D 84 | └───nixosConfigurations 85 | └───nixos: NixOS configuration 86 | ``` 87 | 88 | Voila! Incidentally, this flake has a single output, `nixosConfigurations.nixos`, which is the NixOS configuration itself. 89 | 90 | >[!info] More on Flakes 91 | > See [[nix-rapid]] for more information on flakes. 92 | 93 | Once flake-ified, we can use the same command to activate the new configuration but we must additionally pass the `--flake` flag, viz.: 94 | 95 | ```sh 96 | # The '.' is the path to the flake, which is current directory. 97 | $ sudo nixos-rebuild switch --flake . 98 | ``` 99 | 100 | If everything went well, you should see something like this: 101 | 102 | :::{.center} 103 | ![[nixos-rebuild-switch-flake.png]] 104 | ::: 105 | 106 | Excellent, now we have a flake-ified NixOS configuration that is pure and reproducible! -------------------------------------------------------------------------------- /en/dev.md: -------------------------------------------------------------------------------- 1 | # Nix for Development 2 | 3 | While package management is the key purpose of #[[nix]], its [[drv|derivations]] can also be used to produce non-package types, such as development environments (aka. "devShell"). 4 | 5 | ![[why-dev]] 6 | 7 | ## Language support 8 | 9 | - [[haskell]]# 10 | - [[rust]]# 11 | 12 | ## Tools 13 | 14 | - [[direnv]]# -------------------------------------------------------------------------------- /en/direnv.md: -------------------------------------------------------------------------------- 1 | # `direnv`: manage dev environments 2 | 3 | `direnv` (along with [nix-direnv]) allows one to persist[^gc] nix #[[dev|development]] [[shell|shell]] environments and share them seamlessly with text editors and IDEs. It obviates having to run `nix develop` manually every time you open a new terminal. The moment you `cd` into your project directory, the devshell is automatically activated, thanks to `direnv`. 4 | 5 | [^gc]: [nix-direnv] prevents garbage collection of the devshell, so you do not have to re-download things again. direnv also enables activating the devshell in your current shell, without needing to use a customized bash. 6 | 7 | >[!tip] Starship 8 | > It is recommended to use [**starship**](https://starship.rs/) along with nix-direnv, because it gives a visual indication of the current environment. For example, if you are in a [[shell]], your terminal prompt automatically changes to something like this: 9 | > 10 | > ```sh 11 | > srid on nixos haskell-template on  master [!] via λ 9.2.6 via ❄️ impure (ghc-shell-for-haskell-template-0.1.0.0-0-env) 12 | > ❯ 13 | > ``` 14 | 15 | ## Setup 16 | 17 | :::{class="flex items-center justify-center mb-8"} 18 | 19 | ::: 20 | 21 | 22 | 23 | 24 | If you use [[home-manager]], both `nix-direnv` and `starship` can be installed using the following configuration: 25 | 26 | ```nix 27 | # home.nix 28 | programs.direnv = { 29 | enable = true; 30 | nix-direnv.enable = true; 31 | }; 32 | programs.starship = { 33 | enable = true; 34 | }; 35 | ``` 36 | 37 | >[!tip] Newcomer Tip 38 | > If you have never used [[home-manager]] before, we recommend that you set it up by following the instrutions at https://github.com/juspay/nixos-unified-template (which is based on [nixos-unified](https://nixos-unified.org/), thus works on macOS and Linux). 39 | 40 | 41 | ### Text Editor configuration 42 | 43 | #### VSCode 44 | 45 | For VSCode, use [Martin Kühl's direnv extension](https://marketplace.visualstudio.com/items?itemName=mkhl.direnv). 46 | 47 | #### Doom Emacs 48 | 49 | Doom Emacs has the [`:tools` `direnv` module](https://github.com/doomemacs/doomemacs/tree/master/modules/tools/direnv) to automatically load the devshell environment when you open the project directory. 50 | 51 | ## Add a `.envrc` 52 | 53 | To enable direnv on Flake-based projects, add the following to your `.envrc`: 54 | 55 | ```text title=".envrc" 56 | use flake 57 | ``` 58 | 59 | Now run `direnv allow` to authorize the current `.envrc` file. You can now `cd` into the project directory in a terminal and the devshell will be automatically activated. 60 | 61 | ### Reload automatically when some files change 62 | 63 | #### [[haskell]] - when `.cabal` files change 64 | 65 | Since both [[nixify-haskell-nixpkgs|nixpkgs]] and [haskell-flake](https://community.flake.parts/haskell-flake) use Nix expressions that read the `.cabal` file to get dependency information, you will want the devshell be recreated every time a `.cabal` file changes. This can be achieved using the `watch_file` function. Modify your `.envrc` to contain: 66 | 67 | ```text title=".envrc" 68 | watch_file *.cabal 69 | use flake 70 | ``` 71 | 72 | As a result of this whenever you change a `.cabal` file, direnv will reload the environment. If you are using VSCode, you will see a notification that the environment has changed, prompting you to restart it ([see example](https://github.com/nammayatri/nammayatri/tree/main/Backend#visual-studio-code)). 73 | 74 | ## External Links 75 | 76 | - [Effortless dev environments with Nix and direnv](https://determinate.systems/posts/nix-direnv) 77 | 78 | [nix-direnv]: https://github.com/nix-community/nix-direnv 79 | [home-manager]: https://github.com/nix-community/home-manager 80 | -------------------------------------------------------------------------------- /en/drv.md: -------------------------------------------------------------------------------- 1 | # Derivation 2 | 3 | #[[nix]] derivations are instructions (recipes) for building a Nix package. 4 | 5 | ## Links 6 | 7 | - https://zero-to-nix.com/concepts/derivations -------------------------------------------------------------------------------- /en/event.md: -------------------------------------------------------------------------------- 1 | # Events 2 | 3 | We host events to bring together the community. Our primary venue is in [Bangalore]. 4 | 5 | ## Upcoming events 6 | 7 | ```query {.timeline} 8 | children:. 9 | ``` 10 | 11 | 12 | [Bangalore]: https://en.wikipedia.org/wiki/Bangalore 13 | -------------------------------------------------------------------------------- /en/event.yaml: -------------------------------------------------------------------------------- 1 | template: 2 | sidebar: 3 | enable: false 4 | toc: 5 | enable: false 6 | uptree: 7 | enable: true 8 | breadcrumbs: 9 | enable: true 10 | base: 11 | containerClass: container mx-auto max-w-prose 12 | -------------------------------------------------------------------------------- /en/event/nix-dev-home.md: -------------------------------------------------------------------------------- 1 | --- 2 | date: 2023-03-05 3 | author: srid 4 | page: 5 | image: event/nix-dev-home/screenshot.png 6 | --- 7 | 8 | # Using `home-manager` to manage dotfiles, packages, services 9 | 10 | :::{.center} 11 | | When | Where | 12 | | ----------------------------------------------------- | ------------------------------------------------- | 13 | | Tuesday, March 5, 2025 at 4:30PM | [Online Meetup][hasgeek] | 14 | ::: 15 | 16 | [Sridhar Ratnakumar][srid] will demonstrate using [[nix|Nix]] to declaratively manage your **dotfiles, programs and services** using [[home-manager|home-manager]], thus replacing the likes of legacy software like homebrew. The goal is to create an **one-click environment** to setup an user environment on any system, be it a Macbook or a Linux machine. 17 | 18 | Among the various examples, we will showcase how to configure Neovim declaratively in Nix, and have it work across platforms. In addition, we will show how to use [[direnv|direnv]] to develop projects uniformly across different machines. 19 | 20 | RSVP links: 21 | 22 | - [Functional Programming India][hasgeek] 23 | 24 | See also: 25 | 26 | - [Juspay's home-manager template](https://github.com/juspay/nix-dev-home) 27 | 28 | ![[nix-dev-home/screenshot.png]] 29 | 30 | [srid]: https://x.com/sridca 31 | 32 | [hasgeek]: https://hasgeek.com/fpindia/nixos-asia-home-manager/ 33 | -------------------------------------------------------------------------------- /en/event/services-flake-meetup.md: -------------------------------------------------------------------------------- 1 | --- 2 | date: 2025-01-04 3 | author: shivaraj-bh 4 | page: 5 | image: event/services-flake-meetup/screenshot.png 6 | --- 7 | 8 | # services-flake: Services simplified for Dev/CI workflows 9 | 10 | :::{.center} 11 | | When | Where | 12 | | ----------------------------------------------------- | ------------------------------------------------- | 13 | | Saturday, Jan 4, 2025 at 5 PM IST | [Online meetup][jitsi] | 14 | ::: 15 | 16 | [Shivaraj B H][shivaraj-bh] will demonstrate using [[services-flake]] to declaratively manage service dependencies (for example, databases) of your project in the [[nix|Nix]] development environment and re-use the same configuration for testing in your CI workflow. This talk builds upon [my lightning talk from NixCon 2024][nixcon-talk], diving deeper into the topic with additional insights. 17 | 18 | The talk serves as a video demonstration of the **Part-4** in the [[nixify-haskell]] series. 19 | 20 | RSVP links: 21 | 22 | - [Functional Programming India][hasgeek] 23 | 24 | See also: 25 | 26 | - [FP India Advent 2025](https://functionalprogramming.in/advent/2025.html) 27 | 28 | ![[services-flake-meetup/screenshot.png]] 29 | 30 | [jitsi]: https://meet.jit.si/services-flake 31 | 32 | [hasgeek]: https://hasgeek.com/fpindia/shivaraj-talks-about-about-nix-service-flake/ 33 | 34 | [shivaraj-bh]: https://x.com/shivaraj_bh_ 35 | 36 | [nixcon-talk]: https://talks.nixcon.org/nixcon-2024/talk/review/UTZQ8YZHKSMTUPRSC83TKALDUYNL9BCX 37 | 38 | -------------------------------------------------------------------------------- /en/event/srid-nix-dev.md: -------------------------------------------------------------------------------- 1 | --- 2 | date: 2023-01-23 3 | author: srid 4 | page: 5 | image: event/srid-nix-dev/vscode-haskell-template.png 6 | --- 7 | 8 | # Getting Started with Nix for Haskell & Rust 9 | 10 | :::{.center} 11 | | When | Where | 12 | | -------------------------------- | ------------------------------------------------- | 13 | | Tuesday, January 23, 2024 at 4PM | [IndiQube Garden, Bengaluru][map-indiqube-garden] | 14 | ::: 15 | 16 | [Sridhar Ratnakumar][srid] will demonstrate the delights of using [[nix|Nix]] to [[dev|develop]] [[rust|Rust]] as well as [[haskell|Haskell]] projects without needing to do any manual global setup on your system. We'll start from a pristine [[macos|macOS]] machine as well as a pristine Linux machine to get our [[dev|development environment]] up and running in no time, all the way up to [LSP] support in [[vscode|VSCode]]. 17 | 18 | RSVP links: 19 | 20 | - [The Bangalore Haskell User Group](https://www.meetup.com/the-bangalore-haskell-user-group/events/298349003) 21 | 22 | ![[vscode-haskell-template.png]] 23 | 24 | [srid]: https://x.com/sridca 25 | [map-indiqube-garden]: https://www.google.com/maps/place/12%C2%B056'12.0%22N+77%C2%B037'17.5%22E/@12.936661,77.62153,17z/data=!3m1!4b1!4m4!3m3!8m2!3d12.936661!4d77.62153?entry=ttu 26 | [LSP]: https://langserver.org/ 27 | -------------------------------------------------------------------------------- /en/flake-parts.md: -------------------------------------------------------------------------------- 1 | 2 | # flake-parts 3 | 4 | `flake-parts` brings the #[[modules|NixOS module system]] to #[[flakes|flakes]], thus providing a cleaner and simpler way to write otherwise complex flakes. 5 | 6 | - Official site: https://flake.parts/ 7 | - Module documentation: https://community.flake.parts/ 8 | -------------------------------------------------------------------------------- /en/flake-url.md: -------------------------------------------------------------------------------- 1 | 2 | # Flake URL 3 | 4 | A #[[flakes|flake]] can be referred to using an URL-like syntax. 5 | 6 | ## Examples 7 | 8 | ```sh 9 | # A flake on a GitHub repo 10 | github:srid/emanote 11 | 12 | # A local flake at current directory 13 | . 14 | 15 | # Another way to refer to local flakes 16 | path:/Users/srid/code/foo 17 | 18 | # Full Git references is also possible: 19 | git+https://github.com/juspay/services-flake?ref=dev 20 | ``` 21 | 22 | ## Reference 23 | 24 | - The URL-like syntax is documented [here](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#url-like-syntax). 25 | -------------------------------------------------------------------------------- /en/flakes.md: -------------------------------------------------------------------------------- 1 | 2 | # Flakes 3 | 4 | Flakes is a necessary abstraction of top of #[[nix]] that improves on usability and reproducibility. Flakes is [production ready despite being marked as experimental](https://determinate.systems/posts/experimental-does-not-mean-unstable). 5 | 6 | ```query 7 | children:. 8 | ``` 9 | 10 | ## Links 11 | 12 | - https://nixos.wiki/wiki/Flakes -------------------------------------------------------------------------------- /en/git.md: -------------------------------------------------------------------------------- 1 | # Git 2 | 3 | Git is the most commonly used version control system for #[[dev|software development]]. 4 | 5 | ## Declarative configuration 6 | 7 | Git can be declaratively configured in [[nix]] via [[home-manager]]. [Here is](https://github.com/srid/nixos-config/blob/master/home/git.nix) an example: 8 | 9 | ```nix 10 | { 11 | programs.git = { 12 | enable = true; 13 | userName = "john"; 14 | userEmail = "john@doe.com"; 15 | ignores = [ "*~" "*.swp" ]; 16 | extraConfig = { 17 | init.defaultBranch = "master"; 18 | }; 19 | }; 20 | } 21 | ``` 22 | 23 | ## Git related pages 24 | 25 | ```query 26 | children:. 27 | ``` 28 | -------------------------------------------------------------------------------- /en/gotchas.md: -------------------------------------------------------------------------------- 1 | # Gotchas 2 | 3 | #[[nix]] can behave unexpectedly in certain cases. 4 | 5 | ```query 6 | children:. 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /en/gotchas/macos-upgrade.md: -------------------------------------------------------------------------------- 1 | 2 | # Nix is broken after macOS upgrade 3 | 4 | Upgrading #[[macos]] is known to break [[nix]]. When this happens, just uninstall Nix and then #[[install|install]] it again. 5 | 6 | 1. Uninstall Nix 7 | - Run `/nix/nix-installer uninstall` 8 | - If that path above does not exist, [follow these instructions](https://nixos.org/manual/nix/stable/installation/uninstall.html#macos) to manually uninstall Nix. 9 | 1. Reboot your Mac 10 | 1. [[install]] 11 | 12 | -------------------------------------------------------------------------------- /en/gotchas/nested-devshells.md: -------------------------------------------------------------------------------- 1 | # Nested devShells can cause problems 2 | 3 | cf. 4 | - https://github.com/NixOS/nix/issues/10388 5 | - https://github.com/NixOS/nix/issues/6140 6 | -------------------------------------------------------------------------------- /en/gotchas/new-file.md: -------------------------------------------------------------------------------- 1 | 2 | # Nix does not recognize a new file I added 3 | 4 | Often you'll see an error like this, 5 | 6 | ```text 7 | error: getting status of '/nix/store/vlks3d7fr5ywc923pvqacx2bkzm1782j-source/foo': No such file or directory 8 | ``` 9 | 10 | This usually means you have not staged this new file/ directory to the Git 11 | index. When using #[[flakes]], Nix will not see [untracked] files/ directories by default. To resolve this, just `git add -N` the untracked file/ directory. 12 | 13 | >[!info] For further information 14 | > https://github.com/NixOS/nix/issues/8389 15 | 16 | [untracked]: https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository 17 | -------------------------------------------------------------------------------- /en/gotchas/sqlite-corruption.md: -------------------------------------------------------------------------------- 1 | 2 | # Nix's sqlite database is corrupted/broken 3 | 4 | If [[nix]] throws an error like: 5 | 6 | ```text 7 | error: getting status of '/nix/store/....drv': No such file or directory 8 | ``` 9 | 10 | You can try to fix it by running: 11 | 12 | ```sh 13 | nix-store --verify --repair 14 | ``` -------------------------------------------------------------------------------- /en/haskell-rust-ffi.md: -------------------------------------------------------------------------------- 1 | --- 2 | page: 3 | image: haskell-rust-ffi/haskell-rust-ffi-banner.png 4 | --- 5 | 6 | # Rust FFI in Haskell 7 | 8 | This #[[tutorial|tutorial]] will guide you through using [[nix]] to simplify the workflow of incorporating [[rust]] library as a dependency in your [[haskell]] project via [FFI](https://en.wikipedia.org/wiki/Foreign_function_interface). If you are new to [[nix]] and [[flakes]], we recommend starting with the [[nix-tutorial]]. 9 | 10 | > [!info] Foreign Function Interface (FFI) 11 | > This isn't solely restricted to Haskell and Rust, it can be used between any two languages that can establish a common ground to communicate, such as C. 12 | 13 | The objective of this tutorial is to demonstrate calling a Rust function that returns `Hello, from rust!` from within a Haskell package. Let's begin by setting up the Rust library. 14 | 15 | :::{.center} 16 | ![[haskell-rust-ffi-banner.png]] 17 | ::: 18 | 19 | {#init-rust} 20 | ## Initialize Rust Project 21 | 22 | Start by initializing a new Rust project using [rust-nix-template](https://github.com/srid/rust-nix-template): 23 | 24 | ```sh 25 | git clone https://github.com/srid/rust-nix-template.git 26 | cd rust-nix-template 27 | ``` 28 | 29 | Now, let's run the project: 30 | 31 | ```sh 32 | nix develop 33 | just run 34 | ``` 35 | 36 | {#rust-lib} 37 | ## Create a Rust Library 38 | 39 | The template we've initialized is a binary project, but we need a library project. The library should export a function callable from Haskell. For simplicity, let's export a function named `hello` that returns a `C-style string`. To do so, create a new file named `src/lib.rs` with the following contents and `git add src/lib.rs`: 40 | 41 | [[haskell-rust-ffi/lib.rs]] 42 | ![[haskell-rust-ffi/lib.rs]] 43 | 44 | > [!info] Calling Rust code from C 45 | > You can learn more about it [here](https://doc.rust-lang.org/nomicon/ffi.html#calling-rust-code-from-c). 46 | 47 | Now, the library builds, but we need the dynamic library files required for FFI. To achieve this, let's add a `crate-type` to the `Cargo.toml`: 48 | 49 | ```toml 50 | [lib] 51 | crate-type = ["cdylib"] 52 | ``` 53 | 54 | After running `cargo build`, you should find a `librust_nix_template.dylib`[^hyphens-disallowed] (if you are on macOS) or `librust_nix_template.so` (if you are on Linux) in the `target/debug` directory. 55 | 56 | [^hyphens-disallowed]: Note that the hyphens are disallowed in the library name; hence it's named `librust_nix_template.dylib`. Explicitly setting the name of the library with hyphens will fail while parsing the manifest with: `library target names cannot contain hyphens: rust-nix-template` 57 | 58 | {#init-haskell} 59 | ## Initialize Haskell Project 60 | 61 | Fetch `cabal-install` and `ghc` from the `nixpkgs` in [flake registry](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-registry.html) and initialize a new Haskell project: 62 | 63 | ```sh 64 | nix shell nixpkgs#ghc nixpkgs#cabal-install -c cabal -- init -n --exe -m --simple hello-haskell -d base --overwrite 65 | ``` 66 | 67 | {#nixify-haskell} 68 | ## Nixify Haskell Project 69 | 70 | We will utilize [haskell-flake](https://community.flake.parts/haskell-flake) to nixify the Haskell project. Add the following to `./hello-haskell/default.nix`: 71 | 72 | [[haskell-rust-ffi/hs/default.nix]] 73 | ![[haskell-rust-ffi/hs/default.nix]] 74 | 75 | Additionally, add the following to `flake.nix`: 76 | 77 | ```nix 78 | { 79 | inputs.haskell-flake.url = "github:srid/haskell-flake"; 80 | 81 | outputs = inputs: 82 | # Inside `mkFlake` 83 | { 84 | imports = [ 85 | inputs.haskell-flake.flakeModule 86 | ./hello-haskell 87 | ]; 88 | }; 89 | } 90 | ``` 91 | 92 | Stage the changes: 93 | 94 | ```sh 95 | git add hello-haskell 96 | ``` 97 | 98 | Now, you can run `nix run .#hello-haskell` to build and execute the Haskell project. 99 | 100 | {#merge-devshell} 101 | ## Merge Rust and Haskell Development Environments 102 | 103 | In the previous section, we created `devShells.haskell`. Let's merge it with the Rust development environment in `flake.nix`: 104 | 105 | ```nix 106 | { 107 | # Inside devShells.default 108 | inputsFrom = [ 109 | # ... 110 | self'.devShells.haskell 111 | ]; 112 | } 113 | ``` 114 | 115 | Now, re-enter the shell, and you'll have both Rust and Haskell development environments: 116 | 117 | ```sh 118 | exit 119 | nix develop 120 | cd hello-haskell && cabal build 121 | cd .. && cargo build 122 | ``` 123 | 124 | {#add-rust-lib} 125 | ## Add Rust Library as a Dependency 126 | 127 | Just like any other dependency, you'll first add it to your `hello-haskell/hello-haskell.cabal` file: 128 | 129 | ```text 130 | executable hello-haskell 131 | -- ... 132 | extra-libraries: rust_nix_template 133 | ``` 134 | 135 | Try building it: 136 | 137 | ```sh 138 | cd hello-haskell && cabal build 139 | ``` 140 | 141 | You'll likely encounter an error like this: 142 | 143 | ```sh 144 | ... 145 | * Missing (or bad) C library: rust_nix_template 146 | ... 147 | ``` 148 | 149 | The easiest solution might seem to be `export LIBRARY_PATH=../target/debug`. However, this is not reproducible and would mean running an additional command to setup the prerequisite to build the Haskell package. Even worse if the Rust project is in a different repository. 150 | 151 | Often, the easiest solution isn't the simplest. Let's use Nix to simplify this process. 152 | 153 | When you use Nix, you set up all the prerequisites beforehand, which is why you'll encounter an error when trying to re-enter the devShell without explicitly specifying where the Rust project is: 154 | 155 | ```sh 156 | ... 157 | error: function 'anonymous lambda' called without required argument 'rust_nix_template' 158 | ... 159 | ``` 160 | 161 | To specify the Rust project as a dependency, we [setup haskell-flake dependency overrides](https://community.flake.parts/haskell-flake/dependency) by editing `hello-haskell/default.nix` to: 162 | 163 | ```nix 164 | { 165 | # Inside haskellProjects.default 166 | settings = { 167 | rust_nix_template.custom = _: self'.packages.default; 168 | }; 169 | } 170 | ``` 171 | 172 | This process eliminates the need for manual Rust project building as it's wired as a prerequisite to the Haskell package. 173 | 174 | {#call-rust} 175 | ## Call Rust function from Haskell 176 | 177 | Replace the contents of `hello-haskell/app/Main.hs` with: 178 | 179 | [[haskell-rust-ffi/hs/Main.hs]] 180 | ![[haskell-rust-ffi/hs/Main.hs]] 181 | 182 | The implementation above is based on the [Haskell FFI documentation](https://wiki.haskell.org/Foreign_Function_Interface). Now, run the Haskell project: 183 | 184 | ```sh 185 | nix run .#hello-haskell 186 | ``` 187 | 188 | You should see the output `Hello, from rust!`. 189 | 190 | > [!note] macOS caveat 191 | > If you are on [[macos]], the Haskell package will not run because `dlopen` will be looking for the `.dylib` file in the temporary build directory (`/private/tmp/nix-build-rust-nix...`). To fix this, you need to include [fixDarwinDylibNames](https://github.com/NixOS/nixpkgs/blob/af8fd52e05c81eafcfd4fb9fe7d3553b61472712/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh) in `flake.nix`: 192 | > 193 | >```nix 194 | >{ 195 | > # Inside `perSystem.packages.default` 196 | > # ... 197 | > buildInputs = if pkgs.stdenv.isDarwin then [ pkgs.fixDarwinDylibNames ] else [ ]; 198 | > postInstall = '' 199 | > ${if pkgs.stdenv.isDarwin then "fixDarwinDylibNames" else ""} 200 | > ''; 201 | >} 202 | >``` 203 | 204 | {#cabal-repl} 205 | ## Problems with `cabal repl` 206 | 207 | `cabal repl` doesn't look for `NIX_LDFLAGS` to find the dynamic library, see why [here](https://discourse.nixos.org/t/shared-libraries-error-with-cabal-repl-in-nix-shell/8921/10). This can be worked around in `hello-haskell/default.nix` using: 208 | 209 | ```nix 210 | { 211 | # Inside `devShells.haskell` 212 | shellHook = '' 213 | export LIBRARY_PATH=${config.haskellProjects.default.outputs.finalPackages.rust_nix_template}/lib 214 | ''; 215 | } 216 | ``` 217 | 218 | Re-enter the shell, and you're set: 219 | 220 | ```sh 221 | ❯ cd hello-haskell && cabal repl 222 | Build profile: -w ghc-9.4.8 -O1 223 | In order, the following will be built (use -v for more details): 224 | - hello-haskell-0.1.0.0 (exe:hello-haskell) (ephemeral targets) 225 | Preprocessing executable 'hello-haskell' for hello-haskell-0.1.0.0.. 226 | GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help 227 | [1 of 2] Compiling Main ( app/Main.hs, interpreted ) 228 | Ok, one module loaded. 229 | ghci> main 230 | Hello, from rust! 231 | ``` 232 | 233 | > [!note] What about `ghci`? 234 | > If you use `ghci` you will need to link the library manually: `ghci -lrust_nix_template`. See the [documentation](https://downloads.haskell.org/ghc/latest/docs/users_guide/ghci.html#extra-libraries). 235 | 236 | {#tpl} 237 | ## Template 238 | 239 | You can find the template at . This template also includes formatting setup with [[treefmt|treefmt-nix]] and [[vscode]] integration. 240 | -------------------------------------------------------------------------------- /en/haskell.md: -------------------------------------------------------------------------------- 1 | 2 | # Haskell 3 | 4 | For nixifying Haskell projects, see our tutorial series [[nixify-haskell]] 5 | 6 | For a comprehensive list of ways to nixify Haskell projects, see https://nixos.wiki/wiki/Haskell 7 | 8 | ```query 9 | children:. 10 | ``` 11 | 12 | [haskell-flake]: https://github.com/srid/haskell-flake 13 | -------------------------------------------------------------------------------- /en/hm-tutorial.md: -------------------------------------------------------------------------------- 1 | 2 | # home-manager Tutorial Series 3 | 4 | A tutorial series on #[[home-manager]], 5 | 6 | - [ ] Setting it up using https://github.com/juspay/nixos-unified-template 7 | - [ ] Basics (packages, dotfiles) 8 | - [ ] Services (macOS and Ubuntu) 9 | -------------------------------------------------------------------------------- /en/home-manager.md: -------------------------------------------------------------------------------- 1 | Use #[[nix]] to manage your user environment. 2 | 3 | https://github.com/nix-community/home-manager 4 | 5 | ## Getting Started 6 | 7 | https://github.com/juspay/nix-dev-home 8 | 9 | To view help from terminal, 10 | 11 | ```sh 12 | $ man home-configuration.nix 13 | ``` 14 | 15 | ## Sub-pages 16 | 17 | ```query 18 | children:. 19 | ``` 20 | -------------------------------------------------------------------------------- /en/howto.md: -------------------------------------------------------------------------------- 1 | # HOWTO 2 | 3 | How to do various things with [[nix]]: 4 | 5 | ```query 6 | children:. 7 | ``` 8 | -------------------------------------------------------------------------------- /en/howto/git-profiles.md: -------------------------------------------------------------------------------- 1 | # Separate Git "profiles" 2 | 3 | You want to override #[[git|Git]] config (such as commit author email) for only certain repos, such as those under a certain folder. This is useful when dealing with corporate policies, which often block commit pushes that doesn't comfort to certain standards, such as using work email address in the commit email. Those using Bitbucket's [Control Freak](https://marketplace.atlassian.com/apps/1217635/control-freak-commit-checkers-and-jira-hooks-for-bitbucket?tab=overview&hosting=cloud) may be familiar with this error throw in response `git push`: 4 | 5 | ```text 6 | remote: 7 | remote: Control Freak - Commit 484b773a7e6d2ed8 rejected: bad committer metadata. 8 | remote: ----- 9 | remote: Committer "John Doe " does not exactly match 10 | remote: a Bitbucket user record. The closest match is: 11 | remote: 12 | remote: "john.doe " 13 | ``` 14 | 15 | 16 | {#git-config} 17 | ## Git config has a solution 18 | 19 | Git provides a way to solve the above problem -- by specifying configuration unique to repos whose paths match a given filepattern. This is achieved using [the `includeIf` section](https://git-scm.com/docs/git-config#_includes) in Git config. But how do we configure this *through* Nix? 20 | 21 | {#hm} 22 | ## Configuring in home-manager 23 | 24 | When using #[[home-manager]], you can add the following to your `programs.git` module: 25 | 26 | ```nix 27 | programs.git = { 28 | # Bitbucket git access and policies 29 | includes = [{ 30 | condition = "gitdir:~/mycompany/**"; 31 | contents = { 32 | user.email = "john.doe@mycompany.com"; 33 | }; 34 | }]; 35 | } 36 | ``` 37 | 38 | With this, any commit you make to repos under the `~/mycompany` directory will use that email address as its commit author email. 39 | 40 | ## Examples 41 | 42 | - [srid/nixos-config: juspay.nix](https://github.com/srid/nixos-config/blob/f5388e798737d63eae4f88508f57fea0dd0b4192/home/juspay.nix) 43 | -------------------------------------------------------------------------------- /en/howto/hm-fonts.md: -------------------------------------------------------------------------------- 1 | # Installing fonts using home-manager 2 | 3 | Whether you are on #[[macos|macOS]] or [[nixos|NixOS]], you can install and setup fonts in an unified fashion with [[nix|Nix]] using #[[home-manager|home-manager]]. 4 | 5 | For e.g., to install the [Cascadia Code][cascadia] font: 6 | 7 | ```nix 8 | { 9 | home.packages = [ 10 | # Fonts 11 | cascadia-code 12 | ]; 13 | 14 | fonts.fontconfig.enable = true; 15 | } 16 | ``` 17 | 18 | See [this issue](https://github.com/nix-community/home-manager/issues/605) for details. 19 | 20 | ## Verify on macOS {#macos} 21 | 22 | To confirm that the font was successfully installed on [[macos]], you can open the [Font Book][font-book] app and search for the font. They will have been installed into `~/Library/Fonts/HomeManager` folder. 23 | 24 | [cascadia]: https://x.com/dhh/status/1791920107637354964 25 | [font-book]: https://support.apple.com/en-ca/guide/font-book/welcome/mac 26 | -------------------------------------------------------------------------------- /en/howto/local-flake-input.md: -------------------------------------------------------------------------------- 1 | 2 | # Use a local directory as flake input 3 | 4 | A [[flake-url]] can not only be [[git]] repositories. They can also refer to local paths. If you have two projects `~/code/foo` and `~/code/bar`, and `bar` depends on `foo`, you can use the following `flake.nix` in `bar` to have it refer to the local `foo` project: 5 | 6 | ```nix 7 | { 8 | inputs = { 9 | foo.url = "path:/Users/me/code/foo"; 10 | }; 11 | outputs = inputs: { ... }; 12 | } 13 | ``` 14 | 15 | >[!warning] `flake.lock` 16 | > Whenever you modify files under `~/code/foo`, you must run update the `flake.lock` hash in `~/code/bar` by running: 17 | > 18 | > ```sh 19 | > nix flake update foo 20 | > ``` 21 | > 22 | > The alternative is to pass `--override-input foo ~/code/foo` to `nix build` or `nix develop` commands; this will override the hash for "foo" in the `flake.lock` file. 23 | -------------------------------------------------------------------------------- /en/howto/nix-package.md: -------------------------------------------------------------------------------- 1 | # Use a specific version of `nix` 2 | 3 | You can choose to run a specific version of `nix` CLI. Now, there are several ways to do it. You can either choose to run a specific version temporarily via `nix run` or pin it permanently in your `home-manager`, `NixOS` or `nix-darwin` configuration. 4 | 5 | ## Temporarily (via `nix run`) 6 | 7 | >[!warning] WIP 8 | 9 | ## Pinning 10 | 11 | >[!warning] WIP 12 | 13 | ### On home-manager 14 | 15 | >[!warning] WIP 16 | 17 | ### On NixOS 18 | 19 | >[!warning] WIP 20 | 21 | ### On nix-darwin 22 | 23 | >[!warning] WIP -------------------------------------------------------------------------------- /en/howto/remote-cp.md: -------------------------------------------------------------------------------- 1 | # Copying packages to a remote Nix store 2 | 3 | This is useful if your local machine is powerful and you have built a number of 4 | packages on it, but want to re-use them on another machine, without using a Nix 5 | cache or rebuilding them. 6 | 7 | ```sh 8 | nix copy --to ssh-ng://admin@100.96.121.13 /nix/store/??? 9 | ``` 10 | 11 | If you use [nixci], this looks like: 12 | 13 | ```sh 14 | nixci . -- --option system aarch64-linux | xargs nix copy --to ssh-ng://admin@100.96.121.13 15 | ``` 16 | 17 | [nixci]: https://github.com/srid/nixci 18 | -------------------------------------------------------------------------------- /en/howto/uninstall-nix.md: -------------------------------------------------------------------------------- 1 | # Uninstall Nix 2 | 3 | 1. Run `/nix/nix-installer uninstall` 4 | - NOTE: If that path above does not exist, [follow these instructions](https://nixos.org/manual/nix/stable/installation/uninstall.html#macos) to manually uninstall Nix. 5 | 1. Reboot 6 | 7 | >[!note] Problems while deleting `Nix Store` volume on macOS 8 | > If the installer fails to delete the `/nix/store` volume, try rebooting your mac 9 | > and running `/nix/nix-installer uninstall` again. If that path doesn't exist, delete manually by following last step from [here](https://nixos.org/manual/nix/stable/installation/uninstall.html#macos). 10 | 11 | -------------------------------------------------------------------------------- /en/ifd.md: -------------------------------------------------------------------------------- 1 | # Import From Derivation (IFD) 2 | 3 | [[nix|Nix]] expressions are *evaluated* to produce #[[drv|derivations]] (among other values). These derivations when *realized* usually produce the compiled binary packages. Sometimes, realizing a derivation can produce a Nix expression representing another derivation. This generated Nix expression too needs to be *evaluated* to its derivation before it can be *realized*. This secondary evaluation is achieved by `import`ing from the derivation being evaluated, and is called "import from derivation" or IFD. 4 | 5 | For detailed explanation, see [this blog post](https://blog.hercules-ci.com/2019/08/30/native-support-for-import-for-derivation/). 6 | -------------------------------------------------------------------------------- /en/index.md: -------------------------------------------------------------------------------- 1 | # NixOS Asia 2 | 3 | > [!tip] Welcome to NixOS Asia 4 | > NixOS Asia is a community of [[nix]] and [[nixos]] users, promulgated initially from the Indian subcontinent. 5 | 6 | 7 | ## Explore this website 8 | 9 | 17 | 18 | - Start from [[install|here]] if you are new to Nix. 19 | - Then, checkout our [[tutorial]]# 20 | - For further reading, read [[howto]]# and [[blog]]# 21 | - Most other pages are usually under [[topics]]# 22 | - You can browse the rest of the content in [the index](-/all). 23 | 24 | ## Community 25 | 26 | You can participate in the community discussion through the following venues. 27 | 28 | - [Zulip](https://nixos.zulipchat.com/): Zulip is a hybrid of "chat" and "forum".[^log] 29 | - [Telegram](https://t.me/nixosasia) 30 | - [Twitter / X](https://twitter.com/nixos_asia): We'll post all announcements here. 31 | - [GitHub](https://github.com/nixos-asia) 32 | 33 | [^log]: Public chat logs are available at [chat.nixos.asia](https://chat.nixos.asia/) 34 | 35 | Also consider taking a look at our sister community, [Functional Programming India](https://functionalprogramming.in/). 36 | 37 | {#contribute} 38 | ## Looking to contribute? 39 | 40 | View *good first issues* involving [Nix][gfi-nix] or [Rust][gfi-rust]. 41 | 42 | [gfi-nix]: https://github.com/search?q=user%3Asrid+user%3Ajuspay+user%3Anixos-asia+user%3Aflake-parts+repo%3APlatonic-Systems%2Fprocess-compose-flake+created%3A%3E%3D2024+label%3A%22good+first+issue%22+language%3ANix+is%3Aopen&type=issues&ref=advsearch 43 | 44 | [gfi-rust]: https://github.com/search?q=user%3Asrid+user%3Ajuspay+user%3Anixos-asia+user%3Aflake-parts+-repo%3Ajuspay%2Fhyperswitch+-repo%3Ajuspay%2Fsuperposition+repo%3APlatonic-Systems%2Fprocess-compose-flake+created%3A%3E%3D2024+label%3A%22good+first+issue%22+language%3ARust+is%3Aopen&type=issues&ref=advsearch 45 | 46 | ## Events 47 | 48 | See [[event]]. 49 | -------------------------------------------------------------------------------- /en/index.yaml: -------------------------------------------------------------------------------- 1 | page: 2 | lang: en 3 | template: 4 | editBaseUrl: https://github.com/nixos-asia/website/edit/master/en 5 | -------------------------------------------------------------------------------- /en/install.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: -1000 3 | --- 4 | 5 | # Install Nix 6 | 7 | 8 | >[!info] Linux 9 | > If you prefer to use Linux, you may be interested in [[nixos-tutorial|installing NixOS]]. The following instructions are for users of other Linux distros as well as [[macos|macOS]]. 10 | 11 | Install #[[nix]] using [the unofficial installer](https://github.com/DeterminateSystems/nix-installer#the-determinate-nix-installer):[^official] 12 | 13 | ```sh 14 | curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | \ 15 | sh -s -- install --no-confirm --extra-conf "trusted-users = $(whoami)" 16 | ``` 17 | 18 | After installing Nix, open a new terminal and run the [Nix Health](https://github.com/juspay/nix-health) checks, 19 | 20 | ```sh 21 | nix --accept-flake-config run github:juspay/omnix health 22 | ``` 23 | 24 | Expect to see all results in either green (or yellow). 25 | 26 | ## Next Steps 27 | 28 | Checkout [[nix-first]] and 29 | 30 | - [[dev]] if you are looking to use Nix for development. 31 | - [[home-manager]] (and [[nix-darwin]] if you are on [[macos]]) if you would like to use Nix for more than packages and [[dev|devShells]]. 32 | 33 | [^official]: You *can* use [the official installer](https://nixos.org/download). However, there are a couple of manual steps necessary: 34 | - As it [does not yet](https://discourse.nixos.org/t/anyone-up-for-picking-at-some-nix-onboarding-improvements/13152/4) include an uninstaller, you will have to manually uninstall Nix when the time comes ([[macos-upgrade|example]]). 35 | - As it does not automatically enable [[flakes]], you will have to [manually enable it](https://nixos.wiki/wiki/Flakes). 36 | -------------------------------------------------------------------------------- /en/jobs.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: 100 3 | --- 4 | 5 | # Nix Jobs 6 | 7 | A list of currently available [[nix|Nix]] jobs. 8 | 9 | {#juspay} 10 | ## Juspay - Nix Engineer (Remote) 11 | 12 | >[!info] 13 | > Posted on May 21, 2024 14 | > 15 | > Hired on Jun 21, 2024 16 | 17 | [Juspay] is looking to add a 3rd member to our Nix team. The position is **full-time and remote**. 18 | 19 | The role primarily involves nixifying our internal projects - which are written mostly in Haskell, but also Rust, PureScript, ReScript, Python and several other languages and tools. We use [flake-parts](https://community.flake.parts/) wherever possible to provide a simpler Developer Experience. To get a sense of what you will mostly be working on, see the Nix in [nammayatri]. The role can potentially involve some Rust work as well. Contributing to Open Source is encouraged; you may view **our Open Source Nix projects** [on GitHub][oss]. 20 | 21 | The ideal candidate is: 22 | 23 | - Motivated about writing Nix 24 | - Cares about improving Developer Experience 25 | - Communicates clearly & writes good documentation[^this] 26 | 27 | To apply, send the Nix contributions you are most proud of (along with your résumé) by [email](mailto:sridhar.ratnakumar@juspay.in) or [X DM](https://x.com/sridca). 28 | 29 | 30 | [Juspay]: https://juspay.in/careers/ 31 | [nammayatri]: https://github.com/nammayatri/nammayatri 32 | [oss]: https://github.com/orgs/juspay/repositories?type=source&q=nix+sort%3Astars 33 | 34 | [^this]: In additional to internal documentation, you will be encouraged to post [[tutorial|tutorials]] and write [[blog|blog posts]] on this very website. 35 | -------------------------------------------------------------------------------- /en/macos.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: 10 3 | --- 4 | 5 | # macOS 6 | 7 | [[nix]] is supported on macOS. 8 | 9 | >[!warning] Darwin support in nixpkgs 10 | > macOS support in [[nixpkgs]] is not of same quality and priority as Linux. See https://github.com/NixOS/nixpkgs/issues/145230 & https://github.com/NixOS/nixpkgs/issues/116341 11 | 12 | ```query 13 | children:. 14 | ``` -------------------------------------------------------------------------------- /en/modules.md: -------------------------------------------------------------------------------- 1 | # Module System 2 | 3 | The #[[nixpkgs]] library provides a module system for [[nix]] expressions. To learn it, see our tutorial: [[nix-modules]]#. 4 | 5 | ## NixOS 6 | 7 | [[nixos]] makes use of the module system to provide various functionality including services and programs. See https://search.nixos.org/options for a list of all available options. 8 | 9 | ## Flakes 10 | 11 | This module system is not natively supported in [[flakes]]. However, flakes can define and use modules using [[flake-parts]]. 12 | 13 | ## Links 14 | 15 | - [Zero to Nix: Modules](https://zero-to-nix.com/concepts/nixos#modules) 16 | -------------------------------------------------------------------------------- /en/nix-darwin.md: -------------------------------------------------------------------------------- 1 | [nix-darwin](https://github.com/LnL7/nix-darwin) brings [[nixos]] like configuration to #[[macos]], allowing you to install packages (among doing other things) purely through #[[nix]]. -------------------------------------------------------------------------------- /en/nix-first.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: 1 3 | page: 4 | image: nix-tutorial/nix-first.png 5 | --- 6 | 7 | # First steps with Nix 8 | 9 | You have [[install|installed Nix]]. Now let's play with the `nix` command but without bothering to write any Nix expressions yet (we reserve that for the [[nix-rapid|next tutorial]]). In particular, we will learn how to use packages from the [[nixpkgs|nixpkgs]] repository and elsewhere. 10 | 11 | ![[nix-first.png]] 12 | 13 | {#run} 14 | ## Running a package 15 | 16 | As of this writing, [[nixpkgs]] has over 80,000 packages. You can search them [here](https://search.nixos.org/packages). Search for "`cowsay`" and [you will find](https://search.nixos.org/packages?type=packages&query=cowsay) that it is available in Nixpkgs. We can download and run the [cowsay](https://en.wikipedia.org/wiki/Cowsay) package as follows: 17 | 18 | ```text 19 | $ nix run nixpkgs#cowsay "G'day $USER" 20 | ____________ 21 | < G'day srid > 22 | ------------ 23 | \ ^__^ 24 | \ (oo)\_______ 25 | (__)\ )\/\ 26 | ||----w | 27 | || || 28 | $ 29 | ``` 30 | 31 | >[!info] `nix run` 32 | > `nix run` command will run the specified package from the flake. Here `nixpkgs` is the [[flakes|flake]], followed by the letter `#`, which is followed by the package ([[drv]]) name `cowsay` that is outputted by that flake. See [[flake-url]] for details on the syntax. 33 | 34 | {#inside-package} 35 | ## Looking inside a package 36 | 37 | What is a Nix "package"? Technically, a Nix package is a special [[store-path]] built using instructions from a [[drv]], both of which reside in the [[store]]. To see what is contained by the `cowsay` package, look inside its [[store-path]]. To get the store path for a package (here, `cowsay`), run `nix build` as follows: 38 | 39 | ```text 40 | $ nix build nixpkgs#cowsay --no-link --print-out-paths 41 | /nix/store/8ij2wj5nh4faqwqjy1fqg20llawbi0d5-cowsay-3.7.0-man 42 | /nix/store/n1lnrvgl43k6zln1s5wxcp2zh9bm0z63-cowsay-3.7.0 43 | ``` 44 | 45 | The `cowsay` [[drv]] produces two output paths, the second of which is the cowsay binary package (the first one is the separate documentation path), and if you inspect that[^tree] you will see the contents of it: 46 | 47 | [^tree]: Incidentally, we use the [tree](https://en.wikipedia.org/wiki/Tree_\(command\)) command, rather than `ls`, to look at the directory tree, using the package from [[nixpkgs]] of course (since it may not already be installed). 48 | 49 | ```text 50 | $ nix run nixpkgs#tree /nix/store/n1lnrvgl43k6zln1s5wxcp2zh9bm0z63-cowsay-3.7.0 51 | /nix/store/n1lnrvgl43k6zln1s5wxcp2zh9bm0z63-cowsay-3.7.0 52 | ├── bin 53 | │   ├── cowsay 54 | │   └── cowthink -> cowsay 55 | └── share 56 | └── cowsay 57 | ├── cows 58 | │   ├── DragonAndCow.pm 59 | │   ├── Example.pm 60 | │   ├── Frogs.pm 61 | │   ├── ... 62 | ``` 63 | 64 | >[!info] Nix Store & Store Paths 65 | > `/nix/store` is a special directory representing the [[store]]. The paths inside `/nix/store` are known as [[store-path]]. Nix fundamentally is, in large part, about manipulating these store paths in a *pure* and *reproducible* fashion; [[drv]] are "recipes" that does this manipulation, and they too live in the [[store]]. 66 | 67 | {#shell} 68 | ## Shell environment 69 | 70 | One of the powers of Nix is that it enables us to create *isolated* [[shell|shell]] environments containing just the packages we need. For eg., here's how we create a transient shell containing the "cowsay" and "[fortune](https://en.wikipedia.org/wiki/Fortune_(Unix))" packages: 71 | 72 | ```text 73 | $ nix shell nixpkgs#cowsay nixpkgs#fortune 74 | ❯ 75 | ``` 76 | 77 | From here, you can verify that both the programs are indeed in `$PATH` as indicated by the "bin" directory in their respective [[store-path|store paths]]: 78 | 79 | ```text 80 | $ nix shell nixpkgs#cowsay nixpkgs#fortune 81 | ❯ which cowsay 82 | /nix/store/n1lnrvgl43k6zln1s5wxcp2zh9bm0z63-cowsay-3.7.0/bin/cowsay 83 | ❯ which fortune 84 | /nix/store/mfw77f008xy0zb7dqdyggw0xj2gd4jjv-fortune-mod-3.20.0/bin/fortune 85 | ❯ fortune | cowsay 86 | ________________________________ 87 | / The longer the title, the less \ 88 | \ important the job. / 89 | -------------------------------- 90 | \ ^__^ 91 | \ (oo)\_______ 92 | (__)\ )\/\ 93 | ||----w | 94 | || || 95 | ``` 96 | 97 | >[!tip] One-off command 98 | > Instead of creating a shell environment, you can also run commands one-off using the `-c` option. The above session can equally be achieved using: 99 | > ```text 100 | > nix shell nixpkgs#cowsay nixpkgs#fortune -c sh -c 'fortune | cowsay' 101 | > ``` 102 | 103 | {#install} 104 | ## Installing a package 105 | 106 | >[!warning] Declarative package management 107 | > This section explains how to install a package *imperatively*. For a better way of installing packages (*declaratively*), see [[hm-tutorial|home-manager]]. 108 | 109 | Neither `nix run` nor `nix shell` will mutate your system environment, aside from changing the [[store]]. If you would like to *permanently* install a package somewhere under your $HOME directory, you can do so using `nix profile install`: 110 | 111 | ```text 112 | $ nix profile install nixpkgs#cowsay nixpkgs#fortune 113 | $ which cowsay 114 | /home/user/.nix-profile/bin/cowsay 115 | $ which fortune 116 | /home/user/.nix-profile/bin/fortune 117 | $ 118 | ``` 119 | 120 | `nix profile install` installs symlinks under the `$HOME/.nix-profile` directory, which the Nix [[install|installer]] already added to your `$PATH`. For details, see the [Nix manual](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-profile-install). 121 | 122 | These symlinks, ultimately, point to the package [[store-path]] outputs under the [[store]], viz.: 123 | 124 | ```text 125 | $ readlink $(which fortune) 126 | /nix/store/mfw77f008xy0zb7dqdyggw0xj2gd4jjv-fortune-mod-3.20.0/bin/fortune 127 | ``` 128 | 129 | Note that this is the same path used by both `nix build` and `nix shell`. Each specific package is uniquely identified by their [[store-path]]; changing any part of its [[drv|build recipe]] (including dependencies), changes that path. Hence, nix is reproducible. 130 | 131 | {#nixpkgs-pin} 132 | ## How is [[nixpkgs|nixpkgs]] fetched 133 | 134 | So far we have been retrieving and installing software from the [[nixpkgs]] flake, which is defined in the GitHub repository: https://github.com/nixos/nixpkgs. This information comes from the [[registry]]: 135 | 136 | 137 | ```text 138 | $ nix registry list | grep nixpkgs 139 | global flake:nixpkgs github:NixOS/nixpkgs/nixpkgs-unstable 140 | ``` 141 | 142 | A registry is simply a mapping of flake alias to [[flake-url]]. 143 | 144 | >[!tip] Adding to registry 145 | > You can add your own flakes to this [[registry|registry]] as well. See [the manual](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-registry-add) 146 | 147 | We can find the current Git revision of [[nixpkgs]] used by our [[registry|registry]] as follows: 148 | 149 | ```text 150 | ❯ nix flake metadata nixpkgs --json | nix run nixpkgs#jq -- -r .locked.rev 151 | 317484b1ead87b9c1b8ac5261a8d2dd748a0492d 152 | ``` 153 | 154 | From here, you can see the revision [on GitHub](https://github.com/NixOS/nixpkgs/commit/317484b1ead87b9c1b8ac5261a8d2dd748a0492d). 155 | 156 | The discerning readers may have noticed that the registry specifies *only* the branch (`nixpkgs-unstable`), but not the specific revision. Nix registry internally [caches flakes locally and updates them automatically](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-registry#description), thus the specific Git revision of [[nixpkgs]] used may change over time! 157 | 158 | > [!tip] Pinning nixpkgs 159 | > To avoid the aforementioned automatic update, you can manually [pin](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-registry-pin) the registry entry for [[nixpkgs]]. In [[hm-tutorial|home-manager]], we will see [an automatic and declarative way](https://github.com/juspay/nix-dev-home/commit/99f304a6512f59194932b2010af5e270efdfebe8) of doing this (through flake inputs). 160 | 161 | You are not required to use a registry. Without a registry, getting a package off nixpkgs would instead involve its fully qualified [[flake-url|URL]]: 162 | 163 | ```text 164 | $ nix run github:NixOS/nixpkgs/nixpkgs-unstable#cowsay 165 | ... 166 | ``` 167 | 168 | {#external-software} 169 | ## Using software outside of [[nixpkgs|nixpkgs]] 170 | 171 | [[nixpkgs]] is not the only way to get software packaged by Nix. As you have seen immediately above, you can install programs from *any* [[flakes|flake]] by specifying its [[flake-url|flake URL]] to the `nix ?` commands. For example, [Emanote](https://emanote.srid.ca/start/install) (which is used to build this very website) can be executed or installed directly off its flake [on GitHub](https://github.com/srid/emanote): 172 | 173 | ```text 174 | $ nix run github:srid/emanote 175 | ... 176 | ``` 177 | 178 | You can of course also install it to your home directory: 179 | 180 | ```text 181 | $ nix profile install github:srid/emanote 182 | ... 183 | ``` 184 | 185 | ## What's next 186 | 187 | - See [[nix-rapid]] where we will go over writing simple Nix expressions and [[flakes|flakes]]. 188 | - If you want to manage your system using Nix, see [[hm-tutorial]] (if you are on [[macos]] or non-NixOS Linux) or [[nixos-tutorial]] (if you are on [[nixos]]). 189 | -------------------------------------------------------------------------------- /en/nix-modules.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: 3 3 | page: 4 | image: nix-tutorial/nix-modules.png 5 | --- 6 | 7 | # Introduction to module system 8 | 9 | Using the [[modules|module system]] is a key stepping stone to writing maintainable and shareable [[nix|Nix]] code. In this tutorial, we'll write a configuration system for the simple [lsd] command, thus *introducing* the reader to the Nix [[modules|module system]], so that they benefit from features such as configuration type checking, option documentation, and modularity. To learn more about the module system, we recommend [this video from Tweag](https://www.youtube.com/watch?v=N7hFP_40DJo) as well the article "[Module system deep dive][doc]" from nix.dev. 10 | 11 | ![[nix-tutorial/nix-modules.png]] 12 | 13 | We shall begin by understanding the low-levels: how to use `evalModules` from [[nixpkgs|nixpkgs]] to define and use our own modules from scratch, using the aforementioned `lsd` use-case. The next tutorial in this series will go one high-level up and talk about how to work with modules across [[flakes|flakes]], using [[flake-parts]]. 14 | 15 | [doc]: https://nix.dev/tutorials/module-system/deep-dive 16 | 17 | ## A simple example 18 | 19 | Consider the following Nix code, defined in a [[flakes|flake]]: 20 | 21 | [[nix-modules/1/flake.nix]] 22 | ![[nix-modules/1/flake.nix]] 23 | 24 | >[!info] Source code for this tutorial 25 | > All source code for the Nix in this tutorial is available [here](https://github.com/nixos-asia/website/tree/master/global/nix-modules). 26 | 27 | This is a simple flake that exposes a package (a [[writeShellApplication]] [[drv]] wrapping [lsd]), that can be [[nix-first|`nix run`ed]] to list the contents of the root directory. 28 | 29 | ```sh 30 | ❯ nix run 31 | drwxrwxr-x root admin 2.5 KB Tue Jan 30 15:19:06 2024  Applications 32 | drwxr-xr-x root wheel 1.2 KB Sat Nov 18 23:43:59 2023  bin 33 | dr-xr-xr-x root wheel 5.1 KB Wed Jan 17 09:21:57 2024  dev 34 | lrwxr-xr-x root wheel 11 B Sat Nov 18 23:43:59 2023  etc ⇒ private/etc 35 | lrwxr-xr-x root wheel 25 B Wed Jan 17 09:22:56 2024  home ⇒ /System/Volumes/Data/home 36 | drwxr-xr-x root wheel 2.2 KB Mon Dec 4 02:08:02 2023  Library 37 | drwxr-xr-x root wheel 224 B Sat Jul 22 20:09:12 2023  nix 38 | ... 39 | ``` 40 | 41 | This program is hardcoded to do a certain thing: it can list the contents of the `/` directory. Now let's say we want to configure its behaviour but without having to modify the derivation itself. 42 | 43 | In particular, we want our program to: 44 | - *list a different directory*. 45 | - or, *show a tree view rather than a linear list*. 46 | 47 | Normally we can achieve this by refactoring our Nix expression to be a *function* (see `lsdFor` ⤵️) that takes arguments for these variations (`dir` and `tree` ⤵️), producing the appropriate [[drv|derivation]] as a result: 48 | 49 | [[nix-modules/2/flake.nix]] 50 | ![[nix-modules/2/flake.nix]] 51 | 52 | Now we can try out each of these variations: 53 | 54 | ```sh 55 | ❯ nix run .#home 56 |  code  Documents  Keybase  Movies  org ... 57 | 58 | ❯ nix run .#downloads 59 |  Downloads 60 | ├──  '$RECYCLE.BIN' 61 | │ └──  desktop.ini 62 | ├──  2303.18223.pdf 63 | ├──  4.jpg 64 | ├──  '[ORIGINAL] PKD MASTERY GUIDE BOOK.pdf' 65 | ├──  'ACTUAL FREEDOM' 66 | │ ├──  'ACTUAL FREEDOM (1).txt' 67 | │ └──  "ACTUAL FREEDOM (Richard's Words Only).txt" 68 | ... 69 | ``` 70 | 71 | The `lsdFor` function returns a `lsd` wrapper package that behaves in accordance with the arguments we pass to it. The flake outputs three packages, including one for listing the user's home directory as well as their "Downloads" folder as a tree view. 72 | 73 | >[!tip] Case for the `lsd` module 74 | > Our above flake is simple enough that it strictly doesn't require further refactoring. However, in larger flakes, having functions peppered throughout the project can be rather difficult to entangle; besides, we want to modular overrides and type checking, along with documentation. To this end, we'll see how to refactor the above to use the module system, and in the process we'll add more configurability to our `lsd` wrapper. 75 | 76 | {#introduce} 77 | ## Introducing the module system 78 | 79 | 1. A Nix *module* is a specification of various `options`. 80 | 1. When the user `imports` this module, they can assign these options. 81 | 1. The module implementation (ie., the `config` attribute) will then use these values to produce the final expression to substitute in call site where the module gets imported. 82 | 83 | Modules can import each other in nested fashion; and option types can have certain merge semantics allowing you to define the same option across multiple modules. 84 | 85 | This is a mouthful, so let's get down to the concrete details. To port our flake above, we need to define two options: `dir`, and `tree`. We will as well add a third option that is not user-setable but will be used set the resulting package. 86 | 87 | Here's our lsd module, defined in `lsd.nix` alongside the flake. Follow along the code comments: 88 | 89 | [[nix-modules/3/lsd.nix]] 90 | ![[nix-modules/3/lsd.nix]] 91 | 92 | >[!info] Follow the comments 93 | > We recommend that you follow the comments in the above Nix file to understand its structure. As always, consult [Module system deep dive][doc] to learn of all the details. 94 | 95 | Note: 96 | 97 | - `mkOption` is used create the option *types* 98 | - Types used here: *str*, *bool*, *package* and *submodule* 99 | - A "submodule" is a nested module, with its own options/ imports and config. 100 | - `config` gives the implementation when the user sets the options. 101 | - In our case, we 'output' the result in the `package` option (which cannot be set by the user, due to `readOnly = true`). 102 | 103 | Let's evaluate it from the [[repl]]: 104 | 105 | ```sh 106 | ❯ nix repl 107 | Welcome to Nix 2.19.2. Type :? for help. 108 | 109 | nix-repl> :lf nixpkgs 110 | Added 15 variables. 111 | 112 | nix-repl> pkgs = legacyPackages.${builtins.currentSystem} 113 | 114 | nix-repl> lib = pkgs.lib 115 | 116 | nix-repl> res = lib.evalModules { modules = [ ./lsd.nix { lsd.dir = "$HOME"; } ]; specialArgs = { inherit pkgs; }; } 117 | 118 | nix-repl> res.config.lsd.package 119 | «derivation /nix/store/my26y1wp6801sslfvfzf21q41fzh8bch-list-contents.drv» 120 | 121 | nix-repl> :b res.config.lsd.package 122 | This derivation produced the following outputs: 123 | out -> /nix/store/m8phgz5ch7whqbs5pk991pc0cfczsghk-list-contents 124 | ``` 125 | 126 | Using `evalModules`, as we saw in the repl session, we can refactor our previous flake: 127 | 128 | [[nix-modules/3/flake.nix]] 129 | ![[nix-modules/3/flake.nix]] 130 | 131 | >[!tip] Hmm! 132 | > You may notice that there's not much difference. If anything our new flake is *slightly* more complex, due to use of `evalModules`. The simplicity of the module system will become evident as you write more complex flakes, or if you want to share your modules or override them. 133 | 134 | {#imports} 135 | ## Importing modules 136 | 137 | Let's do something more interesting in the above flake. We'll create a "common settings" module, and then use that across the packages using the `imports` attribute. `evalModules` implements a type merge system that knows how to merge same attributes from multiple modules. 138 | 139 | [[nix-modules/4/flake.nix]] 140 | ![[nix-modules/4/flake.nix]] 141 | 142 | Compared to the 3rd flake, we have: 143 | 144 | - In [[nix-modules/4/lsd.nix]]: a new option `long` to specify `-l` to lsd. 145 | - In [[nix-modules/4/flake.nix]]: 146 | - a new module `common` enabling the `long` option. 147 | - all packages now `imports` this common module, to derive the `long` option. 148 | - a `mkLib` functions that we will export for reuse from another flake (see below) 149 | 150 | Now when you `nix run` these programs you will get similar output to the previous flake but with a long listing instead. 151 | 152 | {#share} 153 | ## Sharing modules across flakes 154 | 155 | We will create a 5th flake that re-uses module from the 4th flake above. This is a contrived example, but it demonstrates how you can share modules across flakes. 156 | 157 | [[nix-modules/5/flake.nix]] 158 | ![[nix-modules/5/flake.nix]] 159 | 160 | Note that, 161 | 162 | - [[nix-modules/4/flake.nix]] outputs a `mkLib` function that gives us the `common` module along with the `lsdFor` function. 163 | - In [[nix-modules/5/flake.nix]], we access these for re-use, thus relieving our 5th flake of having to define `lsd.nix` and the `common` module. 164 | 165 | Our 5th flake is fairly simple, due to hiding all the implementation in an external flake (4th flake). The 5th flake contains only the "what" and not the "how" of our `lsd` packages; it tells us what to configure, hiding the implementation in an input flake (4th flake). 166 | 167 | {#end} 168 | ## Where to go from here? 169 | 170 | You have just read a quick introduction to the module system, in particular how to define, use and share them in [[flakes]]. To learn more about the module system, we recommend [this video from Tweag](https://www.youtube.com/watch?v=N7hFP_40DJo) as well the article "[Module system deep dive][doc]" from nix.dev. Look out for the next tutorial in this series, where we will talk about [[flake-parts]]. 171 | 172 | [lsd]: https://github.com/lsd-rs/lsd 173 | -------------------------------------------------------------------------------- /en/nix-rapid.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: 2 3 | page: 4 | image: nix-tutorial/nix-rapid.png 5 | --- 6 | 7 | # Rapid Introduction to Nix 8 | 9 | 10 | The goal of this mini-tutorial is to introduce you to [[nix|Nix]] the language, including [[flakes|flakes]], as quickly as possible while also preparing the motivated learner to dive deeper into [the whole Nix ecosystem][zero-to-nix]. At the end of this introduction, you will be able to create a #[[flakes|flake.nix]] that builds a package and provides a [[dev|developer environment]] shell. 11 | 12 | ![[nix-rapid.png]] 13 | 14 | >[!tip] Purely functional 15 | > If you are already experienced in [purely functional programming](https://en.wikipedia.org/wiki/Purely_functional_programming), it is highly recommended to read [Nix - taming Unix with functional programming](https://www.tweag.io/blog/2022-07-14-taming-unix-with-nix/) to gain a foundational perspective into Nix being purely functional but in the context of *file system* (as opposed to values stored in memory). 16 | > 17 | > > [..] we can treat the file system in an operating system like memory in a running program, and equate package management to memory management 18 | 19 | {#pre} 20 | ## Pre-requisites 21 | 22 | - **Install Nix**: Nix can be [[install|installed on Linux and macOS]]. If you are using [[nixos]], it already comes with Nix pre-installed. 23 | - **Play with Nix**: Before writing Nix expressions, it is useful to get a feel for working with the `nix` command. See [[nix-first]] 24 | 25 | ## Attrset 26 | 27 | >[!info] To learn more 28 | > - [Official manual](https://nixos.org/manual/nix/stable/language/values.html#attribute-set) 29 | > - [nix.dev on attrsets](https://nix.dev/tutorials/nix-language#attribute-set) 30 | 31 | The [Nix programming language][nix-lang] provides a lot of general constructs. But at its most basic use, it makes heavy use of *nested hash maps* otherwise called an "attrset". They are equivalent to [`Map Text a`](https://hackage.haskell.org/package/containers-0.6.7/docs/Data-Map-Strict.html#t:Map) in Haskell. The following is a simple example of an attrset: 32 | 33 | ```nix 34 | { 35 | foo = { 36 | bar = 1; 37 | }; 38 | } 39 | ``` 40 | 41 | We have an outer attrset with a single key `foo`, whose value is another attrset with a single key `bar` and a value of `1`. 42 | 43 | ## repl 44 | 45 | Nix expressions can be readily evaluated in the [[repl|Nix repl]]. To start the repl, run `nix repl`. 46 | 47 | ```sh 48 | $ nix repl 49 | Welcome to Nix 2.12.0. Type :? for help. 50 | 51 | nix-repl> 52 | ``` 53 | 54 | You can then evaluate expressions: 55 | 56 | ```nix 57 | nix-repl> 2+3 58 | 5 59 | 60 | nix-repl> x = { foo = { bar = 1; }; } 61 | 62 | nix-repl> x 63 | { foo = { ... }; } 64 | 65 | nix-repl> x.foo 66 | { bar = 1; } 67 | 68 | nix-repl> x.foo.bar 69 | 1 70 | 71 | nix-repl> 72 | ``` 73 | 74 | ## [[flakes|Flakes]] 75 | 76 | >[!info] To learn more 77 | > - [Serokell Blog: Basic flake structure](https://serokell.io/blog/practical-nix-flakes#basic-flake-structure) 78 | 79 | A Nix [[flakes|flake]] is defined in the `flake.nix` file, which denotes an attrset containing two keys `inputs` and `outputs`. *Outputs* can reference *inputs*. Thus, changing an *input* can change the *outputs*. The following is a simple example of a flake: 80 | 81 | ```nix 82 | { 83 | inputs = { }; 84 | 85 | outputs = inputs: { 86 | foo = 42; 87 | }; 88 | } 89 | ``` 90 | 91 | This flake has zero `inputs`. `outputs` is a [function][nix-function] that takes the (realised) inputs as an argument and returns the final output attrset. This output attrset, in our example, has a single key `foo` with a value of `42`. 92 | 93 | We can use the [`nix flake show`][nix-flake-show] command to see the output structure of a flake: 94 | 95 | ```sh 96 | $ nix flake show 97 | path:/Users/srid/code/nixplay?lastModified=1675373998&narHash=sha256-ifNiFGU1VV784kVcssn2rXIil%2feHfMLhPfmvaELefwA= 98 | └───foo: unknown 99 | $ 100 | ``` 101 | 102 | We can use [`nix eval`][nix-eval] to evaluate any output. For example, 103 | 104 | ```sh 105 | $ nix eval .#foo 106 | 42 107 | ``` 108 | 109 | ### Graph 110 | 111 | A flake can refer to other flakes in its inputs. Phrased differently, a flake's outputs can be used as inputs in other flakes. The most common example is the [[nixpkgs]] flake which gets used as an input in most flakes. Intuitively, you may visualize a flake to be a node in a larger [graph], with inputs being the incoming arrows and outputs being the outgoing arrows. 112 | 113 | [graph]: https://en.wikipedia.org/wiki/Directed_graph 114 | 115 | ### Inputs 116 | 117 | > [!info] To learn more 118 | > - [[flake-url|URL-like syntax]] used by the `url` attribute 119 | 120 | Let's do something more interesting with our `flake.nix` by adding the [[nixpkgs]] input: 121 | 122 | ```nix 123 | { 124 | inputs = { 125 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 126 | }; 127 | 128 | outputs = inputs: { 129 | # Note: If you are macOS, substitute `x86_64-linux` with `aarch64-darwin` 130 | foo = inputs.nixpkgs.legacyPackages.x86_64-linux.cowsay; 131 | }; 132 | } 133 | ``` 134 | 135 | >[!note] About `nixpkgs-unstable` 136 | > The `nixpkgs-unstable` branch is frequently updated, hence its name, but this doesn't imply instability or unsuitability for use. 137 | 138 | The [[nixpkgs]] flake has an output called `legacyPackages`, which is indexed by the platform (called "system" in Nix-speak), further containing all the packages for that system. We assign that package to our flake output key `foo`. 139 | 140 | >[!tip] You can use [[repl|`nix repl`]] to explore the outputs of any flake, using TAB completion: 141 | > 142 | > ```sh 143 | > $ nix repl --extra-experimental-features 'flakes repl-flake' github:nixos/nixpkgs/nixpkgs-unstable 144 | > Welcome to Nix 2.12.0. Type :? for help. 145 | > 146 | > Loading installable 'github:nixos/nixpkgs/nixpkgs-unstable#'... 147 | > Added 5 variables. 148 | > nix-repl> legacyPackages.aarch64-darwin.cowsay 149 | > «derivation /nix/store/0s2vdpkpdiljmh8y06xgdw5vg2cqfs0m-cowsay-3.7.0.drv» 150 | > 151 | > nix-repl> 152 | > ``` 153 | 154 | ### Predefined outputs 155 | 156 | Nix commands treat [certain outputs as special](https://nixos.wiki/wiki/Flakes#Output_schema). These are: 157 | 158 | | Output | Nix command | Description | 159 | | ----------- | ----------------- | ---------------------------- | 160 | | `packages` | `nix build` | [[drv]] output | 161 | | `devShells` | `nix develop` | [Development](dev.md) shells | 162 | | `apps` | `nix run` | Runnable applications | 163 | | `checks` | `nix flake check` | Tests and checks | 164 | 165 | All of these predefined outputs are further indexed by the "system" value. 166 | 167 | #### Packages 168 | 169 | >[!info] To learn more 170 | > - [`pkgs.stdenv.mkDerivation`](https://nixos.org/manual/nixpkgs/stable/#sec-using-stdenv) can be used to build a custom package from scratch 171 | 172 | `packages` is the most often used output. Let us extend our previous `flake.nix` to use it: 173 | 174 | ```nix 175 | { 176 | inputs = { 177 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 178 | }; 179 | 180 | outputs = inputs: { 181 | foo = 42; 182 | packages.x86_64-linux = { 183 | cowsay = inputs.nixpkgs.legacyPackages.x86_64-linux.cowsay; 184 | }; 185 | }; 186 | } 187 | ``` 188 | 189 | Here, we are producing an output named `packages` that is an attrset of systems (currently, only `x86_64-linux`) to attrsets of packages. We are definining exactly one package, `cowsay`, for the `x86_64-linux` system. 190 | 191 | ```sh 192 | $ nix flake show 193 | path:/Users/srid/code/nixplay?lastModified=1675374260&narHash=sha256-FRven09fX3hutGa8+dagOCSQKVYAsHI6BsnCSEQ7PG8= 194 | ├───foo: unknown 195 | └───packages 196 | └───aarch64-darwin 197 | └───cowsay: package 'cowsay-3.7.0' 198 | ``` 199 | 200 | Notice that `nix flake show` recognizes the *type* of `packages`. With `foo`, it couldn't (hence type is `unknown`) but with `packages`, it can (hence type is "package"). 201 | 202 | The `packages` output is recognized by `nix build`. 203 | 204 | ```sh 205 | $ nix build .#cowsay 206 | ``` 207 | 208 | The [`nix build`][nix-build] command takes as argument a value of the form `#`. By default, `.` (which is a [[flake-url|flake URL]]) refers to the current flake. Thus, `nix build .#cowsay` will build the `cowsay` package from the current flake under the current system. `nix build` produces a `./result` symlink that points to the Nix store path containing the package: 209 | 210 | ```sh 211 | $ ./result/bin/cowsay hello 212 | _______ 213 | < hello > 214 | ------- 215 | \ ^__^ 216 | \ (oo)\_______ 217 | (__)\ )\/\ 218 | ||----w | 219 | || || 220 | ``` 221 | 222 | If you run `nix build` without arguments, it will default to `.#default`. 223 | 224 | #### Apps 225 | 226 | A flake app is similar to a flake package except it always refers to a runnable program. You can expose the cowsay executable from the cowsay package as the default flake app: 227 | 228 | ```nix 229 | { 230 | inputs = { 231 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 232 | }; 233 | 234 | outputs = inputs: { 235 | apps.x86_64-linux = { 236 | default = { 237 | type= "app"; 238 | program = "${inputs.nixpkgs.legacyPackages.x86_64-linux.cowsay}/bin/cowsay"; 239 | } ; 240 | }; 241 | }; 242 | } 243 | ``` 244 | 245 | Now, you can run `nix run` to run the cowsay app, which is equivalent to doing `nix build .#cowsay && ./result/bin/cowsay` in the previous flake. 246 | 247 | {#demo} 248 | #### Interlude: demo 249 | 250 | 251 | 252 | #### DevShells 253 | 254 | > [!info] To learn more 255 | > - [Official Nix manual][mkShell] 256 | > - [NixOS Wiki](https://nixos.wiki/wiki/Development_environment_with_nix-shell) 257 | 258 | Like `packages`, another predefined flake output is `devShells` - which is used to provide a [[dev|development]] shell aka. a nix [[shell|shell]] or devshell. A devshell is a sandboxed environment containing the packages and other shell environment you specify. nixpkgs provides a function called [`mkShell`][mkShell] that can be used to create devshells. 259 | 260 | As an example, we will update our `flake.nix` to provide a devshell that contains the [jq](https://github.com/stedolan/jq) tool. 261 | 262 | ```nix 263 | { 264 | inputs = { 265 | nixpkgs = { 266 | url = "github:NixOS/nixpkgs/nixos-unstable"; 267 | }; 268 | }; 269 | outputs = inputs: { 270 | foo = 42; 271 | devShells = { # nix develop 272 | aarch64-darwin = { 273 | default = 274 | let 275 | pkgs = inputs.nixpkgs.legacyPackages.aarch64-darwin; 276 | in pkgs.mkShell { 277 | packages = [ 278 | pkgs.jq 279 | ]; 280 | }; 281 | }; 282 | }; 283 | }; 284 | } 285 | ``` 286 | 287 | `nix flake show` will recognize this output as a "development environmenet": 288 | 289 | ```sh 290 | $ nix flake show 291 | path:/Users/srid/code/nixplay?lastModified=1675448105&narHash=sha256-dikTfYD1wbjc+vQ+IUTMXWv%2fm%2f7qb91Hk3ip5MNefeU= 292 | ├───devShells 293 | │ └───aarch64-darwin 294 | │ └───default: development environment 'nix-shell' 295 | └───foo: unknown 296 | ``` 297 | 298 | Just as `packages` can be built using `nix build`, you can enter the devshell using [`nix develop`][nix-develop]: 299 | 300 | ```sh 301 | $ nix develop 302 | ❯ which jq 303 | /nix/store/33n0kx526i5dnv2gf39qv1p3a046p9yd-jq-1.6-bin/bin/jq 304 | ❯ echo '{"foo": 42}' | jq .foo 305 | 42 306 | ❯ 307 | ``` 308 | 309 | Typing `Ctrl+D` or `exit` will exit the devshell. 310 | 311 | ## Conclusion 312 | 313 | This mini tutorial provided a rapid introduction to Nix flakes, enabling you to get started with writing simple flake for your projects. Consult the links above for more information. There is a lot more to Nix than the concepts presented here! You can also read [Zero to Nix][zero-to-nix] for a highlevel introduction to all things Nix and flakes. 314 | 315 | ## See also 316 | 317 | - [A (more or less) one page introduction to Nix, the language](https://github.com/tazjin/nix-1p) 318 | - [Nix - taming Unix with functional programming](https://www.tweag.io/blog/2022-07-14-taming-unix-with-nix/) 319 | 320 | [zero-to-nix]: https://zero-to-nix.com/ 321 | [nix-lang]: https://nixos.org/manual/nix/stable/language/index.html 322 | [nix-flake-show]: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake-show.html 323 | [nix-eval]: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-eval.html 324 | [nix-function]: https://nixos.org/manual/nix/stable/language/constructs.html#functions 325 | [mkShell]: https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell 326 | [exa]: https://github.com/ogham/exa 327 | [nix-build]: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-build.html 328 | [nix-develop]: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-develop.html 329 | [NixOS]: https://nixos.org/ 330 | -------------------------------------------------------------------------------- /en/nix-tutorial.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: -10 3 | --- 4 | 5 | # Nix Tutorial Series 6 | 7 | - [x] [[nix-first]]# 8 | - [x] [[nix-rapid]]# 9 | - [x] [[nix-modules]]# 10 | - [ ] `flake-parts` tutorial 11 | -------------------------------------------------------------------------------- /en/nix.md: -------------------------------------------------------------------------------- 1 | # Nix 2 | 3 | Nix is a [purely functional](https://www.tweag.io/blog/2022-07-14-taming-unix-with-nix/) package manager that also enables reproducible development environments. 4 | 5 | The Linux distro [[nixos]] comes with Nix pre-installed. You can [[install]] manually on other platforms. 6 | 7 | ```query 8 | children:. 9 | ``` -------------------------------------------------------------------------------- /en/nixify-haskell-flake.md: -------------------------------------------------------------------------------- 1 | --- 2 | short-title: 2. Using haskell-flake 3 | --- 4 | 5 | # Simplify Haskell Nix configuration using haskell-flake 6 | 7 | >[!warning] TODO: Write this! 8 | > For now, see the code: https://github.com/juspay/todo-app/pull/16 9 | 10 | Things to highlight: 11 | 12 | - haskell-flake reduces a bunch of lines to pretty much 1 13 | - whilst still allowing all the things you can do with raw nixpkgs infra 14 | - it can also support other package sets, like horizon 15 | - example projects (since todo-app has empty configuration) 16 | -------------------------------------------------------------------------------- /en/nixify-haskell-nixpkgs.md: -------------------------------------------------------------------------------- 1 | --- 2 | short-title: 1. Using nixpkgs only 3 | --- 4 | 5 | # Nixifying a Haskell project using nixpkgs 6 | 7 | Welcome to the [[nixify-haskell]] series, where we start our journey by integrating a Haskell application, particularly one using a PostgreSQL database, into a single-command deployable package. By the end of this article, you'll have a [[flakes|flake.nix]] file that's set to build the project, establish the [[dev|development environment]], and execute the Haskell application along with all its dependent services like PostgreSQL and [PostgREST]. We'll be using [todo-app](https://github.com/juspay/todo-app/tree/903c769d4bda0a8028fe3775415e9bdf29d80555) as a running case study throughout the series, demonstrating the process of building a Haskell project and effectively managing runtime dependencies, such as databases and other services, thereby illustrating the streamlined and powerful capabilities Nix introduces to Haskell development. 8 | 9 | [PostgREST]: https://postgrest.org/en/stable 10 | 11 | >[!warning] Pre-requisites 12 | > - A basic understanding of the [[nix]] and [[flakes]] is assumed. See [[nix-rapid]] 13 | > - To appreciate why Nix is a great choice for Haskell development, see [[why-dev]] 14 | 15 | ## Nixify Haskell package 16 | 17 | Let's build a simple flake for our Haskell project, `todo-app`. Start by cloning the [todo-app](https://github.com/juspay/todo-app/tree/903c769d4bda0a8028fe3775415e9bdf29d80555) repository and checking out the specified commit. 18 | 19 | ```sh 20 | git clone https://github.com/juspay/todo-app.git 21 | cd todo-app 22 | git checkout 076185e34f70e903b992b597232bc622eadfcd51 23 | ``` 24 | 25 | Here's a brief look at the `flake.nix` for this purpose: 26 | 27 | ```nix title="flake.nix" 28 | { 29 | inputs = { 30 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 31 | }; 32 | outputs = { self, nixpkgs }: 33 | let 34 | system = "aarch64-darwin"; 35 | pkgs = nixpkgs.legacyPackages.${system}; 36 | overlay = final: prev: { 37 | todo-app = final.callCabal2nix "todo-app" ./. { }; 38 | }; 39 | myHaskellPackages = pkgs.haskellPackages.extend overlay; 40 | in 41 | { 42 | packages.${system}.default = myHaskellPackages.todo-app; 43 | apps.${system}.default = { 44 | type = "app"; 45 | program = "${self.packages.${system}.default}/bin/todo-app"; 46 | }; 47 | }; 48 | } 49 | ``` 50 | 51 | Now, let's dissect it. 52 | 53 | ### haskellPackages 54 | 55 | The [official manual](https://nixos.org/manual/nixpkgs/stable/#haskell) explains the Haskell's infrastructure in [[nixpkgs]] detail. For our purposes, the main things to understand are: 56 | 57 | - `pkgs.haskellPackages` is an attribute set containing all Haskell packages within `nixpkgs`. 58 | - We can "extend" this package set to add our own Haskell packages. This is what we do when creating `myHaskellPackages`. 59 | - We add the `todo-app` package to `myHaskellPackages` (a package set derived from `pkgs.haskellPackages`), and then use that when defining the flake package, `packages.${system}.default`, below. 60 | 61 | >[!tip] Exploring `pkgs.haskellPackages` 62 | > 63 | > You can use [[repl]] to explore any flake's output. In the repl session below, we locate and build the `aeson` package: 64 | > 65 | > ```nix 66 | > nix repl github:nixos/nixpkgs/nixpkgs-unstable 67 | > nix-repl> pkgs = legacyPackages.${builtins.currentSystem} 68 | > 69 | > nix-repl> pkgs.haskellPackages.aeson 70 | > «derivation /nix/store/sjaqjjnizd7ybirh94ixs51x4n17m97h-aeson-2.0.3.0.drv» 71 | > 72 | > nix-repl> :b pkgs.haskellPackages.aeson 73 | > 74 | > This derivation produced the following outputs: 75 | > doc -> /nix/store/xjvm45wxqasnd5p2kk9ngcc0jbjhx1pf-aeson-2.0.3.0-doc 76 | > out -> /nix/store/1dc6b11k93a6j9im50m7qj5aaa5p01wh-aeson-2.0.3.0 77 | > ``` 78 | 79 | 80 | ### callCabal2nix 81 | 82 | We used `callCabal2nix` function from [[nixpkgs]] to build the `todo-app` package above. This functio generates a Haskell package [[drv]] from its source, utilizing the ["cabal2nix"](https://github.com/NixOS/cabal2nix) program to convert a cabal file into a Nix derivation. 83 | 84 | 85 | ### Overlay 86 | 87 | > [!info] 88 | > - [NixOS Wiki on Overlays](https://nixos.wiki/wiki/Overlays) 89 | > - [Overlay implementation in fixed-points.nix](https://github.com/NixOS/nixpkgs/blob/master/lib/fixed-points.nix)> 90 | 91 | To _extend_ the `pkgs.haskellPackages` package set above, we had to pass what is known as an "overlay". This allows us to either override an existing package or add a new one. 92 | 93 | In the repl session below, we extend the default Haskell package set to override the `shower` package to be built from the Git repo instead: 94 | 95 | ```nix 96 | nix-repl> :b pkgs.haskellPackages.shower 97 | 98 | This derivation produced the following outputs: 99 | doc -> /nix/store/crzcx007h9j0p7qj35kym2rarkrjp9j1-shower-0.2.0.3-doc 100 | out -> /nix/store/zga3nhqcifrvd58yx1l9aj4raxhcj2mr-shower-0.2.0.3 101 | 102 | nix-repl> myHaskellPackages = pkgs.haskellPackages.extend 103 | (self: super: { 104 | shower = self.callCabal2nix "shower" 105 | (pkgs.fetchgit { 106 | url = "https://github.com/monadfix/shower.git"; 107 | rev = "2d71ea1"; 108 | sha256 = "sha256-vEck97PptccrMX47uFGjoBVSe4sQqNEsclZOYfEMTns="; 109 | }) {}; 110 | }) 111 | 112 | nix-repl> :b myHaskellPackages.shower 113 | 114 | This derivation produced the following outputs: 115 | doc -> /nix/store/vkpfbnnzyywcpfj83pxnj3n8dfz4j4iy-shower-0.2.0.3-doc 116 | out -> /nix/store/55cgwfmayn84ynknhg74bj424q8fz5rl-shower-0.2.0.3 117 | ``` 118 | 119 | Notice how we used `callCabal2nix` to build a new Haskell package from the source (located in the specified Git repository). 120 | 121 | 122 | 123 | {#together} 124 | ### Putting It All Together 125 | 126 | 127 | {#devshell} 128 | ## Nixifying Development Shells 129 | 130 | Our existing flake lets us _build_ `todo-app`. But what if we want to _develop_ it? Typically, Haskell development involves tools like [cabal](https://cabal.readthedocs.io/) and [ghcid](https://github.com/ndmitchell/ghcid). These tools require a GHC environment with the packages specified in the `build-depends` of our cabal file. This is where `devShell` comes in, providing an isolated environment with all packages required by the project. 131 | 132 | Here's the `flake.nix` for setting up a development shell: 133 | 134 | ```nix title="flake.nix" 135 | { 136 | inputs = { 137 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 138 | }; 139 | outputs = { self, nixpkgs }: 140 | let 141 | system = "aarch64-darwin"; 142 | pkgs = nixpkgs.legacyPackages.${system}; 143 | overlay = final: prev: { 144 | todo-app = final.callCabal2nix "todo-app" ./. { }; 145 | }; 146 | myHaskellPackages = pkgs.haskellPackages.extend overlay; 147 | in 148 | { 149 | devShells.${system}.default = myHaskellPackages.shellFor { 150 | packages = p : [ 151 | p.todo-app 152 | ]; 153 | nativeBuildInputs = with myHaskellPackages; [ 154 | ghcid 155 | cabal-install 156 | ]; 157 | }; 158 | }; 159 | } 160 | ``` 161 | 162 | ### shellFor 163 | 164 | A Haskell [[dev|devShell]] can be provided in one of the two ways. The default way is to use the (language-independent) `mkShell` function (Generic shell). However to get full IDE support, it is best to use the (haskell-specific) `shellFor` function, which is an abstraction over [`mkShell`](https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell) geared specifically for Haskell development shells 165 | 166 | - Every Haskell package set (such as `pkgs.haskellPackages`), exposes [`shellFor`](https://nixos.wiki/wiki/Haskell#Using_shellFor_.28multiple_packages.29) function, which returns a devShell with GHC package set configured with the Haskell packages in that package set. 167 | - As arguments to `shellFor` - generally, we only need to define two keys `packages` and `nativeBuildInputs`. 168 | - `packages` refers to *local* Haskell packages (that will be compiled by cabal rather than Nix). 169 | - `nativeBuildInputs` refers to programs to make available in the `PATH` of the devShell. 170 | 171 | ### Let's run! 172 | 173 | 174 | {#ext-deps} 175 | ## Nixifying External Dependencies 176 | 177 | We looked at how to package a Haskell package, and thereon how to setup a development shell. Now we come to the final part of this tutorial, where we will see how to package external dependencies (like Postgres). We will demonstrate how to initiate a Postgres server using Nix without altering the global system state. 178 | 179 | Here's the `flake.nix` for making `nix run .#postgres` launch a Postgres server: 180 | 181 | ```nix title="flake.nix" 182 | { 183 | inputs = { 184 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 185 | }; 186 | outputs = { self, nixpkgs }: 187 | let 188 | system = "aarch64-darwin"; 189 | pkgs = nixpkgs.legacyPackages.${system}; 190 | in 191 | { 192 | apps.${system}.postgres = { 193 | type = "app"; 194 | program = 195 | let 196 | script = pkgs.writeShellApplication { 197 | name = "pg_start"; 198 | runtimeInputs = [ pkgs.postgresql ]; 199 | text = 200 | '' 201 | # Initialize a database with data stored in current project dir 202 | [ ! -d "./data/db" ] && initdb --no-locale -D ./data/db 203 | 204 | postgres -D ./data/db -k "$PWD"/data 205 | ''; 206 | }; 207 | in "${script}/bin/pg_start"; 208 | }; 209 | }; 210 | } 211 | ``` 212 | 213 | This flake defines a flake app that can be run using `nix run`. This app is simply a shell script that starts a Postgres server. [[nixpkgs]] provides the convenient [[writeShellApplication]] function to generate such a script. Note that `"${script}"` provides the path in the `nix/store` where the application is located. 214 | 215 | ### Run it! 216 | 217 | 218 | {#combine} 219 | ## Combining All Elements 220 | 221 | 222 | Now it's time to consolidate all the previously discussed sections into a single `flake.nix`. Additionally, we should incorporate the necessary apps for `postgrest` and `createdb`. `postgrest` app will start the service and `createdb` will handle tasks such as loading the database dump, creating a database user, and configuring the database for postgREST. 223 | 224 | ```nix title="flake.nix" 225 | { 226 | inputs = { 227 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 228 | }; 229 | outputs = { self, nixpkgs }: 230 | let 231 | system = "aarch64-darwin"; 232 | pkgs = nixpkgs.legacyPackages.${system}; 233 | overlay = final: prev: { 234 | todo-app = final.callCabal2nix "todo-app" ./. { }; 235 | }; 236 | myHaskellPackages = pkgs.haskellPackages.extend overlay; 237 | in 238 | { 239 | packages.${system}.default = myHaskellPackages.todo-app; 240 | 241 | devShells.${system}.default = myHaskellPackages.shellFor { 242 | packages = p: [ 243 | p.todo-app 244 | ]; 245 | buildInputs = with myHaskellPackages; [ 246 | ghcid 247 | cabal-install 248 | haskell-language-server 249 | ]; 250 | }; 251 | 252 | apps.${system} = { 253 | default = { 254 | type = "app"; 255 | program = "${self.packages.${system}.default}/bin/todo-app"; 256 | }; 257 | postgres = { 258 | type = "app"; 259 | program = 260 | let 261 | script = pkgs.writeShellApplication { 262 | name = "pg_start"; 263 | runtimeInputs = [ pkgs.postgresql ]; 264 | text = 265 | '' 266 | # Initialize a database with data stored in current project dir 267 | [ ! -d "./data/db" ] && initdb --no-locale -D ./data/db 268 | 269 | postgres -D ./data/db -k "$PWD"/data 270 | ''; 271 | }; 272 | in 273 | "${script}/bin/pg_start"; 274 | }; 275 | createdb = { 276 | type = "app"; 277 | program = 278 | let 279 | script = pkgs.writeShellApplication { 280 | name = "createDB"; 281 | runtimeInputs = [ pkgs.postgresql ]; 282 | text = 283 | '' 284 | # Create a database of your current user 285 | if ! psql -h "$PWD"/data -lqt | cut -d \| -f 1 | grep -qw "$(whoami)"; then 286 | createdb -h "$PWD"/data "$(whoami)" 287 | fi 288 | 289 | # Load DB dump 290 | psql -h "$PWD"/data < db.sql 291 | 292 | # Create configuration file for postgrest 293 | echo "db-uri = \"postgres://authenticator:mysecretpassword@localhost:5432/$(whoami)\" 294 | db-schemas = \"api\" 295 | db-anon-role = \"todo_user\"" > data/db.conf 296 | ''; 297 | }; 298 | in 299 | "${script}/bin/createDB"; 300 | }; 301 | postgrest = { 302 | type = "app"; 303 | program = 304 | let 305 | script = pkgs.writeShellApplication { 306 | name = "pgREST"; 307 | runtimeInputs = [ myHaskellPackages.postgrest ]; 308 | text = 309 | '' 310 | postgrest ./data/db.conf 311 | ''; 312 | }; 313 | in 314 | "${script}/bin/pgREST"; 315 | }; 316 | }; 317 | }; 318 | } 319 | ``` 320 | 321 | For the complete souce code, visit [here](https://github.com/juspay/todo-app/tree/tutorial/1). 322 | 323 | >[!note] `forAllSystems` 324 | > The source code uses [`forAllSystems`](https://zero-to-nix.com/concepts/flakes#system-specificity), which was not included in the tutorial above to maintain simplicity. Later, we will obviate `forAllSystems` and simplify the flake further using [[flake-parts]]. 325 | 326 | ### Video Walkthrough 327 | 328 | 329 | 330 | ## Conclusion 331 | 332 | This tutorial pratically demonstrated [[why-dev|why Nix is a great choice for Haskell development]]: 333 | 334 | - **Instantaneous Onboarding**: There is no confusion about how to setup the development environment. It is `nix run .#postgres` to start the postgres server, 335 | `nix run .#createdb` to setup the database and `nix run .#postgrest` to start the Postgrest web server. This happens in a reproducible way, ensuring every 336 | developer gets the same environment. 337 | - **Boosted Productivity**: The commands mentioned in the previous points in conjunction with `nix develop` is all that is needed to make a quick change 338 | and see it in effect. 339 | - **Multi-Platform Support**: All the commands mentioned in the previous points will work in the same way across platforms. 340 | 341 | In the next tutorial part, we will modularize this `flake.nix` using [[flake-parts]]. 342 | -------------------------------------------------------------------------------- /en/nixify-haskell-parts.md: -------------------------------------------------------------------------------- 1 | --- 2 | short-title: 2. Using flake-parts 3 | --- 4 | 5 | # Modularize our flake using flake-parts 6 | 7 | >[!warning] TODO: Write this! 8 | > For now, see the code: https://github.com/juspay/todo-app/pull/9 9 | 10 | Things to highlight: 11 | 12 | - [[flake-parts]] can be used as lightweight `forAllSystems` alternative 13 | - allows us to split top-level flake.nix into small .nix files 14 | - allows us to define [[nix-modules|our own modules]] and use them (just like [[nixos]] options) 15 | - nuts and bolts: 16 | - perSystem, and its args (`self'`, etc.) 17 | - `debug` option and inspecting in repl 18 | -------------------------------------------------------------------------------- /en/nixify-haskell.md: -------------------------------------------------------------------------------- 1 | 2 | # Nixify Haskell projects 3 | 4 | This is a #[[tutorial|tutorial]] series on nixifying #[[haskell]] projects. In part 1, we will begin with using nothing but [[nixpkgs]]. In the latter parts, we'll use simplifiy our project Nix code through [haskell-flake] which builds on top of the Haskell infrastructure in [[nixpkgs]].[^other] 5 | 6 | 1. [x] [[nixify-haskell-nixpkgs]]# 7 | 2. [ ] [[nixify-haskell-parts]]# 8 | 3. [ ] [[nixify-haskell-flake]]# 9 | 4. [ ] [[nixify-services-flake]]# 10 | 11 | [^other]: There are also other approaches (like [haskell.nix](https://github.com/input-output-hk/haskell.nix), [stacklock2nix](https://github.com/cdepillabout/stacklock2nix)). 12 | 13 | [haskell-flake]: https://github.com/srid/haskell-flake 14 | -------------------------------------------------------------------------------- /en/nixify-services-flake.md: -------------------------------------------------------------------------------- 1 | --- 2 | short-title: 4. Using services-flake 3 | --- 4 | 5 | # Integrating external services using services-flake 6 | 7 | >[!warning] TODO: Write this! 8 | > For now, see the code: https://github.com/juspay/todo-app/pull/22 9 | 10 | Things to highlight: 11 | 12 | - `services-flake` provides pre-defined configurations for many services, reducing a bunch of lines to just `services...enable = true;` 13 | - Data directory for all services in `services-flake` is local to the project working directory, by default 14 | - Best practices: 15 | - Use Unix sockets for local development and CI to avoid binding to ports (which is global to the interface) 16 | - Write integration tests using the reserved `test` process in `process-compose-flake`. 17 | -------------------------------------------------------------------------------- /en/nixos-install-disko.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: 2 3 | page: 4 | image: nixos-install-disko/nixos-disko-config.jpeg 5 | --- 6 | 7 | # Install NixOS with `disko` disk partitioning 8 | 9 | In this second tutorial, we will walk you through the process of installing [[nixos|NixOS]]. Unlike [[nixos-install-flake|the first installation tutorial]], we will use the command line to install NixOS manually, except for using [disko] to specify disk partitions declaratively in [[nix|Nix]] itself. This is the first step toward our [[nixos-install-oneclick|next tutorial]], where we will automate the entire installation process. 10 | 11 | 12 | [disko]: https://github.com/nix-community/disko 13 | 14 | {#prepare} 15 | ## Prepare to install NixOS 16 | 17 | 18 | >[!note] Minimal ISO image 19 | > This tutorial doesn't use a [[nixos-install-flake|graphical installer]]. Instead, it uses the minimal ISO image. This is primarily because we don't want the installer to partion the disk for us. We will use [disko](https://github.com/nix-community/disko) to do that. 20 | 21 | - Download the latest NixOS ISO from [here](https://nixos.org/download#download-nixos). Choose the "Minimal ISO image" for your architecture. 22 | - Create a bootable USB flash drive ([instructions here](https://nixos.org/manual/nixos/stable/index.html#sec-booting-from-usb)) 23 | 24 | Boot your computer from this USB flash drive, and expect to be greeted with a command line interface (CLI): 25 | 26 | :::{.center} 27 | ![[nixos-installer-cli.jpeg]] 28 | ::: 29 | 30 | {#partition} 31 | ## Partition the disk 32 | 33 | Before installing NixOS, let's define our partition layout in Nix. We will follow [the official disko documentation](https://github.com/nix-community/disko/blob/master/docs/quickstart.md) and include screenshots wherever necessary. Finally, we will use flakes to manage the configuration. 34 | 35 | {#disk-config} 36 | ### Choosing the disk configuration 37 | 38 | Instead of creating our partition layout from scratch, we can choose one of the examples Disko itself provides (see [here](https://github.com/nix-community/disko/tree/master/example)). We will use the [hybrid](https://github.com/nix-community/disko/blob/master/example/hybrid.nix) example as it will work for both BIOS and UEFI systems. 39 | 40 | Retrieve the disk configuration to a temporary location, calling it `disko-config.nix` (we will use it latter): 41 | 42 | ```bash 43 | curl https://raw.githubusercontent.com/nix-community/disko/master/example/hybrid.nix -o /tmp/disko-config.nix 44 | ``` 45 | 46 | {#disk-config-edit} 47 | ### Modify the disk configuration 48 | 49 | The above downloaded Nix file uses a hardcoded disk device. So, we need to replace it with the device name of the disk we want to install [[nixos]] on. We can use `lsblk` to find it. 50 | 51 | 52 | :::{.center} 53 | ![[nixos-lsblk.jpeg]] 54 | ::: 55 | 56 | In this case, the device name is `vda`. The device file is located at `/dev/vda`. We will use this to modify `disko-config.nix` we downloaded earlier. 57 | 58 | :::{.center} 59 | ![[nixos-disko-config.jpeg]] 60 | ::: 61 | 62 | ### Run the partitioning script 63 | 64 | The disko flake provides an app that will take our partitioning scheme defined in Nix file above, partition the specified disk device and mount it at `/mnt`. We want this to happen prior to installing NixOS. Let's do that now: 65 | 66 | ```bash 67 | sudo nix \ 68 | --experimental-features "nix-command flakes" \ 69 | run github:nix-community/disko -- \ 70 | --mode disko /tmp/disko-config.nix 71 | ``` 72 | 73 | Once the command completes, you should see the disk partitioned and mounted at `/mnt`: 74 | 75 | :::{.center} 76 | ![[nixos-disko-post-partition.jpeg]] 77 | ::: 78 | 79 | {#configuration} 80 | ## Generate initial NixOS configuration 81 | 82 | With the disk partitioned, we are ready to follow the usual NixOS installation process. The first step is to generate the initial NixOS configuration under `/mnt`. 83 | 84 | ```bash 85 | sudo nixos-generate-config --no-filesystems --root /mnt 86 | ``` 87 | 88 | > [!tip] Why `--no-filesystems` and `--root`? 89 | > - The [fileSystems](https://search.nixos.org/options?channel=23.11&show=fileSystems&from=0&size=50&sort=relevance&type=packages&query=fileSystems) configuration will automatically be added by `disko`'s [nixosModule](https://nixos.wiki/wiki/NixOS_modules) (see below). Therefore, we use `--no-filesystems` to avoid generating it here. 90 | > - `--root` is to specify the mountpoint to generate `configuration.nix` and `hardware-configuration.nix` in. Here, our configuration will be generated in `/mnt/etc/nixos`. 91 | 92 | {#flakeify} 93 | ## Flakeify the configuration 94 | 95 | Before we can utilize `disko` in our generated configuration, we will [[configuration-as-flake|convert our configuration to a flake]]. This is a simple process of adding a `flake.nix` file in `/mnt/etc/nixos`: 96 | 97 | ```bash 98 | # /mnt/etc/nixos/flake.nix 99 | { 100 | inputs = { 101 | # NOTE: Replace "nixos-23.11" with that which is in system.stateVersion of 102 | # configuration.nix. You can also use latter versions if you wish to 103 | # upgrade. 104 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; 105 | }; 106 | outputs = inputs@{ self, nixpkgs, ... }: { 107 | # NOTE: 'nixos' is the default hostname set by the installer 108 | nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { 109 | # NOTE: Change this to aarch64-linux if you are on ARM 110 | system = "x86_64-linux"; 111 | modules = [ ./configuration.nix ]; 112 | }; 113 | }; 114 | } 115 | ``` 116 | 117 | > [!note] Make sure to change a couple of things in the above snippet: 118 | > - Replace `nixos-23.11` with the version from [`system.stateVersion`](https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion) in your `/mnt/etc/nixos/configuration.nix`. If you wish to upgrade right away, you can also use latter versions, or use `nixos-unstable` for the bleeding edge. 119 | > - `x86_64-linux` should be `aarch64-linux` if you are on ARM 120 | 121 | For details, see [[configuration-as-flake]]. 122 | 123 | {#add-disko} 124 | ## Add the `disko` nixosModule 125 | 126 | Our NixOS configuration still does not know anything about filesystems. Let's teach it just that by using the previously downloaded disko example. We do this by adding the `disko` flake input, importing its NixOS module before importing our `/tmp/disko-config.nix`. 127 | 128 | 1. Add the `disko` flake input in `/mnt/etc/nixos/flake.nix`: 129 | 130 | ```nix 131 | # In `/mnt/etc/nixos/flake.nix` 132 | { 133 | inputs = { 134 | disko.url = "github:nix-community/disko"; 135 | disko.inputs.nixpkgs.follows = "nixpkgs"; 136 | }; 137 | } 138 | ``` 139 | >[!info] Why the "follows"? 140 | > `disko.inputs.nixpkgs.follows = "nixpkgs";` is to ensure that `disko` uses the same version of `nixpkgs` as specified in the current flake. This avoids having two different sources of `nixpkgs` and saves space. 141 | 142 | 1. Add the `disko` nixosModule: 143 | 144 | ```nix 145 | { 146 | # In `outputs` of `/mnt/etc/nixos/flake.nix` 147 | nixosConfigurations.nixos = { 148 | # ... 149 | modules = [ 150 | ./configuration.nix 151 | inputs.disko.nixosModules.disko 152 | ]; 153 | }; 154 | } 155 | ``` 156 | :::{.center} 157 | ![[nixos-flake-with-disko.jpeg]] 158 | ::: 159 | 160 | 1. Move the `disko-config.nix` to the flake directory: 161 | 162 | ```bash 163 | mv /tmp/disko-config.nix /mnt/etc/nixos 164 | ``` 165 | 166 | 1. Add the disk configuration and use GRUB: 167 | 168 | ```nix 169 | { 170 | # In `/mnt/etc/nixos/configuration.nix` 171 | imports = [ 172 | ./hardware-configuration.nix 173 | ./disko-config.nix 174 | ]; 175 | #boot.loader.systemd-boot.enable = true; 176 | #boot.loader.efi.canTouchEfiVariables = true; 177 | boot.loader.grub.enable = true; 178 | boot.loader.grub.efiSupport = true; 179 | boot.loader.grub.efiInstallAsRemovable = true; 180 | } 181 | ``` 182 | :::{.center} 183 | ![[nixos-configuration-nix-with-disko-config.jpeg]] 184 | ::: 185 | 186 | >[!info] 187 | > The boot loader configuration above is compatible with both BIOS and UEFI systems. Additionally, BIOS also requires [boot.loader.grub.device](https://search.nixos.org/options?channel=23.11&show=boot.loader.grub.device&from=0&size=50&sort=relevance&type=packages&query=boot.loader.grub.device) to be set which is done by `disko`'s `nixosModule`. 188 | 189 | Let's check that our final configuration is correct by using [[repl]]. In particular, we test the `fileSystems` set by `disko`: 190 | 191 | ```sh 192 | # First, create a flake.lock 193 | sudo nix --experimental-features "nix-command flakes" flake lock 194 | 195 | # Start repl 196 | nix --experimental-features "nix-command flakes" repl 197 | ``` 198 | 199 | :::{.center} 200 | ![[nixos-disko-filesystems.jpeg]] 201 | ::: 202 | 203 | If you see something similar to the above, everything's good and we are ready to perform the actual installation. 204 | 205 | {#install} 206 | ## Install NixOS 207 | 208 | With our NixOS configuration in place, we will use the `nixos-install` program to install NixOS: 209 | 210 | ```bash 211 | sudo nixos-install --root /mnt --flake '/mnt/etc/nixos#nixos' 212 | # NOTE: You will be prompted to set the root password at this point. 213 | sudo reboot 214 | ``` 215 | 216 | Once rebooted, you should be greeted with the NixOS login screen, allowing you to login to the machine using the root password you had set. 217 | 218 | {#bonus} 219 | ## Bonus steps 220 | 221 | This tutorial focused mostly on [disko], but left some of the things covered in [[nixos-install-flake|the previous tutorial]] which you might want to consider: 222 | 223 | - [Move configuration to home dir](configuration-as-flake.md#homedir) 224 | - [Store the configuration on Git](nixos-install-flake.md#git) 225 | - [Enable flakes](nixos-install-flake.md#enable-flakes) 226 | 227 | {#video} 228 | ## Video walkthrough 229 | 230 |
231 | 232 |
233 | 234 | {#end} 235 | ## Recap & next steps 236 | 237 | You now have a reproducible disk partitioning scheme. This does come at the cost of a few extra manual steps, but you can automate them with a script. Which is what we will do in [[nixos-install-oneclick|the next tutorial]]. We will use [nixos-anywhere](https://github.com/nix-community/nixos-anywhere) to automate the steps above and eliminate the need for a USB flash drive (assuming you have a working Linux system or are booted into a rescue image). 238 | -------------------------------------------------------------------------------- /en/nixos-install-flake.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: 1 3 | page: 4 | image: nixos-install-flake/nixos-install-flake.png 5 | --- 6 | 7 | # Install NixOS with Flake configuration on Git 8 | 9 | This tutorial will walk you through the steps necessary to install [[nixos|NixOS]], enable [[flakes|flakes]] while tracking the resulting system configuration in a [[git|Git]] repository. 10 | 11 | >[!info] Welcome to the tutorial series on [[nixos]] 12 | > This page is the first in a planned series of tutorials aimed towards onboarding Linux/macOS users into comfortably using [[nixos]] as their primary operating system. 13 | 14 | ![[nixos-install-flake.png]] 15 | 16 | {#prepare} 17 | ## Prepare to install NixOS 18 | 19 | - Download the latest NixOS ISO from [here](https://nixos.org/download#download-nixos). Choose the GNOME (or Plasma) graphical ISO image for the appropriate CPU architecture. 20 | - Create a bootable USB flash drive ([instructions here](https://nixos.org/manual/nixos/stable/index.html#sec-booting-from-usb)) and boot the computer from it. 21 | 22 | NixOS will boot into a graphical environment with the installer already running. 23 | 24 | :::{.center} 25 | ![[nixos-installer.png]] 26 | ::: 27 | 28 | Go through the installation wizard; it is fairly similar to other distros. Once NixOS install is complete, reboot into your new system. You will be greeted with a login screen. 29 | 30 | - Login as the user you created with the password you set during installation. 31 | - Then open the "Console" application from the "Activities" menu. 32 | 33 | {#edit} 34 | ## Your first `configuration.nix` change 35 | 36 | 37 | Your systems configuration includes everything from partition layout to kernel version to packages to services. It is defined in `/etc/nixos/configuration.nix`. The `/etc/nixos` directory looks like this: 38 | 39 | ```sh 40 | $ ls -l /etc/nixos 41 | -rw-r--r-- 1 root root 4001 Dec 9 16:03 configuration.nix 42 | -rw-r--r-- 1 root root 1317 Dec 9 15:43 hardware-configuration.nix 43 | 44 | ``` 45 | 46 | >[!info] What is `hardware-configuration.nix`? 47 | > Hardware specific configuration (eg: disk partitions to mount) are defined in `/etc/nixos/hardware-configuration.nix` which is `import`ed, as a [[modules|module]], by `configuration.nix`. 48 | 49 | All system changes require a change to this `configuration.nix`. For example, in order to "install" or "uninstall" a package, we would edit this `configuration.nix` and activate it. Let's do this now to install the [neovim](https://neovim.io/) text editor. NixOS includes the nano editor by default: 50 | 51 | ```sh 52 | sudo nano /etc/nixos/configuration.nix 53 | ``` 54 | 55 | >[!tip] Nix language 56 | > These `*.nix` files are written in the [[nix]] language. 57 | 58 | In the text editor, make the following changes: 59 | 60 | - Add `neovim` under `environment.systemPackages` 61 | - [Optional] uncomment `services.openssh.enable = true;` to enable the SSH server 62 | 63 | Press Ctrl+X to exit nano. 64 | 65 | Your `configuration.nix` should now look like: 66 | 67 | ```nix 68 | # /etc/nixos/configuration.nix 69 | { 70 | ... 71 | environment.systemPackages = with pkgs; [ 72 | neovim 73 | ]; 74 | ... 75 | services.openssh.enable = true; 76 | ... 77 | } 78 | ``` 79 | 80 | Once the `configuration.nix` file has been saved to disk, you must activate that new configuration using the [nixos-rebuild](https://nixos.wiki/wiki/Nixos-rebuild) command: 81 | 82 | ```sh 83 | sudo nixos-rebuild switch 84 | ``` 85 | 86 | This will take a few minutes to complete―as it will have to fetch neovim and its dependencies from the official [[cache|binary cache]] (`cache.nixos.org`). Once it is done, you should expect to see something like this: 87 | 88 | :::{.center} 89 | ![[nixos-rebuild-switch.png]] 90 | ::: 91 | 92 | You can confirm that neovim is installed by running `which nvim`: 93 | 94 | ```sh 95 | $ which nvim 96 | /run/current-system/sw/bin/nvim 97 | ``` 98 | 99 | >[!tip] Remote access 100 | > Now that you have OpenSSH enabled, you may do the rest of the steps from another machine by ssh'ing to this machine. 101 | 102 | {#flakeify} 103 | ## Flakeify 104 | 105 | ![[configuration-as-flake]] 106 | 107 | Let's [[configuration-as-flake|store our whole configuration]]# in a [[git]] repository. 108 | 109 | {#git} 110 | ## Store the configuration in Git 111 | 112 | First we need to install [[git]]: 113 | - add `git` to `environment.systemPackages`, and 114 | - activate your new configuration using `sudo nixos-rebuild switch --flake .`. 115 | 116 | Then, create a Git repository for your configuration: 117 | 118 | 119 | ```sh 120 | $ cd ~/nixos-config 121 | $ git config --global user.email "srid@srid.ca" 122 | $ git config --global user.name "Sridhar Ratnakumar" 123 | $ git init && git add . && git commit -m init 124 | ``` 125 | 126 | You may now [create a repository](https://docs.github.com/en/get-started/quickstart/create-a-repo) on GitHub or your favourite Git host, and push your configuration repo to it. 127 | 128 | >[!info] Benefits of storing configuration on Git 129 | > - If you buy a new computer, and would like to reproduce your NixOS setup, all you have to do is clone your configuration repo, adjust your `hardware-configuration.nix` and run `sudo nixos-rebuild switch --flake .`. 130 | > - Version controlling configuration changes makes it straightforward to point out problems and/or rollback to previous state. 131 | 132 | 133 | {#enable-flakes} 134 | ## Enable flakes 135 | 136 | As a final step, let's permanently enable [[flakes]] on our system, which is particularly useful if you do a lot of [[dev|software development]]. This time, instead of editing `configuration.nix` again, let's do it in a separate [[modules|module]] (for no particular reasons other than pedagogic purposes). Remember the `modules` argument to `nixosSystem` function in our `flake.nix`? It is a list of modules, so we can add a second module there: 137 | 138 | ```diff 139 | diff --git a/flake.nix b/flake.nix 140 | index cc77fb9..4e84bdf 100644 141 | --- a/flake.nix 142 | +++ b/flake.nix 143 | @@ -8,7 +8,14 @@ 144 | # NOTE: 'nixos' is the default hostname 145 | nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { 146 | system = "x86_64-linux"; 147 | - modules = [ ./configuration.nix ]; 148 | + modules = [ 149 | + ./configuration.nix 150 | + { 151 | + nix = { 152 | + settings.experimental-features = [ "nix-command" "flakes" ]; 153 | + }; 154 | + } 155 | + ]; 156 | }; 157 | }; 158 | } 159 | ``` 160 | 161 | >[!tip] NixOS options 162 | > You can see all the available options for NixOS in the [NixOS options](https://search.nixos.org/options) search engine. 163 | 164 | As before, we must activate the new configuration using `sudo nixos-rebuild switch --flake .`. Once that is done, we can verify that flakes is enabled by re-running `nix flake show` but without the `--extra-experimental-features` flag: 165 | 166 | ```sh 167 | $ nix flake show 168 | warning: Git tree '/home/srid/nixos-config' is dirty 169 | git+file:///home/srid/nixos-config 170 | └───nixosConfigurations 171 | └───nixos: NixOS configuration 172 | ``` 173 | 174 | ## Recap 175 | 176 | You have successfully installed NixOS. The entire system configuration is also stored in a Git repo, and can be reproduced at will during either a reinstallation or a new machine purchase. You can make changes to your configuration, commit them to Git, and push it to GitHub. Additionally we enabled [[flakes]] permanently, which means you can now use all the modern `nix` commands, such as running a package directly from [[nixpkgs]] (same version pinned in `flake.lock` file): 177 | 178 | :::{.center} 179 | ![[nixos-pony.png]] 180 | ::: 181 | 182 | 183 | {#end} 184 | ## Up Next 185 | 186 | In [[nixos-install-disko|the next tutorial]], we will automate the install process a bit by declaratively specifying our disk partitioning in Nix. 187 | 188 | -------------------------------------------------------------------------------- /en/nixos-install-oneclick.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: 3 3 | --- 4 | 5 | # Install NixOS directly from a remote flake 6 | 7 | >[!WARNING] WIP 8 | > This tutorial has not been completed yet. 9 | 10 | Unlike the previous tutorials ([[nixos-install-flake|1]]; [[nixos-install-disko|2]]), the goal here is to near-fully automate our NixOS install using one command (see the next section). 11 | 12 | {#install} 13 | ## How to install 14 | 15 | Boot your computer from any NixOS install live CD ([Minimal ISO image](https://nixos.org/download/#nixos-iso) is sufficient), and then from the terminal run: 16 | 17 | >[!NOTE] Flake template? 18 | > Move this template to [flake-parts/templates](https://github.com/flake-parts/templates) and guide users as to how to [override](https://github.com/flake-parts/templates/issues/2) it (to set `system`, hostname and root user's authorized ssh key)? 19 | 20 | ```sh 21 | # Assuming 22 | # - your system is x86_64-linux 23 | # - your harddrive device is /dev/sda 24 | FLAKE="github:nixos-asia/website?dir=global/nixos-install-oneclick#oneclick" 25 | DISK_DEVICE=/dev/sda 26 | sudo nix \ 27 | --extra-experimental-features 'flakes nix-command' \ 28 | run github:nix-community/disko#disko-install -- \ 29 | --flake "$FLAKE" \ 30 | --write-efi-boot-entries \ 31 | --disk main "$DISK_DEVICE" 32 | ``` 33 | 34 | Here, `"github:nixos-asia/website?dir=global/nixos-install-oneclick#oneclick"` is [our own sample configuration](https://github.com/nixos-asia/website/tree/master/global/nixos-install-oneclick) flake. Feel free to substitute it with your own flake. 35 | 36 | If everything goes well, you should see the installation successfully finish with a message like below: 37 | 38 | ```text 39 | ... 40 | Random seed file /boot/loader/random-seed successfully written (32 bytes). 41 | Successfully initialized system token in EFI variable with 32 bytes. 42 | Created EFI boot entry "Linux Boot Manager". 43 | installation finished! 44 | ``` 45 | 46 | 1. Take note of the IP address of your machine using `ifconfig`. 47 | 1. Reboot your computer (or VM)! Expect to boot into NixOS. 48 | 1. Test ssh access using `ssh root@` 49 | 50 | ## User management 51 | 52 | The above flake is meant to be used on a server. As such, it authorizes root access through SSH keys. 53 | 54 | - [ ] If you are setting up a desktop, you may have to ... 55 | 56 | ## Making further changes to the flake 57 | 58 | - [ ] After install, how do we make further changes to the flake and apply that configuration? Can we simplify this? 59 | 60 | 61 | This worked: 62 | 63 | ```sh 64 | [root@oneclick:~]# git clone https://github.com/nixos-asia/website.git 65 | 66 | [root@oneclick:~]# cd website/global/nixos-install-oneclick/ 67 | 68 | [root@oneclick:~/website/global/nixos-install-oneclick]# sudo nixos-rebuild switch --flake . 69 | ``` 70 | -------------------------------------------------------------------------------- /en/nixos-tutorial.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: -7 3 | --- 4 | 5 | # NixOS Tutorial Series 6 | 7 | - [x] **Installation** 8 | 9 | Choose from *one of* the following ways to install [[nixos]]: 10 | 11 | | Tutorial | Description | 12 | | ------------------------------- | ----------------------------------------------------------------------- | 13 | | [x] [[nixos-install-flake]]# | Install NixOS the easy way, using graphical installer | 14 | | [x] [[nixos-install-disko]]# | Partially automated install; disko used for automatic disk partitioning | 15 | | [ ] [[nixos-install-oneclick]]# | Fully automated install using an *existing* configuration | 16 | - [ ] Basics 17 | - [ ] Services -------------------------------------------------------------------------------- /en/nixos.md: -------------------------------------------------------------------------------- 1 | # NixOS 2 | 3 | NixOS is a Linux distribution based on the [[nix]] package manager. 4 | 5 | ## Getting Started 6 | 7 | See [[nixos-tutorial]]# 8 | 9 | ```query 10 | children:. 11 | ``` -------------------------------------------------------------------------------- /en/nixpkgs.md: -------------------------------------------------------------------------------- 1 | nixpkgs () is a monorepo containing a collection of #[[nix]] packages. It also includes various utility Nix functions (like [[writeShellApplication]]#), as well as the [[nixos]] Linux distribution (including the [[modules]]). 2 | 3 | In [[flakes|flakes]], nixpkgs is the most commonly used input. 4 | 5 | ## Links 6 | 7 | - [Zero to Nix: nixpkgs](https://zero-to-nix.com/concepts/nixpkgs) 8 | -------------------------------------------------------------------------------- /en/process-compose-flake.md: -------------------------------------------------------------------------------- 1 | # process-compose-flake 2 | 3 | [process-compose-flake](https://community.flake.parts/process-compose-flake) is a #[[flake-parts]] module for [process-compose](https://github.com/F1bonacc1/process-compose). 4 | -------------------------------------------------------------------------------- /en/registry.md: -------------------------------------------------------------------------------- 1 | 2 | # Flake registry 3 | 4 | Global registry of #[[flakes|Nix flakes]] 5 | 6 | https://github.com/NixOS/flake-registry 7 | 8 | -------------------------------------------------------------------------------- /en/repl.md: -------------------------------------------------------------------------------- 1 | # nix repl 2 | 3 | `nix repl` starts an interactive environment for evaluating #[[nix]] expressions 4 | 5 | https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-repl.html 6 | 7 | ## Tips 8 | 9 | - To load a [[flakes|flake]], use `:lf ` -------------------------------------------------------------------------------- /en/rust.md: -------------------------------------------------------------------------------- 1 | 2 | # Rust 3 | 4 | There are several ways to provide packaging and [[dev|development enviornment]] for Rust projects. 5 | 6 | Here's a simple template to begin with: 7 | - https://github.com/srid/rust-nix-template 8 | 9 | ## `buildRustPackage` 10 | 11 | If you just want to package a Rust program, use [[buildRustPackage]]#. 12 | 13 | ## Crane 14 | 15 | You may also be interested in using [crane] for advanced projects. Some example projects that do this: 16 | 17 | | Project | Description | 18 | | ----------------------------------------------- | ------------- | 19 | | https://github.com/srid/dioxus-desktop-template | A desktop app | 20 | | https://github.com/srid/nixci | A CLI app | 21 | 22 | [crane]: https://crane.dev/ -------------------------------------------------------------------------------- /en/services-flake.md: -------------------------------------------------------------------------------- 1 | 2 | # services-flake 3 | 4 | [services-flake](https://community.flake.parts/services-flake) provides declarative, composable, and reproducible services for [[dev|Nix development environment]], and is based on #[[flake-parts|flake-parts]]. Enabling users to have [[nixos|NixOS]]-like service on [[macos|macOS]] and Linux. 5 | -------------------------------------------------------------------------------- /en/shell.md: -------------------------------------------------------------------------------- 1 | 2 | # Nix Shell 3 | 4 | 5 | A non-flake version of documentation on #[[nix]] shell can be found [here](https://nix.dev/tutorials/first-steps/declarative-shell). 6 | -------------------------------------------------------------------------------- /en/store-path.md: -------------------------------------------------------------------------------- 1 | 2 | # Store path 3 | 4 | https://zero-to-nix.com/concepts/nix-store#store-paths -------------------------------------------------------------------------------- /en/store.md: -------------------------------------------------------------------------------- 1 | 2 | # Nix Store 3 | 4 | The directory used by #[[nix|Nix]] to store [[store-path|store paths]]# (including [[drv|derivations]]). 5 | 6 | https://zero-to-nix.com/concepts/nix-store 7 | -------------------------------------------------------------------------------- /en/topics.md: -------------------------------------------------------------------------------- 1 | 2 | # Topics 3 | 4 | In addition to [[tutorial]], we also have [atomic](https://neuron.zettel.page/atomic) notes on various concepts. Here are the top-level entry points to them: 5 | 6 | - [[nix]]# 7 | - [[nixos]]# 8 | - [[macos]]# 9 | -------------------------------------------------------------------------------- /en/traceVerbose.md: -------------------------------------------------------------------------------- 1 | 2 | # `traceVerbose` 3 | 4 | [Nix 2.10](https://nixos.org/manual/nix/stable/release-notes/rl-2.10) introduced a new function, `builtins.traceVerbose`, that works like `builtins.trace` but is no-op until the user explicitly enables it. 5 | 6 | For eg., running `nix build` will not cause `traceVerbose` to have any effect. But if you run `nix build --trace-verbose`, then logs from `traceVerbose` will be printed to the console. 7 | 8 | ## Examples 9 | 10 | - haskell-flake uses this to [provide conditional logging](https://community.flake.parts/haskell-flake/debugging) 11 | 12 | #[[howto]] 13 | -------------------------------------------------------------------------------- /en/treefmt.md: -------------------------------------------------------------------------------- 1 | # Auto formatting using `treefmt-nix` 2 | 3 | [treefmt](https://github.com/numtide/treefmt) provides an interface to run multiple [code formatters](https://en.wikipedia.org/wiki/Prettyprint) at once, so you don't have to run them manually for each file type in your #[[dev|development]] project. 4 | 5 | ## Writing the Nix to configure treefmt in your project 6 | 7 | ### Add treefmt and flake-root to your inputs 8 | 9 | The [`flake-root`](https://github.com/srid/flake-root) #[[flake-parts]] module is needed to find the root of your project based on the presence of a file, by default it is `flake.nix`. 10 | 11 | ```nix 12 | { 13 | # Inside `inputs` 14 | treefmt-nix.url = "github:numtide/treefmt-nix"; 15 | flake-root.url = "github:srid/flake-root"; 16 | } 17 | ``` 18 | 19 | ### Import `flakeModule` output of treefmt and flake-root 20 | 21 | ```nix 22 | { 23 | # Inside outputs' `flake-parts.lib.mkFlake` 24 | imports = [ 25 | inputs.treefmt-nix.flakeModule 26 | inputs.flake-root.flakeModule 27 | ]; 28 | } 29 | ``` 30 | 31 | ### Configure your formatter 32 | 33 | To actually enable the individual formatters you want to configure treefmt. The example configuration below only consists of formatters required by a haskell project using nix. Refer to [treefmt-doc](https://numtide.github.io/treefmt/formatters/) for more formatters. 34 | 35 | ```nix 36 | { 37 | # Inside mkFlake's `perSystem` 38 | treefmt.config = { 39 | inherit (config.flake-root) projectRootFile; 40 | # This is the default, and can be overriden. 41 | package = pkgs.treefmt; 42 | # formats .hs files (fourmolu is also available) 43 | programs.ormolu.enable = true; 44 | # formats .nix files 45 | programs.nixpkgs-fmt.enable = true; 46 | # formats .cabal files 47 | programs.cabal-fmt.enable = false; 48 | # Suggests improvements for your code in .hs files 49 | programs.hlint.enable = false; 50 | }; 51 | } 52 | ``` 53 | 54 | ### Add treefmt to your devShell 55 | 56 | Finally, add the resulting treefmt wrapper (`build.wrapper`) to your devShell. We also add the individual formatters (`build.programs`) to the devShell, so that they can be used directly in text editors and IDEs. 57 | 58 | ```nix 59 | { 60 | # Inside mkFlake's `perSystem` 61 | haskellProjects.default = { 62 | devShell.tools = _: { 63 | treefmt = config.treefmt.build.wrapper; 64 | } // config.treefmt.build.programs; 65 | }; 66 | } 67 | ``` 68 | 69 | ### Flake check 70 | 71 | The `treefmt-nix` flake module automatically adds a flake check that can be evaluated to make sure that the project is already autoformatted. 72 | 73 | ## Tips 74 | 75 | ### Exclude folders 76 | 77 | If there are folders where you wouldn't want to run the formatter on, use the following: 78 | 79 | ```nix 80 | # Inside mkFlake's `perSystem.treefmt.config` 81 | settings.formatter..excludes = [ "./foo/*" ]; 82 | ``` 83 | 84 | ### Use a different package for formatter 85 | 86 | The package shipped with the current [[nixpkgs]] might not be the desired one, follow the snippet below to override the package (assuming `nixpkgs-21_11` is present in your flake's inputs). 87 | 88 | ```nix 89 | # Inside mkFlake's `perSystem.treefmt.config` 90 | programs.ormolu.package = nixpkgs-21_11.haskellPackages.ormolu; 91 | ``` 92 | The same can be applied to other formatters. 93 | 94 | ### Pass additional parameters to your formatter 95 | 96 | You might want to change a certain behaviour of your formatter by overriding by passing the input to the executable. The following example shows how to pass `ghc-opt` to ormolu: 97 | 98 | ```nix 99 | # Inside mkFlake's `perSystem.treefmt.config` 100 | settings.formatter.ormolu = { 101 | options = [ 102 | "--ghc-opt" 103 | "-XTypeApplications" 104 | ]; 105 | }; 106 | ``` 107 | 108 | Ormolu requires this `ghc-opt` because unlike a lot of language extensions which are enabled by default, there are some which aren't. These can be found using `ormolu --manual-exts`. 109 | 110 | ## Example 111 | 112 | - [Sample treefmt config for your haskell project](https://github.com/srid/haskell-template/blob/a8b6d1f547d761ba392a31e644494d0eeee49c2a/flake.nix#L38-L55) 113 | 114 | ## Upcoming 115 | 116 | - `treefmt` will provide a pre-commit mode to disable commit if formatting checks fail. This is tracked here: https://github.com/numtide/treefmt/issues/78 117 | -------------------------------------------------------------------------------- /en/tutorial.md: -------------------------------------------------------------------------------- 1 | --- 2 | order: -100 3 | --- 4 | 5 | # Tutorials 6 | 7 | >[!warning] WIP 8 | > Our tutorials are being written. 9 | 10 | > [!note] Structure of these tutorials 11 | > Our tutorials are deliberately designed to give a quick overview of a topic, and then link to other resources for further reading. Think of them as providing a "guided tour" of the topic in question, as well as providing a learning progression. 12 | 13 | - [[nix-tutorial]]# 14 | - [[nixos-tutorial]]# 15 | - [[hm-tutorial]]# 16 | - [[dev]] tutorial series 17 | - [[nixify-haskell]] 18 | - [[haskell-rust-ffi]] 19 | - [ ] CI/CD tutorial series 20 | 21 | -------------------------------------------------------------------------------- /en/vscode.md: -------------------------------------------------------------------------------- 1 | # VSCode 2 | 3 | [Visual Studio Code](https://code.visualstudio.com/) is a popular open source code editor from Microsoft with extension support. 4 | 5 | {#nix} 6 | ## Using in [[nix|Nix]] based projects 7 | 8 | If your project provides a [[flakes|flake.nix]] along with a #[[dev|development]] shell, it can be developed on VSCode using one of the two ways (prefer the 2nd way): 9 | 10 | 1. Open VSCode [from a terminal][vscode-term], inside of a [[shell|devshell]] (i.e., `nix develop -c code .`), **or** 11 | 2. Setup [[direnv|direnv]] and install the [direnv VSCode extension][direnv-ext]. 12 | 13 | >[!tip] The `.vscode` folder 14 | > You can persist Nix related extensions & settings for VSCode in the project root's `.vscode` folder (see [example](https://github.com/srid/haskell-template/tree/master/.vscode)). This enables other people working on the project to inherit the same environment as you. 15 | 16 | {#direnv} 17 | ### Working on `direnv`-activated projects 18 | 19 | If you use [[direnv|direnv]], it is rather simple to get setup with VSCode: 20 | 21 | Once you have cloned your project repo and have activated the direnv environment (using `direnv allow), you can open it in VSCode to develop it: 22 | 23 | - Launch [VSCode](https://code.visualstudio.com/), and open the `git clone`’ed project directory [as single-folder workspace](https://code.visualstudio.com/docs/editor/workspaces#_singlefolder-workspaces) 24 | - NOTE: If you are on Windows, you must use the [Remote - WSL extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) to open the folder in WSL. 25 | - When prompted by VSCode, install the [workspace recommended](https://code.visualstudio.com/docs/editor/extension-marketplace#_workspace-recommended-extensions) extensions. 26 | - If it doesn’t prompt, press Cmd+Shift+X and search for `@recommended` to install them all manually. 27 | - Ensure that the direnv extension is fully activated. You should expect to see this in the footer of VSCode: ![image](https://user-images.githubusercontent.com/3998/235459201-f0442741-294b-40bc-9c65-77500c9f4f1c.png) 28 | - For Haskell projects: Once direnv is activated (and only then) open a Haskell file (`.hs`). You should expect haskell-language-server to startup, as seen in the footer: ![image](https://user-images.githubusercontent.com/3998/235459551-7c6c0c61-f4e8-41f3-87cf-6a834e2cdbc7.png) 29 | - Once this processing is complete, all IDE features should work. 30 | - The experience is similar for other languages; for Rust, it will be rust-analyzer. 31 | 32 | To give this a try, here are some sample repos: 33 | 34 | - Haskell: https://github.com/srid/haskell-template 35 | - Rust: https://github.com/srid/rust-nix-template 36 | 37 | 38 | [vscode-term]: https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line 39 | [direnv-ext]: https://marketplace.visualstudio.com/items?itemName=mkhl.direnv 40 | -------------------------------------------------------------------------------- /en/why-dev.md: -------------------------------------------------------------------------------- 1 | 2 | # Why Choose Nix for develoment? 3 | 4 | Why opt for [[nix]] when #[[dev|developping]] a software project instead of language-specific alternatives (such as Stack or GHCup for [[haskell]])? 5 | 6 | - **Instantaneous Onboarding**: Typical project READMEs detail environment setup instructions that often fail to work uniformly across different developers' machines, taking hours or even days to configure. Nix offers an instant and reproducible setup, allowing any newcomer to get their development environment ready swiftly with one command. 7 | - **Boosted Productivity**: Developers can dedicate more time to writing software, as Nix ensures a fully functional development environment through `nix develop`. 8 | - **Multi-Platform Support**: The same configuration reliably works across [[macos]], Linux, and WSL. 9 | 10 | >[!note] macOS support 11 | > While [[macos]] doesn't enjoy first-class support in [[nixpkgs]] yet, [improvements are underway](https://github.com/NixOS/nixpkgs/issues/116341). 12 | 13 | -------------------------------------------------------------------------------- /en/writeShellApplication.md: -------------------------------------------------------------------------------- 1 | # `writeShellApplication` 2 | 3 | The recommended way to create [[drv]] using shell scripts. 4 | 5 | https://nixos.org/manual/nixpkgs/stable/#trivial-builder-writeShellApplication 6 | 7 | - The function generates a [[drv]] for a shell script specified as the value for `text` attribute. 8 | - `runtimeInputs`: packages to be made available to the shell application's PATH. 9 | - Uses [shellcheck](https://github.com/koalaman/shellcheck) to statically analyze your bash script for issues. 10 | 11 | ## Examples 12 | 13 | - [In hackage server](https://github.com/srid/haskell-flake/discussions/330) 14 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "commonmark-simple": { 4 | "flake": false, 5 | "locked": { 6 | "lastModified": 1707333942, 7 | "narHash": "sha256-o1am93UXviPVdwwPPL5DcD8M4gwFple8SKw/lVmixa8=", 8 | "owner": "srid", 9 | "repo": "commonmark-simple", 10 | "rev": "0308362957d77eea462c2c99d110820fbf30b4b8", 11 | "type": "github" 12 | }, 13 | "original": { 14 | "owner": "srid", 15 | "repo": "commonmark-simple", 16 | "type": "github" 17 | } 18 | }, 19 | "commonmark-wikilink": { 20 | "flake": false, 21 | "locked": { 22 | "lastModified": 1738248145, 23 | "narHash": "sha256-UN2Nh+uf+DzM336Ojzr6YZV4RJy8BPx9Q5GZpax3wt0=", 24 | "owner": "srid", 25 | "repo": "commonmark-wikilink", 26 | "rev": "1d7aa327fb33b41f3c4899d5b29aa122780c900f", 27 | "type": "github" 28 | }, 29 | "original": { 30 | "owner": "srid", 31 | "repo": "commonmark-wikilink", 32 | "type": "github" 33 | } 34 | }, 35 | "ema": { 36 | "flake": false, 37 | "locked": { 38 | "lastModified": 1738428103, 39 | "narHash": "sha256-vZgaNI0y6IKnWDSLFsl7mwSUZ3ONgduclQkB6WK0VMo=", 40 | "owner": "srid", 41 | "repo": "ema", 42 | "rev": "4478e88d33126ef0b478b2980a71592b8f9afd6b", 43 | "type": "github" 44 | }, 45 | "original": { 46 | "owner": "srid", 47 | "repo": "ema", 48 | "type": "github" 49 | } 50 | }, 51 | "emanote": { 52 | "inputs": { 53 | "commonmark-simple": "commonmark-simple", 54 | "commonmark-wikilink": "commonmark-wikilink", 55 | "ema": "ema", 56 | "emanote-template": "emanote-template", 57 | "flake-parts": "flake-parts", 58 | "flake-root": "flake-root", 59 | "haskell-flake": "haskell-flake", 60 | "heist-extra": "heist-extra", 61 | "nixos-unified": "nixos-unified", 62 | "nixpkgs": "nixpkgs", 63 | "treefmt-nix": "treefmt-nix", 64 | "unionmount": "unionmount" 65 | }, 66 | "locked": { 67 | "lastModified": 1742762001, 68 | "narHash": "sha256-+1DIDrH2K3fk4zUyOG+t8dA76XpnDFNnW9J/nDavVRY=", 69 | "owner": "srid", 70 | "repo": "emanote", 71 | "rev": "323c6aff3a3d2c069855745c08558ee0abb959f5", 72 | "type": "github" 73 | }, 74 | "original": { 75 | "owner": "srid", 76 | "repo": "emanote", 77 | "type": "github" 78 | } 79 | }, 80 | "emanote-template": { 81 | "flake": false, 82 | "locked": { 83 | "lastModified": 1731804312, 84 | "narHash": "sha256-3rKT3H5UYbLtFm10ioIEO+7WEgTFT21vUry/0Oj9OWo=", 85 | "owner": "srid", 86 | "repo": "emanote-template", 87 | "rev": "5fa04e49ab6b47f8d9a53f754265d2277e94a5ae", 88 | "type": "github" 89 | }, 90 | "original": { 91 | "owner": "srid", 92 | "repo": "emanote-template", 93 | "type": "github" 94 | } 95 | }, 96 | "flake-parts": { 97 | "inputs": { 98 | "nixpkgs-lib": [ 99 | "emanote", 100 | "nixpkgs" 101 | ] 102 | }, 103 | "locked": { 104 | "lastModified": 1733312601, 105 | "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", 106 | "owner": "hercules-ci", 107 | "repo": "flake-parts", 108 | "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", 109 | "type": "github" 110 | }, 111 | "original": { 112 | "owner": "hercules-ci", 113 | "repo": "flake-parts", 114 | "type": "github" 115 | } 116 | }, 117 | "flake-root": { 118 | "locked": { 119 | "lastModified": 1723604017, 120 | "narHash": "sha256-rBtQ8gg+Dn4Sx/s+pvjdq3CB2wQNzx9XGFq/JVGCB6k=", 121 | "owner": "srid", 122 | "repo": "flake-root", 123 | "rev": "b759a56851e10cb13f6b8e5698af7b59c44be26e", 124 | "type": "github" 125 | }, 126 | "original": { 127 | "owner": "srid", 128 | "repo": "flake-root", 129 | "type": "github" 130 | } 131 | }, 132 | "haskell-flake": { 133 | "locked": { 134 | "lastModified": 1734984991, 135 | "narHash": "sha256-oUYtRBD3Yhw2jvKYo0lfd82fgEQQbFoiJcHO923gmOc=", 136 | "owner": "srid", 137 | "repo": "haskell-flake", 138 | "rev": "daf00052906bdd977e57a07f7048437214232e87", 139 | "type": "github" 140 | }, 141 | "original": { 142 | "owner": "srid", 143 | "repo": "haskell-flake", 144 | "type": "github" 145 | } 146 | }, 147 | "heist-extra": { 148 | "flake": false, 149 | "locked": { 150 | "lastModified": 1737313814, 151 | "narHash": "sha256-WCXhs/xhCR4CKBEadQjqqgUb47bLzDY7P7oL5cSgDHc=", 152 | "owner": "srid", 153 | "repo": "heist-extra", 154 | "rev": "6f73e000a34b7c054b516b9504b5a7ed08ce6a2d", 155 | "type": "github" 156 | }, 157 | "original": { 158 | "owner": "srid", 159 | "repo": "heist-extra", 160 | "type": "github" 161 | } 162 | }, 163 | "nixos-unified": { 164 | "locked": { 165 | "lastModified": 1729697921, 166 | "narHash": "sha256-gqcmWE+4Vr5/l6AoQc2jIbJHCAXAY+qWPC0ruoAHV1Q=", 167 | "owner": "srid", 168 | "repo": "nixos-unified", 169 | "rev": "e60e64841e74c777799624531dcb2f311f95f639", 170 | "type": "github" 171 | }, 172 | "original": { 173 | "owner": "srid", 174 | "repo": "nixos-unified", 175 | "type": "github" 176 | } 177 | }, 178 | "nixpkgs": { 179 | "locked": { 180 | "lastModified": 1734988233, 181 | "narHash": "sha256-Ucfnxq1rF/GjNP3kTL+uTfgdoE9a3fxDftSfeLIS8mA=", 182 | "owner": "nixos", 183 | "repo": "nixpkgs", 184 | "rev": "de1864217bfa9b5845f465e771e0ecb48b30e02d", 185 | "type": "github" 186 | }, 187 | "original": { 188 | "owner": "nixos", 189 | "ref": "nixpkgs-unstable", 190 | "repo": "nixpkgs", 191 | "type": "github" 192 | } 193 | }, 194 | "root": { 195 | "inputs": { 196 | "emanote": "emanote", 197 | "flake-parts": [ 198 | "emanote", 199 | "flake-parts" 200 | ], 201 | "nixpkgs": [ 202 | "emanote", 203 | "nixpkgs" 204 | ] 205 | } 206 | }, 207 | "treefmt-nix": { 208 | "inputs": { 209 | "nixpkgs": [ 210 | "emanote", 211 | "nixpkgs" 212 | ] 213 | }, 214 | "locked": { 215 | "lastModified": 1734982074, 216 | "narHash": "sha256-N7M37KP7cHWoXicuE536GrVvU8nMDT/gpI1kja2hkdg=", 217 | "owner": "numtide", 218 | "repo": "treefmt-nix", 219 | "rev": "e41e948cf097cbf96ba4dff47a30ea6891af9f33", 220 | "type": "github" 221 | }, 222 | "original": { 223 | "owner": "numtide", 224 | "repo": "treefmt-nix", 225 | "type": "github" 226 | } 227 | }, 228 | "unionmount": { 229 | "flake": false, 230 | "locked": { 231 | "lastModified": 1710078535, 232 | "narHash": "sha256-gKBgBtuiRTD3/3EeY8aMgFzuaSEffJacBxsCB3ct1eg=", 233 | "owner": "srid", 234 | "repo": "unionmount", 235 | "rev": "41ae982fa118770bf4d3a3f2d48ac1ffb61c9f09", 236 | "type": "github" 237 | }, 238 | "original": { 239 | "owner": "srid", 240 | "repo": "unionmount", 241 | "type": "github" 242 | } 243 | } 244 | }, 245 | "root": "root", 246 | "version": 7 247 | } 248 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | emanote.url = "github:srid/emanote"; 4 | nixpkgs.follows = "emanote/nixpkgs"; 5 | flake-parts.follows = "emanote/flake-parts"; 6 | }; 7 | 8 | outputs = inputs@{ self, flake-parts, nixpkgs, ... }: 9 | flake-parts.lib.mkFlake { inherit inputs; } { 10 | systems = nixpkgs.lib.systems.flakeExposed; 11 | imports = [ inputs.emanote.flakeModule ]; 12 | perSystem = { self', pkgs, lib, system, ... }: 13 | let 14 | langs = { 15 | en = { path = ./en; port = 7788; }; 16 | fr = { path = ./fr; port = 7789; }; 17 | }; 18 | in 19 | { 20 | emanote = { 21 | sites = lib.mapAttrs 22 | (name: lang: { 23 | inherit (lang) port; 24 | layers = [{ path = lang.path; pathString = name; } { path = ./global; pathString = "global"; }]; 25 | prettyUrls = true; 26 | baseUrl = "/${name}/"; 27 | basePath = name; 28 | }) 29 | langs; 30 | }; 31 | devShells.default = pkgs.mkShell { 32 | buildInputs = [ 33 | pkgs.nixpkgs-fmt 34 | pkgs.nixd 35 | pkgs.just 36 | ]; 37 | }; 38 | packages = rec { 39 | indexPage = pkgs.writeTextDir 40 | "index.html" 41 | '' 42 | 43 | 44 | 45 | Welcome to NixOS Asia 46 | 47 | 48 | 49 | 50 |
51 | English | Français 52 |
53 | 54 | 55 | ''; 56 | site = pkgs.symlinkJoin { 57 | name = "nixos-asia-site"; 58 | paths = [ indexPage ] ++ lib.mapAttrsToList 59 | (name: _: self'.packages.${name}) 60 | langs; 61 | }; 62 | default = site; 63 | }; 64 | apps.preview.program = pkgs.writeShellApplication { 65 | name = "emanote-static-preview"; 66 | runtimeInputs = [ pkgs.static-web-server ]; 67 | text = '' 68 | set -x 69 | static-web-server -d ${self'.packages.default} "$@" 70 | ''; 71 | }; 72 | apps.default.program = self'.apps.en.program; # Alias to English site 73 | formatter = pkgs.nixpkgs-fmt; 74 | }; 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /fr/index.md: -------------------------------------------------------------------------------- 1 | # NixOS Asie 2 | 3 | > [!warning] La version française n'est pas encore écrite. 4 | > Si vous souhaitez aider, voyez [ici](https://github.com/nixos-asia/website/issues/18). 5 | -------------------------------------------------------------------------------- /fr/index.yaml: -------------------------------------------------------------------------------- 1 | page: 2 | lang: fr 3 | siteTitle: NixOS Asie 4 | siteUrl: https://nixos.asia/fr 5 | template: 6 | editBaseUrl: https://github.com/nixos-asia/website/edit/master/fr 7 | -------------------------------------------------------------------------------- /global/blog/replacing-docker-compose/docker-to-nix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/blog/replacing-docker-compose/docker-to-nix.png -------------------------------------------------------------------------------- /global/blog/replacing-docker-compose/ny-services-flake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/blog/replacing-docker-compose/ny-services-flake.png -------------------------------------------------------------------------------- /global/event/nix-dev-home/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/event/nix-dev-home/screenshot.png -------------------------------------------------------------------------------- /global/event/services-flake-meetup/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/event/services-flake-meetup/screenshot.png -------------------------------------------------------------------------------- /global/event/srid-nix-dev/vscode-haskell-template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/event/srid-nix-dev/vscode-haskell-template.png -------------------------------------------------------------------------------- /global/haskell-rust-ffi/haskell-rust-ffi-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/haskell-rust-ffi/haskell-rust-ffi-banner.png -------------------------------------------------------------------------------- /global/haskell-rust-ffi/hs/Main.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} 2 | 3 | {-# HLINT ignore "Use camelCase" #-} 4 | 5 | module Main where 6 | 7 | import Foreign.C.String (CString, peekCString) 8 | 9 | -- | The `hello` function exported by the `rust_nix_template` library. 10 | foreign import ccall "hello" hello_rust :: IO CString 11 | 12 | -- | Call `hello_rust` and convert the result to a Haskell `String`. 13 | hello_haskell :: IO String 14 | hello_haskell = hello_rust >>= peekCString 15 | 16 | main :: IO () 17 | main = hello_haskell >>= putStrLn 18 | -------------------------------------------------------------------------------- /global/haskell-rust-ffi/hs/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | perSystem = { config, pkgs, self', ... }: { 3 | haskellProjects.default = { 4 | projectRoot = ./.; 5 | autoWire = [ "packages" "checks" "apps" ]; 6 | }; 7 | 8 | devShells.haskell = pkgs.mkShell { 9 | name = "hello-haskell"; 10 | inputsFrom = [ 11 | config.haskellProjects.default.outputs.devShell 12 | ]; 13 | }; 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /global/haskell-rust-ffi/lib.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::CString; 2 | use std::os::raw::c_char; 3 | 4 | /// A function that returns "Hello, from rust!" as a C style string. 5 | #[no_mangle] 6 | pub extern "C" fn hello() -> *mut c_char { 7 | let s = CString::new("Hello, from rust!").unwrap(); 8 | s.into_raw() 9 | } -------------------------------------------------------------------------------- /global/index.yaml: -------------------------------------------------------------------------------- 1 | # For documentation and available settings, see 2 | # https://github.com/srid/emanote/blob/master/emanote/default/index.yaml 3 | 4 | page: 5 | siteTitle: NixOS Asia 6 | siteUrl: https://nixos.asia/en 7 | headHtml: | 8 | 9 | image: static/nixos-asia.svg 10 | 11 | template: 12 | theme: green 13 | iconUrl: static/nixos-asia.svg 14 | 15 | uptree: 16 | enable: true 17 | toc: 18 | enable: false 19 | sidebar: 20 | enable: false 21 | 22 | urlStrategy: pretty 23 | 24 | feed: 25 | siteUrl: https://nixos.asia 26 | -------------------------------------------------------------------------------- /global/nix-modules/1/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1706191920, 6 | "narHash": "sha256-eLihrZAPZX0R6RyM5fYAWeKVNuQPYjAkCUBr+JNvtdE=", 7 | "owner": "NixOS", 8 | "repo": "nixpkgs", 9 | "rev": "ae5c332cbb5827f6b1f02572496b141021de335f", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "owner": "NixOS", 14 | "ref": "nixos-unstable", 15 | "repo": "nixpkgs", 16 | "type": "github" 17 | } 18 | }, 19 | "root": { 20 | "inputs": { 21 | "nixpkgs": "nixpkgs" 22 | } 23 | } 24 | }, 25 | "root": "root", 26 | "version": 7 27 | } 28 | -------------------------------------------------------------------------------- /global/nix-modules/1/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 4 | }; 5 | outputs = { self, nixpkgs }: 6 | let 7 | # TODO: Change this to x86_64-linux if you are on Linux 8 | system = "aarch64-darwin"; 9 | pkgs = nixpkgs.legacyPackages.${system}; 10 | in 11 | { 12 | packages.${system}.default = pkgs.writeShellApplication { 13 | name = "list-contents"; 14 | runtimeInputs = [ pkgs.lsd ]; 15 | text = '' 16 | lsd -l / 17 | ''; 18 | }; 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /global/nix-modules/2/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1706191920, 6 | "narHash": "sha256-eLihrZAPZX0R6RyM5fYAWeKVNuQPYjAkCUBr+JNvtdE=", 7 | "owner": "NixOS", 8 | "repo": "nixpkgs", 9 | "rev": "ae5c332cbb5827f6b1f02572496b141021de335f", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "owner": "NixOS", 14 | "ref": "nixos-unstable", 15 | "repo": "nixpkgs", 16 | "type": "github" 17 | } 18 | }, 19 | "root": { 20 | "inputs": { 21 | "nixpkgs": "nixpkgs" 22 | } 23 | } 24 | }, 25 | "root": "root", 26 | "version": 7 27 | } 28 | -------------------------------------------------------------------------------- /global/nix-modules/2/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 4 | }; 5 | outputs = { self, nixpkgs }: 6 | let 7 | # TODO: Change this to x86_64-linux if you are on Linux 8 | system = "aarch64-darwin"; 9 | pkgs = nixpkgs.legacyPackages.${system}; 10 | # ⤵️ We introduced a function here 11 | lsdFor = { dir, tree ? false }: pkgs.writeShellApplication { 12 | name = "list-contents"; 13 | runtimeInputs = [ pkgs.lsd ]; 14 | text = '' 15 | lsd ${if tree then "--tree" else ""} "${dir}" 16 | ''; 17 | }; 18 | in 19 | { 20 | packages.${system} = { 21 | # ⤵️ And call that function here 22 | default = lsdFor { dir = "/"; }; 23 | home = lsdFor { dir = "$HOME"; }; 24 | downloads = lsdFor { dir = "$HOME/Downloads"; tree = true; }; 25 | }; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /global/nix-modules/3/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1706191920, 6 | "narHash": "sha256-eLihrZAPZX0R6RyM5fYAWeKVNuQPYjAkCUBr+JNvtdE=", 7 | "owner": "NixOS", 8 | "repo": "nixpkgs", 9 | "rev": "ae5c332cbb5827f6b1f02572496b141021de335f", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "owner": "NixOS", 14 | "ref": "nixos-unstable", 15 | "repo": "nixpkgs", 16 | "type": "github" 17 | } 18 | }, 19 | "root": { 20 | "inputs": { 21 | "nixpkgs": "nixpkgs" 22 | } 23 | } 24 | }, 25 | "root": "root", 26 | "version": 7 27 | } 28 | -------------------------------------------------------------------------------- /global/nix-modules/3/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 4 | }; 5 | outputs = { self, nixpkgs }: 6 | let 7 | # TODO: Change this to x86_64-linux if you are on Linux 8 | system = "aarch64-darwin"; 9 | pkgs = nixpkgs.legacyPackages.${system}; 10 | lib = pkgs.lib; 11 | lsdFor = settings: 12 | let 13 | result = lib.evalModules { 14 | modules = [ 15 | # Note that 'settings' is no different to the lsd.nix module. 16 | ./lsd.nix 17 | settings 18 | ]; 19 | # Arguments passed here become automatically available to all 20 | # modules. 21 | specialArgs = { inherit pkgs; }; 22 | }; 23 | in 24 | result.config.lsd.package; 25 | in 26 | { 27 | packages.${system} = { 28 | default = lsdFor { lsd.dir = "/"; }; 29 | home = lsdFor { lsd.dir = "$HOME"; }; 30 | downloads = lsdFor { lsd.dir = "$HOME/Downloads"; lsd.tree = true; }; 31 | }; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /global/nix-modules/3/lsd.nix: -------------------------------------------------------------------------------- 1 | # A module can be an attrset, or a function returning an attrset. 2 | # 3 | # Our module here is of the latter kind. By default, certain arguments are 4 | # automatically passed. You can specify additional arguments in `_module.args`. 5 | { pkgs, lib, config, ... }: 6 | { 7 | # A module's "interface" is defined in `options`. 8 | options = { 9 | # The `lsd` option is of type sub-module; meaning, it can contain further 10 | # options and config. 11 | lsd = lib.mkOption { 12 | default = { }; 13 | type = lib.types.submodule { 14 | options = { 15 | # The `dir` option is of type string. 16 | # 17 | # If the user doesn't set it, its default value of "/" is used. 18 | dir = lib.mkOption { 19 | type = lib.types.str; 20 | default = "/"; 21 | description = "The directory to list"; 22 | }; 23 | # The `tree` option is of type boolean. 24 | tree = lib.mkOption { 25 | type = lib.types.bool; 26 | default = false; 27 | description = "Whether to show a tree view"; 28 | }; 29 | # The `package` option is of type package. 30 | # 31 | # It is not user-settable, hence `readOnly = true`. The value will be 32 | # set in the `config` implementation below. 33 | package = lib.mkOption { 34 | type = lib.types.package; 35 | readOnly = true; 36 | }; 37 | }; 38 | }; 39 | }; 40 | }; 41 | 42 | # A module's "implementation" is defined in `config`. 43 | config = 44 | let 45 | cfg = config.lsd; 46 | in 47 | { 48 | lsd.package = 49 | pkgs.writeShellApplication { 50 | name = "list-contents"; 51 | runtimeInputs = [ pkgs.lsd ]; 52 | text = '' 53 | lsd ${if cfg.tree then "--tree" else ""} "${cfg.dir}" 54 | ''; 55 | }; 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /global/nix-modules/4/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1706191920, 6 | "narHash": "sha256-eLihrZAPZX0R6RyM5fYAWeKVNuQPYjAkCUBr+JNvtdE=", 7 | "owner": "NixOS", 8 | "repo": "nixpkgs", 9 | "rev": "ae5c332cbb5827f6b1f02572496b141021de335f", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "owner": "NixOS", 14 | "ref": "nixos-unstable", 15 | "repo": "nixpkgs", 16 | "type": "github" 17 | } 18 | }, 19 | "root": { 20 | "inputs": { 21 | "nixpkgs": "nixpkgs" 22 | } 23 | } 24 | }, 25 | "root": "root", 26 | "version": 7 27 | } 28 | -------------------------------------------------------------------------------- /global/nix-modules/4/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 4 | }; 5 | outputs = { self, nixpkgs }: 6 | let 7 | # TODO: Change this to x86_64-linux if you are on Linux 8 | system = "aarch64-darwin"; 9 | pkgs = nixpkgs.legacyPackages.${system}; 10 | mkLib = pkgs: { 11 | lsdFor = settings: 12 | let 13 | result = pkgs.lib.evalModules { 14 | modules = [ 15 | ./lsd.nix 16 | settings 17 | ]; 18 | specialArgs = { inherit pkgs; }; 19 | }; 20 | in 21 | result.config.lsd.package; 22 | # ⤵️ A common module for re-use in other modules (see below) 23 | common = { 24 | lsd = { 25 | long = pkgs.lib.mkDefault true; 26 | }; 27 | }; 28 | }; 29 | inherit (mkLib pkgs) lsdFor common; 30 | in 31 | { 32 | # ⤵️ Let's export some things for use in 5/flake.nix 33 | inherit mkLib; 34 | 35 | packages.${system} = { 36 | default = lsdFor { 37 | # ⤵️ Here, we import the common module 38 | imports = [ common ]; 39 | lsd.dir = "/"; 40 | }; 41 | home = lsdFor { 42 | # ⤵️ Here, we import the common module 43 | imports = [ common ]; 44 | lsd.dir = "$HOME"; 45 | }; 46 | downloads = lsdFor { 47 | # ⤵️ Here, we import the common module 48 | imports = [ common ]; 49 | lsd = { 50 | dir = "$HOME/Downloads"; 51 | tree = true; 52 | }; 53 | }; 54 | }; 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /global/nix-modules/4/lsd.nix: -------------------------------------------------------------------------------- 1 | { pkgs, lib, config, ... }: 2 | { 3 | # The interface 4 | options = { 5 | lsd = lib.mkOption { 6 | default = { }; 7 | type = lib.types.submodule { 8 | options = { 9 | dir = lib.mkOption { 10 | type = lib.types.str; 11 | default = "/"; 12 | description = "The directory to list"; 13 | }; 14 | tree = lib.mkOption { 15 | type = lib.types.bool; 16 | default = false; 17 | description = "Whether to show a tree view"; 18 | }; 19 | long = lib.mkOption { 20 | type = lib.types.bool; 21 | default = false; 22 | description = "Whether to show a long view"; 23 | }; 24 | package = lib.mkOption { 25 | type = lib.types.package; 26 | readOnly = true; 27 | }; 28 | }; 29 | }; 30 | }; 31 | }; 32 | 33 | # The implementation 34 | config = 35 | let 36 | cfg = config.lsd; 37 | in 38 | { 39 | lsd.package = 40 | pkgs.writeShellApplication { 41 | name = "list-contents"; 42 | runtimeInputs = [ pkgs.lsd ]; 43 | text = '' 44 | lsd ${if cfg.tree then "--tree" else ""} ${if cfg.long then "-l" else ""} "${cfg.dir}" 45 | ''; 46 | }; 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /global/nix-modules/5/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake4": { 4 | "inputs": { 5 | "nixpkgs": "nixpkgs" 6 | }, 7 | "locked": { 8 | "lastModified": 1, 9 | "narHash": "sha256-2KGXcyn3l8WvHTwkqrDZ/XamjSyEuNiokwp0KWKsxxU=", 10 | "path": "../4", 11 | "type": "path" 12 | }, 13 | "original": { 14 | "path": "../4", 15 | "type": "path" 16 | } 17 | }, 18 | "nixpkgs": { 19 | "locked": { 20 | "lastModified": 1706191920, 21 | "narHash": "sha256-eLihrZAPZX0R6RyM5fYAWeKVNuQPYjAkCUBr+JNvtdE=", 22 | "owner": "NixOS", 23 | "repo": "nixpkgs", 24 | "rev": "ae5c332cbb5827f6b1f02572496b141021de335f", 25 | "type": "github" 26 | }, 27 | "original": { 28 | "owner": "NixOS", 29 | "ref": "nixos-unstable", 30 | "repo": "nixpkgs", 31 | "type": "github" 32 | } 33 | }, 34 | "nixpkgs_2": { 35 | "locked": { 36 | "lastModified": 1706191920, 37 | "narHash": "sha256-eLihrZAPZX0R6RyM5fYAWeKVNuQPYjAkCUBr+JNvtdE=", 38 | "owner": "NixOS", 39 | "repo": "nixpkgs", 40 | "rev": "ae5c332cbb5827f6b1f02572496b141021de335f", 41 | "type": "github" 42 | }, 43 | "original": { 44 | "owner": "NixOS", 45 | "ref": "nixos-unstable", 46 | "repo": "nixpkgs", 47 | "type": "github" 48 | } 49 | }, 50 | "root": { 51 | "inputs": { 52 | "flake4": "flake4", 53 | "nixpkgs": "nixpkgs_2" 54 | } 55 | } 56 | }, 57 | "root": "root", 58 | "version": 7 59 | } 60 | -------------------------------------------------------------------------------- /global/nix-modules/5/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 4 | # ⤵️ 4/flake.nix is specified as input here, to allow us to reuse its 5 | # outputs. 6 | flake4.url = "path:../4"; 7 | }; 8 | outputs = { self, nixpkgs, flake4 }: 9 | let 10 | # TODO: Change this to x86_64-linux if you are on Linux 11 | system = "aarch64-darwin"; 12 | pkgs = nixpkgs.legacyPackages.${system}; 13 | # ⤵️ We import the library from 4/flake.nix 14 | lsdLib = flake4.mkLib pkgs; 15 | in 16 | { 17 | packages.${system} = { 18 | # ⤵️ And use it here. 19 | default = lsdLib.lsdFor { 20 | imports = [ lsdLib.common ]; 21 | lsd.dir = "/"; 22 | }; 23 | home = lsdLib.lsdFor { 24 | lsd.dir = "$HOME"; 25 | }; 26 | downloads = lsdLib.lsdFor { 27 | lsd = { 28 | dir = "$HOME/Downloads"; 29 | tree = true; 30 | }; 31 | }; 32 | }; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /global/nix-tutorial/nix-first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nix-tutorial/nix-first.png -------------------------------------------------------------------------------- /global/nix-tutorial/nix-modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nix-tutorial/nix-modules.png -------------------------------------------------------------------------------- /global/nix-tutorial/nix-rapid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nix-tutorial/nix-rapid.png -------------------------------------------------------------------------------- /global/nixos-install-disko/nixos-configuration-nix-with-disko-config.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-disko/nixos-configuration-nix-with-disko-config.jpeg -------------------------------------------------------------------------------- /global/nixos-install-disko/nixos-disko-config.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-disko/nixos-disko-config.jpeg -------------------------------------------------------------------------------- /global/nixos-install-disko/nixos-disko-filesystems.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-disko/nixos-disko-filesystems.jpeg -------------------------------------------------------------------------------- /global/nixos-install-disko/nixos-disko-post-partition.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-disko/nixos-disko-post-partition.jpeg -------------------------------------------------------------------------------- /global/nixos-install-disko/nixos-flake-with-disko.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-disko/nixos-flake-with-disko.jpeg -------------------------------------------------------------------------------- /global/nixos-install-disko/nixos-installer-cli.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-disko/nixos-installer-cli.jpeg -------------------------------------------------------------------------------- /global/nixos-install-disko/nixos-lsblk.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-disko/nixos-lsblk.jpeg -------------------------------------------------------------------------------- /global/nixos-install-flake/nixos-install-flake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-flake/nixos-install-flake.png -------------------------------------------------------------------------------- /global/nixos-install-flake/nixos-installer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-flake/nixos-installer.png -------------------------------------------------------------------------------- /global/nixos-install-flake/nixos-pony.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-flake/nixos-pony.png -------------------------------------------------------------------------------- /global/nixos-install-flake/nixos-rebuild-switch-flake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-flake/nixos-rebuild-switch-flake.png -------------------------------------------------------------------------------- /global/nixos-install-flake/nixos-rebuild-switch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/nixos-install-flake/nixos-rebuild-switch.png -------------------------------------------------------------------------------- /global/nixos-install-oneclick/disk-config.nix: -------------------------------------------------------------------------------- 1 | { 2 | disko.devices = { 3 | disk = { 4 | main = { 5 | # When using disko-install, we will overwrite this value from the commandline 6 | device = "/dev/disk/by-id/some-disk-id"; 7 | type = "disk"; 8 | content = { 9 | type = "gpt"; 10 | partitions = { 11 | MBR = { 12 | type = "EF02"; # for grub MBR 13 | size = "1M"; 14 | }; 15 | ESP = { 16 | type = "EF00"; 17 | size = "500M"; 18 | content = { 19 | type = "filesystem"; 20 | format = "vfat"; 21 | mountpoint = "/boot"; 22 | }; 23 | }; 24 | root = { 25 | size = "100%"; 26 | content = { 27 | type = "filesystem"; 28 | format = "ext4"; 29 | mountpoint = "/"; 30 | }; 31 | }; 32 | }; 33 | }; 34 | }; 35 | }; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /global/nixos-install-oneclick/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "disko": { 4 | "inputs": { 5 | "nixpkgs": [ 6 | "nixpkgs" 7 | ] 8 | }, 9 | "locked": { 10 | "lastModified": 1711261295, 11 | "narHash": "sha256-5DUNQl9BSmLxgGLbF05G7hi/UTk9DyZq8AuEszhQA7Q=", 12 | "owner": "nix-community", 13 | "repo": "disko", 14 | "rev": "5d2d3e421ade554b19b4dbb0d11a04023378a330", 15 | "type": "github" 16 | }, 17 | "original": { 18 | "owner": "nix-community", 19 | "repo": "disko", 20 | "type": "github" 21 | } 22 | }, 23 | "nixpkgs": { 24 | "locked": { 25 | "lastModified": 1711124224, 26 | "narHash": "sha256-l0zlN/3CiodvWDtfBOVxeTwYSRz93muVbXWSpaMjXxM=", 27 | "owner": "NixOS", 28 | "repo": "nixpkgs", 29 | "rev": "56528ee42526794d413d6f244648aaee4a7b56c0", 30 | "type": "github" 31 | }, 32 | "original": { 33 | "owner": "NixOS", 34 | "ref": "nixos-23.11", 35 | "repo": "nixpkgs", 36 | "type": "github" 37 | } 38 | }, 39 | "root": { 40 | "inputs": { 41 | "disko": "disko", 42 | "nixpkgs": "nixpkgs" 43 | } 44 | } 45 | }, 46 | "root": "root", 47 | "version": 7 48 | } 49 | -------------------------------------------------------------------------------- /global/nixos-install-oneclick/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; 4 | disko.url = "github:nix-community/disko"; 5 | disko.inputs.nixpkgs.follows = "nixpkgs"; 6 | }; 7 | outputs = { self, nixpkgs, disko, ... }: 8 | let 9 | # TODO: Adjust these values to your needs 10 | system = "x86_64-linux"; 11 | hostName = "oneclick"; 12 | rootAuthorizedKeys = [ 13 | # This user can ssh using `ssh root@` 14 | "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHQRxPoqlThDrkR58pKnJgmeWPY9/wleReRbZ2MOZRyd" 15 | ]; 16 | in 17 | { 18 | nixosConfigurations.${hostName} = nixpkgs.lib.nixosSystem { 19 | inherit system; 20 | modules = [ 21 | ./disk-config.nix 22 | disko.nixosModules.disko 23 | ({ pkgs, ... }: { 24 | boot.loader = { 25 | systemd-boot.enable = true; 26 | efi.canTouchEfiVariables = true; 27 | }; 28 | networking = { inherit hostName; }; 29 | services.openssh.enable = true; 30 | environment.systemPackages = with pkgs; [ 31 | htop 32 | git 33 | neovim 34 | ]; 35 | 36 | users.users.root.openssh.authorizedKeys.keys = rootAuthorizedKeys; 37 | 38 | system.stateVersion = "23.11"; 39 | }) 40 | ]; 41 | }; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /global/static/nixos-asia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixos-asia/website/0a676a86e30aaa47cde46eb50ea0b4cf9ea27690/global/static/nixos-asia.png -------------------------------------------------------------------------------- /global/static/nixos-asia.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 46 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /global/templates/filters/query-timeline.tpl: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /global/templates/hooks/after-note.tpl: -------------------------------------------------------------------------------- 1 | 14 | 15 |
16 |
17 | 18 | 19 | 21 | 22 | 24 | 25 | 26 | 27 | 28 |
29 |
-------------------------------------------------------------------------------- /justfile: -------------------------------------------------------------------------------- 1 | default: 2 | @just --list 3 | 4 | # Run the website locally with hot reload 5 | run: 6 | nix run 7 | -------------------------------------------------------------------------------- /om.yaml: -------------------------------------------------------------------------------- 1 | ci: 2 | default: 3 | ROOT: 4 | dir: . 5 | nix-modules-1: 6 | dir: ./global/nix-modules/1 7 | nix-modules-2: 8 | dir: ./global/nix-modules/2 9 | nix-modules-3: 10 | dir: ./global/nix-modules/3 11 | nix-modules-4: 12 | dir: ./global/nix-modules/4 13 | nix-modules-5: 14 | dir: ./global/nix-modules/5 15 | overrideInputs: 16 | flake4: ./global/nix-modules/4 17 | develop: 18 | default: 19 | readme: | 20 | 🍾 Welcome to nixos.asia website authoring. 21 | 22 | To run the English website locally for rapid edit-preview cycles, run: 23 | 24 | ```sh 25 | nix run .#en # Or, just: nix run 26 | ```` 27 | --------------------------------------------------------------------------------