Skip to content

Commit

Permalink
replace nix-shell with Nix Flake (#737)
Browse files Browse the repository at this point in the history
* replace `nix-shell` with Nix Flake

This `flake.nix` provides the same resources as the deleted Nix files with less code to maintain.

This commit does not fix/update the docs generation via Nix; this remains TODO.

* Nix Flake GitHub Action badge

* test Nix Flake on both Mac and Linux

* Apply suggestions from code review

Co-authored-by: Ken Micklas <[email protected]>

---------

Co-authored-by: Ken Micklas <[email protected]>
  • Loading branch information
peterbecich and kmicklas authored Jan 6, 2025
1 parent 8bab511 commit 6e85470
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 103 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
24 changes: 24 additions & 0 deletions .github/workflows/nix-flake.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Nix Flake"
on:
pull_request:
push:
jobs:
nix:
strategy:
fail-fast: true
matrix:
os:
- ubuntu-latest
- macos-latest
name: Nix on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: "Check `nix develop` shell"
run: nix develop --check
- name: "Check `nix develop` shell can run command"
run: nix develop --command "true"
- run: nix build
- run: nix flake check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ TAGS
docs/ChinookData
result
result-*
.direnv
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Beam: a type-safe, non-TH Haskell relational database library and ORM

[![Build status](https://github.com/haskell-beam/beam/workflows/Build/badge.svg)](https://github.com/haskell-beam/beam/workflows/Build/badge.svg)
[![Build status](https://github.com/haskell-beam/beam/actions/workflows/nix-flake.yaml/badge.svg)](https://github.com/haskell-beam/beam/actions/workflows/nix-flake.yaml)

If you use beam commercially, please consider a donation to make this project possible: https://liberapay.com/tathougies

Expand Down Expand Up @@ -79,12 +80,15 @@ to run this against. See the documentation for examples.

## Building the documentation

Beam uses `mkdocs` for its documentation generation. The included
`build-docs.sh` script can take care of building the documentation and serving
it locally. In order to use the tool though, make sure you have a python
installation with the `mkdocs` module installed. You can do this by creating a
virtualenv, and pip installing `mkdocs`, or in a Nix shell with
`nix-shell docs`.
Beam uses [`mkdocs`](https://www.mkdocs.org/) for its documentation generation.

### Requirements
* Python installation with [`mkdocs` module](https://pypi.org/project/mkdocs/)
* Alternatively, open the Nix Flake shell via `nix develop`.

Then run `build-docs.sh`.

TODO: define Nix package for docs bundle.

The documentation uses a custom Markdown preprocessor to automatically build
examples against the canonical Chinook database. By default, beam will build
Expand Down
4 changes: 1 addition & 3 deletions docs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
with nixpkgs;

let
beamLib = import ../nix/lib.nix { inherit nixpkgs; };
beamGhc = beamLib.makeBeamGhc ghc;
docsEnv = poetry2nix.mkPoetryEnv {
projectDir = ./.;
};
Expand Down Expand Up @@ -51,7 +49,7 @@ stdenv.mkDerivation {
[]
./..;
nativeBuildInputs = [
(beamGhc.ghc.withPackages beamLib.beamPackageList)
# (beamGhc.ghc.withPackages beamLib.beamPackageList)
docsEnv
poetry
postgresql
Expand Down
91 changes: 91 additions & 0 deletions flake.lock

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

62 changes: 62 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
haskell-flake.url = "github:srid/haskell-flake";

testcontainers.url =
"github:testcontainers/testcontainers-hs/e286bd2ba9747c2d8c3756a3a89910e579e318e3";
testcontainers.flake = false;
};
outputs = inputs@{ self, nixpkgs, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = nixpkgs.lib.systems.flakeExposed;
imports = [ inputs.haskell-flake.flakeModule ];

perSystem = { self', pkgs, ... }: {

haskellProjects.default = {
basePackages = pkgs.haskell.packages.ghc98;

packages = {
testcontainers.source = inputs.testcontainers;
};
settings = {
testcontainers.check = false;
beam-postgres.check = false;
};

devShell = {
enable = true;

hlsCheck.enable = false;

tools = hp: {
inherit (pkgs)
postgresql
sqlite-interactive
poetry
curl
pv # http://www.ivarch.com/programs/pv.shtml
;
};
};
};

packages.all = pkgs.symlinkJoin {
name = "all";
paths = [
self'.packages.beam-core
self'.packages.beam-migrate
self'.packages.beam-postgres
self'.packages.pagila
self'.packages.beam-sqlite
];
};

packages.default = self'.packages.all;

# docs = import ./docs { inherit nixpkgs; };
};
};
}
61 changes: 0 additions & 61 deletions nix/lib.nix

This file was deleted.

4 changes: 0 additions & 4 deletions nix/nixpkgs.nix

This file was deleted.

13 changes: 0 additions & 13 deletions release.nix

This file was deleted.

16 changes: 0 additions & 16 deletions shell.nix

This file was deleted.

0 comments on commit 6e85470

Please sign in to comment.