Skip to content

Commit 2676ab4

Browse files
authored
feat: remove snowfall and use flake-parts (#12)
- Snowfall lib is a bit opinionated and its better to rely on something less intrusive. - We now use `flake-parts` where we load all `.parts.nix` modules with `import-tree`. - Toolchain files can be placed in the folder `./tools/nix/toolchains` which then can be used to define `devShells` in `./tools/nix/shells` . Each `toolchain-*.nix` file returns an attrset of devenv modules (can be functions or pure attrsets, currently only attrsets are used). - The `perSystem` flake-parts config receives two additional parameters `pkgs` and `pkgsStable` which are the imported `nixpkgs` and `nixpkgs-stable` inputs. - `just/nix.just` is introduced to outsource some stuff. - python env in `setup` only calls `uv sync` which is better, respecting the set variables `UV_PROJECT_ENVIRONMENT` etc.
1 parent b7d07d9 commit 2676ab4

78 files changed

Lines changed: 1909 additions & 1655 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/actions/setup-nix/action.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ inputs:
1212
runs:
1313
using: "composite"
1414
steps:
15-
- uses: cachix/install-nix-action@v30
15+
- uses: cachix/install-nix-action@v31
1616
with:
1717
nix_path: nixpkgs=channel:nixos-unstable
18-
- uses: cachix/cachix-action@v15
18+
- uses: cachix/cachix-action@v16
1919
with:
2020
name: "${{ inputs.cachix_cache_name }}"
2121
authToken: "${{ inputs.cachix_auth_token }}"

justfile

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ output_dir := root_dir / ".output"
66
flake_dir := root_dir / "./tools/nix"
77

88
mod maintenance "./tools/just/maintenance.just"
9+
mod nix "./tools/just/nix.just"
910

1011
# Default target if you do not specify a target.
1112
default:
@@ -38,20 +39,8 @@ nix-list *args:
3839

3940
# Enter the default Nix development shell.
4041
develop *args:
41-
just nix-develop default "$@"
42+
just nix::develop default "$@"
4243

4344
# Enter the CI Nix development shell.
4445
ci *args:
45-
just nix-develop ci "$@"
46-
47-
# Enter the Nix development shell `$1` and execute the command `${@:2}`.
48-
[private]
49-
nix-develop *args:
50-
#!/usr/bin/env bash
51-
set -eu
52-
cd "{{root_dir}}"
53-
shell="$1"; shift 1;
54-
args=("$@") && [ "${#args[@]}" != 0 ] || args="$SHELL"
55-
nix develop --no-pure-eval --accept-flake-config \
56-
"{{flake_dir}}#$shell" \
57-
--command "${args[@]}"
46+
just nix::develop ci "$@"

src/.jinja/common/justfile

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ flake_dir := root_dir / "tools/nix"
66
output_dir := root_dir / ".output"
77
build_dir := output_dir / "build"
88

9+
mod nix "./tools/just/nix.just"
10+
911
# Default target if you do not specify a target.
1012
default:
1113
just --list --unsorted
1214

1315
# Enter the default Nix development shell and execute the command `"$@`.
1416
develop *args:
15-
just nix-develop "default" "$@"
17+
just nix::develop "default" "$@"
1618

1719
# Format the project.
1820
format *args:
@@ -25,22 +27,10 @@ setup *args:
2527

2628
# Run commands over the ci development shell.
2729
ci *args:
28-
just nix-develop "ci" "$@"
30+
just nix::develop "ci" "$@"
2931

3032
## Nix Stuff ==================================================================
3133
# Show all packages configured in the Nix `flake.nix`.
3234
nix-list *args:
3335
cd tools/nix && nix flake --no-pure-eval show
34-
35-
# Enter the Nix `devShell` with name `$1` and execute the command `${@:2}` (default command is '$SHELL')
36-
[private]
37-
nix-develop *args:
38-
#!/usr/bin/env bash
39-
set -eu
40-
cd "{{root_dir}}"
41-
shell="$1"; shift 1;
42-
args=("$@") && [ "${#args[@]}" != 0 ] || args="$SHELL"
43-
nix develop --no-pure-eval --accept-flake-config \
44-
"{{flake_dir}}#$shell" --command "${args[@]}"
45-
## ============================================================================
4636
{%- endraw -%}

src/generic/tools/ci/general.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ function ci::setup_python_venv() {
6767
root_dir=$(git rev-parse --show-toplevel)
6868

6969
# If VIRTUAL_ENV is set use it.
70-
local venv_dir="${VIRTUAL_ENV:-$root_dir/.venv}"
71-
ci::print_info "Python virtual env. dir '$venv_dir' set."
72-
if [ ! -d "$venv_dir" ]; then
73-
ci::print_info "Setting up venv environment in '$venv_dir'."
74-
uv venv "$venv_dir" &>/dev/null
75-
fi
70+
export VIRTUAL_ENV="${VIRTUAL_ENV:-$root_dir/.venv}"
71+
export UV_PROJECT_ENVIRONMENT="$VIRTUAL_ENV"
72+
73+
ci::print_info "Python virtual env. dir '$UV_PROJECT_ENVIRONMENT' set."
7674

77-
ci::print_info "Installing pip dependencies..."
78-
uv pip install -r "$root_dir/pyproject.toml" &>/dev/null
75+
if [ ! -d "$UV_PROJECT_ENVIRONMENT" ]; then
76+
ci::print_info "Setting up venv environment in '$UV_PROJECT_ENVIRONMENT'."
77+
uv sync
78+
fi
7979
}

src/generic/tools/just/nix.just

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
set positional-arguments
2+
set shell := ["bash", "-cue"]
3+
4+
default:
5+
just --list --unsorted -f "{{source_file()}}"
6+
7+
# Enter the Nix development shell `$1` and execute the command `${@:2}`.
8+
[no-cd]
9+
develop *args:
10+
#!/usr/bin/env bash
11+
set -eu
12+
root_dir=$(git rev-parse --show-toplevel) || exit 1
13+
flake_dir="$root_dir/tools/nix"
14+
15+
shell="$1"; shift 1;
16+
args=("$@") && [ "${#args[@]}" != 0 ] ||
17+
args=(env SHELL="$SHELL" "$SHELL")
18+
19+
nix_args=("--no-pure-eval")
20+
21+
nix develop \
22+
"${nix_args[@]}" \
23+
--accept-flake-config \
24+
"$flake_dir#$shell" \
25+
--command "${args[@]}"
26+
27+
# Start an Nix interpreter with loaded flake.
28+
[no-cd]
29+
repl *args:
30+
#!/usr/bin/env bash
31+
set -eu
32+
33+
root_dir=$(git rev-parse --show-toplevel) || exit 1
34+
flake_dir="$root_dir/tools/nix"
35+
nix_args=("--no-pure-eval" "$@")
36+
37+
nix repl \
38+
"${nix_args[@]}" \
39+
--accept-flake-config \
40+
"$flake_dir"
41+
42+
# Build a package in the `packages` output of `flake.nix`
43+
alias build := package
44+
[no-cd]
45+
package attrname *args:
46+
#!/usr/bin/env bash
47+
set -eu
48+
root_dir=$(git rev-parse --show-toplevel) || exit 1
49+
flake_dir="$root_dir/tools/nix"
50+
nix_args=("${@:2}")
51+
52+
mkdir -p .output/package
53+
outlink=".output/package/{{attrname}}"
54+
nix build \
55+
--accept-flake-config \
56+
"${nix_args[@]}" \
57+
-L "$flake_dir#{{attrname}}" \
58+
--out-link "$outlink" --json
59+
60+
# Show all packages.
61+
[no-cd]
62+
package-show:
63+
#!/usr/bin/env bash
64+
set -eu
65+
root_dir=$(git rev-parse --show-toplevel) || exit 1
66+
flake_dir="$root_dir/tools/nix"
67+
68+
# We cannot use `nix flake show` due to other systems where
69+
# IFD (import-from-derivation -> from-yaml Nix derivation)
70+
# does not work.
71+
system=$(nix eval --impure --raw --expr builtins.currentSystem)
72+
nix eval --json "$flake_dir#packages.$system" | jq

0 commit comments

Comments
 (0)