-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
posts/2024-12-19/01: add "Quick bits: basic flake.nix template"
- Loading branch information
1 parent
3719c27
commit 4522bf8
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
posts/2024-12-19/01-quick-bits-basic-flake-nix-template.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Quick bits: basic flake.nix template | ||
|
||
Sometimes I want a really basic `flake.nix` that has no dependencies except for | ||
`nixpkgs` itself, e.g.: I want to avoid | ||
[flake-utils](https://github.com/numtide/flake-utils) or any other dependency. | ||
So, here you go: | ||
|
||
```nix | ||
{ | ||
description = "Description"; | ||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | ||
}; | ||
outputs = | ||
{ self, nixpkgs, ... }: | ||
let | ||
supportedSystems = [ | ||
"aarch64-linux" | ||
"x86_64-linux" | ||
"aarch64-darwin" | ||
"x86_64-linux" | ||
]; | ||
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. | ||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems; | ||
# Nixpkgs instantiated for supported system types. | ||
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); | ||
in | ||
{ | ||
packages = forAllSystems ( | ||
system: | ||
let | ||
pkgs = nixpkgsFor.${system}; | ||
in | ||
rec { | ||
default = pkgs.hello; | ||
} | ||
); | ||
}; | ||
} | ||
``` | ||
|
||
Not sure where I grabbed the definition for `forAllSystems` and `nixpkgsFor`. I | ||
have the impression it was in a [Julia Evans blog post](https://jvns.ca/), but | ||
I can't find it. | ||
|
||
Anyway, it is here for me to remember, and it may help someone else. |