Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pkgs/dmd): Automate definition of package versions #9

Merged
merged 21 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c827699
docs(license): Add MIT license
PetarKirov Jan 28, 2024
adf1c78
build(direnv): Upgrade `nix-direnv` to 3.0.4
PetarKirov Jan 28, 2024
8a50c62
ci(gh-actions): Remove the "Magic Nix Cache" action
PetarKirov Jan 28, 2024
3e1fae5
ci(gh-actions): Cancel old pipelines to the same PR/branch
PetarKirov Jan 28, 2024
827972e
build(shell.nix): Add `dtools` dep
PetarKirov Sep 25, 2023
42cb7e4
style(nix): Format files with `alejandra`
PetarKirov Jan 27, 2024
5b66020
config(git): Ignore `bin/` folder
PetarKirov Jan 27, 2024
d0b4d0b
improve(scripts/fetch_binary.d): Print result as json
PetarKirov Sep 24, 2023
6cbd3a6
wip: refactor(script): Factor-out common code
PetarKirov Sep 29, 2023
b4b9bfd
improve(scripts/fetch_binary.d): Add ldc_src option
PetarKirov Jan 27, 2024
f68f8f1
feat(pkgs/dmd-binary): Generate `supported-binary-versions.json`
PetarKirov Sep 25, 2023
7e6f9db
feat(pkgs/dmd-binary): Add versions: 2.079.1 - 2.089.1
PetarKirov Jan 26, 2024
eb5be99
feat(pkgs/dmd): Implement version-catalog metadata infra
PetarKirov Sep 21, 2023
39c1576
feat(pkgs/dub): Implement version-catalog metadata infra
PetarKirov Jan 27, 2024
60afeed
feat(pkgs/ldc): Implement version-catalog metadata infra
PetarKirov Jan 27, 2024
b871b43
fix(lib/mk-gh-actions-matrix): Escape package name which are not prop…
PetarKirov Jan 25, 2024
27f0b67
build(pkgs): Implement build-status infrastructure
PetarKirov Jan 25, 2024
d5da1a5
docs(readme): Initial pass over the docs
PetarKirov Jan 28, 2024
89cb222
build(flake.nix/inputs): Add `flake-compat`
PetarKirov Jan 28, 2024
3502a9f
feat(default.nix): Add compatibility-shim for pre-Flakes Nix
PetarKirov Jan 28, 2024
9967cdb
docs(readme): Document pre-flake usage
PetarKirov Jan 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# shellcheck shell=bash
if ! has nix_direnv_version || ! nix_direnv_version 2.4.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.4.0/direnvrc" "sha256-XQzUAvL6pysIJnRJyR7uVpmUSZfc7LSgWQwq/4mBr1U="
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
fi

dotenv_if_exists
nix_direnv_watch_file shell.nix
watch_file shell.nix
use flake
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
generate-matrix:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -44,9 +48,6 @@ jobs:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v9

- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2

