Skip to content

Commit

Permalink
nix: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pnmadelaine committed Sep 29, 2023
1 parent bc21311 commit 45cc7d8
Show file tree
Hide file tree
Showing 45 changed files with 433 additions and 314 deletions.
14 changes: 14 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(
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
1 change: 1 addition & 0 deletions doc/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(import ../nix/devshells.nix {}).doc
10 changes: 6 additions & 4 deletions flake.lock

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

55 changes: 8 additions & 47 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
description = "Typhon";

inputs = {
flake-utils.url = "github:numtide/flake-utils";
flake-compat.url = "github:edolstra/flake-compat";

flake-utils.url = "flake-utils";

nixpkgs.url = "nixpkgs/nixos-unstable";

crane = {
url = "github:ipetkov/crane";
inputs.flake-compat.follows = "flake-compat";
inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-overlay.follows = "rust-overlay";
};

rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
Expand All @@ -19,50 +25,5 @@
};
};

outputs = inputs @ {
self,
flake-utils,
nixpkgs,
crane,
rust-overlay,
}: let
lib = import ./lib inputs;
in
flake-utils.lib.eachSystem lib.systems (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [(import rust-overlay)];
};
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
targets = ["wasm32-unknown-unknown"];
};
craneLib = crane.lib.${system}.overrideToolchain rustToolchain;

typhon = pkgs.callPackage ./nix/server.nix {inherit craneLib;};
typhon-webapp = pkgs.callPackage ./nix/webapp.nix {inherit craneLib;};
typhon-doc = pkgs.callPackage ./nix/doc.nix {};
typhon-api-client-test =
pkgs.callPackage ./nix/api-client-test.nix {inherit craneLib;};
typhon-devshell =
pkgs.callPackage ./nix/devshell.nix {inherit rustToolchain;};
in {
packages = {
inherit typhon typhon-webapp typhon-doc typhon-api-client-test;
default = typhon;
};

devShells.default = typhon-devshell;

checks = {
api = pkgs.callPackage ./nix/check-api.nix {
inherit typhon typhon-api-client-test;
};
formatted = pkgs.callPackage ./nix/check-formatted.nix {inherit rustToolchain;};
nixos = pkgs.callPackage ./nix/nixos/test.nix {typhon = self;};
};
})
// {
inherit lib;
nixosModules.default = import ./nix/nixos/typhon.nix self;
};
outputs = inputs: import ./nix/outputs.nix {sources = inputs;};
}
3 changes: 0 additions & 3 deletions lib/systems.nix

This file was deleted.

25 changes: 0 additions & 25 deletions nix/api-client-test.nix

This file was deleted.

42 changes: 0 additions & 42 deletions nix/check-api.nix

This file was deleted.

18 changes: 0 additions & 18 deletions nix/check-formatted.nix

This file was deleted.

82 changes: 82 additions & 0 deletions nix/checks/api.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
sources ? import ../sources.nix,
system ? builtins.currentSystem or "unknown-system",
pkgs ? import ../nixpkgs.nix {inherit sources system;},
rust ? import ../rust.nix {inherit sources system;},
}: let
inherit (pkgs) lib;

inherit (rust) craneLib;

src = lib.sourceByRegex ../.. [
"Cargo.toml"
"Cargo.lock"
"typhon.*"
];

cargoToml = ../../typhon-api-client-test/Cargo.toml;

cargoExtraArgs = "-p typhon-api-client-test";

nativeBuildInputs = [
pkgs.openssl
pkgs.pkg-config
];

cargoArtifacts = craneLib.buildDepsOnly {
inherit
src
cargoToml
cargoExtraArgs
nativeBuildInputs
;
};

typhon-api-client-test = craneLib.buildPackage {
inherit
src
cargoToml
cargoArtifacts
cargoExtraArgs
nativeBuildInputs
;
};

typhon = import ../packages/server.nix {inherit sources system;};
in
pkgs.stdenv.mkDerivation {
name = "test-typhon-api";
phases = ["configurePhase" "installPhase"];
DATABASE_URL = "/tmp/typhon.sqlite";
configurePhase = ''
export HOME=$(mktemp -d)
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
'';
installPhase = ''
# start Typhon server
typhon -p $(echo -n password | sha256sum | head -c 64) -j null -w "" &
sleep 1
# run the test client
PROJECT_DECL="path:${../../tests/empty}" typhon-api-client-test
# kill the server and creates $out
kill %1 && touch $out
'';
nativeBuildInputs = builtins.attrValues {
inherit
typhon
typhon-api-client-test
;
inherit
(pkgs)
coreutils
bubblewrap
diesel-cli
pkg-config
sqlite
nix
;
};
}
8 changes: 8 additions & 0 deletions nix/checks/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
sources ? import ../sources.nix,
system ? builtins.currentSystem or "unknown-system",
}: {
api = import ./api.nix {inherit sources system;};
formatted = import ./formatted.nix {inherit sources system;};
nixos = import ./nixos.nix {inherit sources system;};
}
19 changes: 19 additions & 0 deletions nix/checks/formatted.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
sources ? import ../sources.nix,
system ? builtins.currentSystem or "unknown-system",
pkgs ? import ../nixpkgs.nix {inherit sources system;},
rust ? import ../rust.nix {inherit sources system;},
}:
pkgs.stdenv.mkDerivation {
name = "formatted";
src = ../..;
nativeBuildInputs = [
pkgs.alejandra
rust.rustToolchain
];
buildPhase = ''
alejandra -c .
cargo fmt --check
'';
installPhase = "touch $out";
}
14 changes: 6 additions & 8 deletions nix/nixos/test.nix → nix/checks/nixos.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
typhon,
testers,
sources ? import ../sources.nix,
system ? builtins.currentSystem or "unknown-system",
pkgs ? import ../nixpkgs.nix {inherit sources system;},
typhon ? import ../nixos/typhon.nix {inherit sources;},
}:
testers.nixosTest ({
pkgs,
lib,
...
}: {
pkgs.testers.nixosTest ({pkgs, ...}: {
name = "typhon-test";

nodes = {
typhon = {...}: {
nix.settings.experimental-features = ["nix-command" "flakes"];
imports = [typhon.nixosModules.default];
imports = [typhon];
services.typhon = {
enable = true;
hashedPassword = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824";
Expand Down
42 changes: 0 additions & 42 deletions nix/devshell.nix

This file was deleted.

Loading

0 comments on commit 45cc7d8

Please sign in to comment.