Skip to content

Commit

Permalink
Migrate nix environment to flakes (#604)
Browse files Browse the repository at this point in the history
* 🚧 WIP: migrating to flakes

* re-add commands

* darwin-only packages

* clean up a bunch of unused stack-to-nix stuff

* --nix-pure is working now?

* ditch lorri

* add cachix + note

* remove redundant --nix from commands

* tweak github actions cache

* action cache busting
  • Loading branch information
walkah authored Jun 23, 2022
1 parent 3435bd7 commit 6b78568
Show file tree
Hide file tree
Showing 23 changed files with 391 additions and 1,415 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eval "$(lorri direnv)"
use flake
60 changes: 30 additions & 30 deletions .github/workflows/artifacts-nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ jobs:
- ubuntu-latest

steps:
- uses: actions/checkout@v2
name: 📤 Checkout
if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/main'

- uses: cachix/install-nix-action@v16
name: ❄️ Set up Nix
with:
nix_path: nixpkgs=channel:nixos-unstable

- uses: actions/cache@v2
name: 🗄️ Cache ~/.stack
with:
path: ~/.stack
key: ${{ matrix.os }}-stack-nix-4

- name: 🏗️ Build
run: |
nix-shell --command build
- name: 🏺 Upload CLI Artifact
uses: actions/upload-artifact@v2
with:
name: fission-cli-${{ matrix.os }}-nix
path: ./.stack-work/**/*-nix/**/bin/fission

- name: 🏺 Upload Server Artifact
uses: actions/upload-artifact@v2
with:
name: fission-server-${{ matrix.os }}-nix
path: ./.stack-work/**/*-nix/**/bin/fission-server
- uses: actions/checkout@v2
name: 📤 Checkout
if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/main'

- uses: cachix/install-nix-action@v16
name: ❄️ Set up Nix
with:
nix_path: nixpkgs=channel:nixos-unstable

- uses: actions/cache@v2
name: 🗄️ Cache ~/.stack
with:
path: ~/.stack
key: ${{ matrix.os }}-stack-nix-${{ hashFiles('stack.yaml.lock') }}

- name: 🏗️ Build
run: |
nix-shell --command build
- name: 🏺 Upload CLI Artifact
uses: actions/upload-artifact@v2
with:
name: fission-cli-${{ matrix.os }}-nix
path: ./.stack-work/**/*-nix/**/bin/fission

- name: 🏺 Upload Server Artifact
uses: actions/upload-artifact@v2
with:
name: fission-server-${{ matrix.os }}-nix
path: ./.stack-work/**/*-nix/**/bin/fission-server
30 changes: 15 additions & 15 deletions .github/workflows/ci-nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ jobs:
- ubuntu-latest

steps:
- uses: actions/checkout@v2
name: 📤 Checkout
if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/main'
- uses: actions/checkout@v2
name: 📤 Checkout
if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/main'

- uses: cachix/install-nix-action@v16
name: ❄️ Set up Nix
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/install-nix-action@v16
name: ❄️ Set up Nix
with:
nix_path: nixpkgs=channel:nixos-unstable

- uses: actions/cache@v2
name: 🗄️ Cache ~/.stack
with:
path: ~/.stack
key: ${{ matrix.os }}-stack-nix-ci-4
- uses: actions/cache@v2
name: 🗄️ Cache ~/.stack
with:
path: ~/.stack
key: ${{ matrix.os }}-stack-nix-${{ hashFiles('stack.yaml.lock') }}

- name: 🧪 Test
run: |
nix-shell --command quality
- name: 🧪 Test
run: |
nix-shell --command quality
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,4 @@ MigrationBackup/

fission-web-server/data/
fission-web-server/.env
.direnv/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ Web server, database, 3rd party integrations
# Building

Fission is built inside of a pure Nix shell via the [Stack integration](https://docs.haskellstack.org/en/stable/nix_integration/). This means that you _should_ only need to type `stack build` to do a complete build of all packages.

If you're using a nix shell, you can use `cachix` to prevent re-building dependencies (particularly on `aarch64-darwin`) via: `cachix use fission-codes`.
28 changes: 13 additions & 15 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{ haskellNixSrc ? builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz
}:

let
haskellNix = import haskellNixSrc { };
pkgs = import haskellNix.sources.nixpkgs-unstable haskellNix.nixpkgsArgs;

pkgSet = pkgs.haskell-nix.mkStackPkgSet {
stack-pkgs = import ./nix/pkgs.nix;
pkg-def-extras = [];
modules = [];
};

in
pkgSet.config.hsPkgs
(import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{
src = ./.;
}).defaultNix
60 changes: 60 additions & 0 deletions flake.lock

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

67 changes: 67 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
description = "Fission tools";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-22.05";
flake-utils.url = "github:numtide/flake-utils";

flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};

outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let

pkgs = nixpkgs.legacyPackages.${system};

# Inspired by https://www.tweag.io/blog/2022-06-02-haskell-stack-nix-shell/
stack-wrapped = pkgs.symlinkJoin {
name = "stack";
paths = [ pkgs.stack ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/stack \
--add-flags "\
--nix \
--nix-pure \
--nix-shell-file=nix/stack-integration.nix \
"
'';
};

# Wrapper commands for convenience
commands = import ./nix/commands.nix;
server-path = "~/.local/bin/fission-server";
tasks = commands {
inherit pkgs;
inherit server-path;
inherit stack-wrapped;
};

# The default version of HLS (with binary cache) is built with GHC 9.0.1
# We can get this version working with our current set up, but it builds
# from source (and takes a long time).
#
# The prebuilt package is marked as broken on aarch64-darwin
haskellPackages = pkgs.haskell.packages.ghc8107;
in
{
devShells.default = pkgs.mkShell {
name = "fission";
buildInputs = [
stack-wrapped
haskellPackages.haskell-language-server
pkgs.cachix
pkgs.nixpkgs-fmt
pkgs.stylish-haskell
tasks
];
NIX_PATH = "nixpkgs=" + pkgs.path;
};
}
);
}
1 change: 0 additions & 1 deletion nix-tools

This file was deleted.

Loading

0 comments on commit 6b78568

Please sign in to comment.