- uses: cachix/cachix-action@v14
with:
name: ${{ vars.CACHIX_CACHE }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ result
.direnv/

# Dub
.dub
.dub/
bin/

# Dotenv
.env
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Petar Kirov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
183 changes: 183 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<div align="center" style="margin: 1em 0 3em 0;">

# ![dlang-nix][dlang-nix-badge]

</div>

<div align="center">

[![Built with Nix][built-with-nix-badge]][nix]
[![Built with D][built-with-d-badge]][d]
![GitHub Actions][github-actions-badge]
![GitHub License][github-license-badge]

</div>

This projects provides Nix derivations for building reproducible and declarative development environments for the D programming language.

Currently

This project provides Nix expressions for building DMD, LDC and DUB.

## Usage

### Nix Flakes

While Nix Flakes are still experimental, they are the recommended way to use
this project, as `flake.lock` files ensure that you will be able to reproduce
the exact same build in the future. Furthermore, Flakes allow you to benefit
from the our binary cache -
[dlang-community.cachix.org][dlang-community-cachix], which is hosted by Cachix.

#### View available packages

```bash
nix flake show github:PetarKirov/dlang-nix
```

#### Enter a shell with a particular version of DMD and DUB installed

```bash
➤ nix shell \
github:PetarKirov/dlang-nix#dmd-2_102_2 \
github:PetarKirov/dlang-nix#dub-1_30_0

➤ dmd --version
DMD64 D Compiler v2.102.2

Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved written by Walter Bright

➤ dub --version
DUB version 1.30.0, built on Jan 1 1980
```

#### Add to your local Nix flakes registry

```bash
➤ nix registry add d github:PetarKirov/dlang-nix

➤ nix shell d#dmd-2_102_2 d#dub-1_30_0

➤ dmd --version
DMD64 D Compiler v2.102.2

Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved written by Walter Bright

➤ dub --version
DUB version 1.30.0, built on Jan 1 1980
```

#### Install packages to your Nix profile

```bash
➤ nix profile install d#dmd-2_102_2 d#dub-1_30_0 d#ldc_
```

#### Creating declarative & reproducible development environment

Add the following `flake.nix` to your project:

```nix
{
inputs = {
dlang-nix.url = "github:PetarKirov/dlang-nix";
nixpkgs.follows = "dlang-nix/nixpkgs";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
};

outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "x86_64-darwin" "aarch64-darwin"];
perSystem = { inputs', ... }: {
devShells.default = pkgs.mkShell {
packages = [
inputs'.dlang-nix.packages.ldc
inputs'.dlang-nix.packages.dub
];
};
};
};
}
```

And then run `nix develop` to enter a shell with the latest LDC and DUB installed:

```bash
$ dub
bash: dub: command not found

$ nix develop

$ dub --version
DUB version 1.30.0, built on Jan 1 1980
```

You can find the full example in [`templates/devshell/`](./templates/devshell/).

### Pre-flakes usage

The `default.nix` file in the root of this repo exposes all flake outputs as
Nix attributes. This is useful for users who haven't yet made the jump to the
Nix Flakes world.

For example, if you have an existing `shell.nix` file, all you need to do is add
the changes marked as "NEW" from the snippet below:

```nix
{pkgs ? import <nixpkgs> {}}: let
# NEW: Import the dlang-nix Nix library:
dlang-nix = import (pkgs.fetchFromGitHub {
owner = "PetarKirov";
repo = "dlang.nix";
rev = "3502a9f6dd2074c2f84d49baa5043f6601ca6407";
hash = "sha256-djp8c2iONh+ET+wHbPLruNTuF7xSAYoMmwp1HfsrVTA=";
});

# NEW: Add `dpkgs` shorthand:
dpkgs = dlang-nix.packages."${pkgs.system}";
in
pkgs.mkShell {
packages = [
# NEW: Reference D-related packages from `dpkgs`:
dpkgs.dmd
dpkgs.dub
];
}
```

You can find the full example in
[`templates/pre-flake-devshell/`](./templates/pre-flake-devshell/).

## Source and binary variants

DMD and LDC packages come in two variants: `binary` and `source`.

The `binary` variants are based on the the official DMD and LDC releases, but
repackaged with `autoPatchelfHook` / `fixDarwinDylibNames`.

The `source` variants are built from source using the `binary` package for the
first step of the bootstrap process.

As far as users of this repo are concerned, both the `binary` and `source`
variants are distributed as pre-built binaries via the
[dlang-community.cachix.org][dlang-community-cachix] binary cache.

This is useful for building custom versions of DMD and LDC, or for building DMD
and LDC with custom patches.

[d]: https://dlang.org
[nix]: https://nixos.org

[built-with-nix-badge]: https://img.shields.io/static/v1?logo=nixos&logoColor=white&label=&message=Built%20with%20Nix&color=41439a&style=for-the-badge
[built-with-d-badge]: https://img.shields.io/static/v1?logo=d&logoColor=white&label=&message=Built%20with%20D&color=B03931&style=for-the-badge

[dlang-community-cachix]: https://dlang-community.cachix.org

[github-license-badge]: https://img.shields.io/github/license/PetarKirov/dlang-nix?style=for-the-badge

[github-actions-badge]: https://img.shields.io/badge/github%20actions-black.svg?style=for-the-badge&logo=github&logoColor=white

[dlang-nix-badge]: ./docs/img/dlang.nix-badge.svg
10 changes: 10 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;
flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
thisFlake = import flake-compat {src = ./.;};
in
thisFlake.defaultNix
10 changes: 10 additions & 0 deletions docs/img/dlang.nix-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;

flake-compat.url = "github:edolstra/flake-compat";

flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
Expand Down
13 changes: 13 additions & 0 deletions lib/build-status.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{lib, ...}: {
getBuildStatus = package: version: system: let
data = lib.importJSON ./../pkgs/${package}/build-status.json;
in
data.${version}.${system}
or {
# If not build status is found, we assume that the package builds
# successfully with no workarounds.
build = true;
check = true;
skippedTests = [];
};
}
6 changes: 4 additions & 2 deletions lib/mk-gh-actions-matrix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# "macos-latest-xlarge" = "aarch64-darwin";
};

inherit (import ./build-status.nix {inherit lib;}) getBuildStatus;

mkGHActionsMatrix = {
include = lib.pipe (builtins.attrNames nixSystemToGHPlatform) [
(builtins.concatMap
Expand All @@ -23,9 +25,9 @@
p = self.packages.${system}.${package};
in {
os = platform;
allowedToFail = builtins.elem system (p.passthru.allowedToFailOn or []);
allowedToFail = !(p.passthru.buildStatus or (throw "${package} does not expose build status")).build;
inherit system package;
attrPath = "packages.${system}.${package}";
attrPath = "packages.${system}.${lib.strings.escapeNixIdentifier package}";
})
(builtins.attrNames self.packages.${system})
))
Expand Down
Loading
Loading