Skip to content

Commit

Permalink
Flake organization improvements (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
aldoborrero committed Sep 26, 2023
1 parent cb8e7d8 commit 96bd37d
Show file tree
Hide file tree
Showing 18 changed files with 306 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.2.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.0/direnvrc" "sha256-5EwyKnkJNQeXrRkYbwwRBcXbibosCJqyIUuz9Xq+LRc="
fi
nix_direnv_watch_file ./nix/shell.nix
nix_direnv_watch_file ./flake-shell.nix
use flake
38 changes: 38 additions & 0 deletions checks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{inputs, ...}: {
perSystem = {
pkgs,
config,
...
}: {
checks = let
devour-flake = pkgs.callPackage inputs.devour-flake {};
in
{
nix-build-all = pkgs.writeShellApplication {
name = "nix-build-all";
runtimeInputs = [
pkgs.nix
devour-flake
];
text = ''
# Make sure that flake.lock is sync
nix flake lock --no-update-lock-file
# Do a full nix build (all outputs)
devour-flake . "$@"
'';
};
}
# mix in tests
// config.testing.checks;

devshells.default.commands = [
{
category = "Tools";
name = "check";
help = "Checks the source tree";
command = "nix flake check";
}
];
};
}
16 changes: 2 additions & 14 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
{system ? builtins.currentSystem}: 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;
};

flake = import flake-compat {
inherit system;
src = ./.;
};
let
flake = import ./flake-compat.nix {};
in
flake.defaultNix
16 changes: 16 additions & 0 deletions flake-compat.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
system ? builtins.currentSystem,
flakeLockPath ? ./flake.lock,
src ? ./.,
}: let
lock = builtins.fromJSON (builtins.readFile flakeLockPath);
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;
};
in
import flake-compat {
inherit system src;
}
8 changes: 3 additions & 5 deletions nix/shell.nix → flake-shell.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
perSystem = {
pkgs,
inputs',
pkgsUnstable,
...
}: let
inherit (inputs'.nixpkgs-unstable.legacyPackages) nix-update statix mkdocs;
in {
}: {
devshells.default = {
name = "ethereum.nix";
packages = [
packages = with pkgsUnstable; [
nix-update
statix
mkdocs
Expand Down
23 changes: 20 additions & 3 deletions flake.lock

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

37 changes: 28 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,55 @@
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat.url = "github:nix-community/flake-compat";
devour-flake = {
url = "github:srid/devour-flake";
flake = false;
};
};

outputs = inputs @ {
flake-parts,
nixpkgs,
...
}: let
lib = nixpkgs.lib.extend (final: _: import ./nix/lib final);
lib = nixpkgs.lib.extend (final: _: import ./lib.nix final);
in
flake-parts.lib.mkFlake {
inherit inputs;
specialArgs = {
inherit lib; # make custom lib available to parent functions
};
specialArgs = {inherit lib;};
}
rec {
imports = [
{_module.args.lib = lib;} # make custom lib available to all `perSystem` functions
./nix
./packages
./modules
./mkdocs.nix
inputs.devshell.flakeModule
inputs.flake-parts.flakeModules.easyOverlay
inputs.flake-root.flakeModule
inputs.hercules-ci-effects.flakeModule
inputs.treefmt-nix.flakeModule
./checks.nix
./flake-shell.nix
./formatter.nix
./mkdocs.nix
./modules
./packages
];
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
perSystem = {system, ...}: {
_module.args = {
pkgs = lib.mkNixpkgs {
inherit system;
inherit (inputs) nixpkgs;
};
pkgsUnstable = lib.mkNixpkgs {
inherit system;
nixpkgs = inputs.nixpkgs-unstable;
};
};
};
herculesCI.ciSystems = with builtins; filter (system: (match ".*-darwin" system) == null) systems;
};
}
12 changes: 4 additions & 8 deletions nix/formatter.nix → formatter.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{inputs, ...}: {
imports = [
inputs.treefmt-nix.flakeModule
];

{
perSystem = {
config,
pkgs,
Expand All @@ -11,11 +7,13 @@
treefmt.config = {
inherit (config.flake-root) projectRootFile;
package = pkgs.treefmt;

flakeFormatter = true;
flakeCheck = true;
programs = {
alejandra.enable = true;
deadnix.enable = true;
prettier.enable = true;
statix.enable = true;
};
};

Expand All @@ -27,7 +25,5 @@
command = "nix fmt";
}
];

formatter = config.treefmt.build.wrapper;
};
}
Loading

0 comments on commit 96bd37d

Please sign in to comment.