Skip to content

Commit

Permalink
Add nix flakes support (#594)
Browse files Browse the repository at this point in the history
* flake.nix: add basic support

* Use flake-compat to derive default.nix & shell.nix from flake.nix

- introduce flake-compat
- pin nixpkgs at flake.lock
- modify how we import default.nix/shell.nix

* Move pinned nixpkgs from dep/nixpkgs to flake.lock

* CI: now build and test with nix flake as well

* Up ver to 1.9.17.1
  • Loading branch information
TheKK committed Apr 14, 2021
1 parent 602c3de commit 1cd90be
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 32 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/ci.yaml
Expand Up @@ -13,7 +13,10 @@ jobs:
DOCKERTAG: latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v12
- uses: cachix/install-nix-action@v13
with:
extra_nix_config: |
experimental-features = nix-command flakes
# This also runs nix-build.
- uses: cachix/cachix-action@v8
with:
Expand All @@ -25,7 +28,13 @@ jobs:
- name: Build 🔧
run: |
nix-build -j4 --no-out-link ci.nix
# Test default.nix
nix-build -j4
# Test flake.nix
nix build --out-link flake-result
- name: Verify output of default.nix & flake.nix
run: |
[ $(readlink result) = $(readlink flake-result) ]
- name: Retrieve neuron version
run: |
echo "NEURONVER=$(./result/bin/neuron --version)" >> $GITHUB_ENV
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@ dist-*
.ghc.environment.*
result
result-2
result-data
.shake
.neuron
neuron.prof
Expand Down
6 changes: 3 additions & 3 deletions ci.nix
@@ -1,11 +1,11 @@
{ system ? builtins.currentSystem }:
let
pkgs = import ./dep/nixpkgs { inherit system; };
pkgs = import ./nixpkgs.nix { inherit system; };
in
pkgs.recurseIntoAttrs {
# Build both default.nix and shell.nix such that both derivations are
# pushed to cachix. This allows the development workflow (bin/run, etc.) to
# use cachix to full extent.
neuron = import ./default.nix {};
neuronShell = import ./shell.nix {};
neuron = import ./default.nix;
neuronShell = import ./shell.nix;
}
17 changes: 13 additions & 4 deletions default.nix
@@ -1,4 +1,13 @@
args@{ system ? builtins.currentSystem, ...}:
let
pkgs = import ./dep/nixpkgs { inherit system; } ;
in (import ./project.nix { pkgs = pkgs; } ).neuron
(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
2 changes: 0 additions & 2 deletions dep/nixpkgs/default.nix

This file was deleted.

7 changes: 0 additions & 7 deletions dep/nixpkgs/github.json

This file was deleted.

9 changes: 0 additions & 9 deletions dep/nixpkgs/thunk.nix

This file was deleted.

4 changes: 2 additions & 2 deletions docker.nix
Expand Up @@ -7,8 +7,8 @@
# --argstr tag <image-tag>
# )
let
pkgs = import ./dep/nixpkgs {};
neuron = import ./. {};
pkgs = import ./nixpkgs.nix {};
neuron = import ./.;
in {
name ? "sridca/neuron"
, tag ? "dev"
Expand Down
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.

28 changes: 28 additions & 0 deletions flake.nix
@@ -0,0 +1,28 @@
{
description = "Future-proof note-taking and publishing based on Zettelkasten";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/fcab19deb78fbb5ea24e19b133cf34358176396a";
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 = import nixpkgs { inherit system; };
project = import ./project.nix { inherit pkgs; };

in rec {
packages = { neuron = project.neuron; };
defaultPackage = packages.neuron;

apps = { neuron = flake-utils.lib.mkApp { drv = packages.neuron; }; };
defaultApp = apps.neuron;

devShell = project.shell;
});
}
2 changes: 1 addition & 1 deletion neuron.cabal
@@ -1,6 +1,6 @@
cabal-version: 2.4
name: neuron
version: 1.9.27.0
version: 1.9.27.1
license: AGPL-3.0-only
copyright: 2020 Sridhar Ratnakumar
maintainer: srid@srid.ca
Expand Down
8 changes: 8 additions & 0 deletions nixpkgs.nix
@@ -0,0 +1,8 @@
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nixpkgs = lock.nodes.nixpkgs.locked;

in import (fetchTarball {
url = "https://github.com/nixos/nixpkgs/archive/${nixpkgs.rev}.tar.gz";
sha256 = nixpkgs.narHash;
})
2 changes: 1 addition & 1 deletion project.nix
@@ -1,5 +1,5 @@
let
nixpkgs = import ./dep/nixpkgs {};
nixpkgs = import ./nixpkgs.nix {};
in {
pkgs ? nixpkgs,
pkgsForBins ? null,
Expand Down
14 changes: 13 additions & 1 deletion shell.nix
@@ -1 +1,13 @@
args@{ ... }: (import ./project.nix args).shell
(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 = ./.;
}).shellNix
2 changes: 1 addition & 1 deletion static.nix
@@ -1,7 +1,7 @@
args@{...}:
let
# FIXME: Use a nixpkgs that works with static builds
nixpkgs = import ./dep/nixpkgs args;
nixpkgs = import ./nixpkgs.nix args;
pkgs = nixpkgs.pkgsMusl;
in
(import ./project.nix {
Expand Down

0 comments on commit 1cd90be

Please sign in to comment.