Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion flake.lock

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

28 changes: 15 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{ description = "Put Nix in everything!";

inputs.nixpkgs.url = github:nixos/nixpkgs;
inputs.amber.url = github:amber-lang/amber;
inputs.nix.url = github:nixos/nix/2.26.2;
inputs.fakedir =
{ url = github:nixie-dev/fakedir;
inputs = {
nixpkgs.url = github:nixos/nixpkgs;
amber.url = github:amber-lang/amber;
nix.url = github:nixos/nix/2.26.2;
fakedir = {
url = github:nixie-dev/fakedir;
inputs.nixpkgs.follows = "nixpkgs";
inputs.utils.follows = "flake-utils";
};

# Only required for macOS unit tests
nix-darwin.url = github:nix-darwin/nix-darwin;
};

nixConfig.extra-substituters = "https://nix-wrap.cachix.org";
nixConfig.extra-trusted-public-keys = "nix-wrap.cachix.org-1:FcfSb7e+LmXBZE/MdaFWcs4bW2OQQeBnB/kgWlkZmYI=";

outputs = { self, nix, nixpkgs, flake-utils, fakedir, amber, ... }:
outputs = { self, nix, nixpkgs, nix-darwin, flake-utils, fakedir, amber, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = import nixpkgs { inherit system; };
Expand All @@ -35,13 +40,10 @@
libfakedir = fakedir.packages.${system}.fakedir;
} else {});

checks =
let callTest = f: pkgs.callPackage f { inherit (self.packages.${system}) nixie sources static-bins; };
in {
generation = callTest ./tests/generation.nix;
rootless = callTest ./tests/rootless.nix;
migration = callTest ./tests/migration.nix;
};
checks = import ./tests {
inherit nixpkgs system nix-darwin;
inherit (self.outputs.packages.${system}) nixie sources static-bins;
};

devShells = {
default = pkgs.mkShell {
Expand Down
26 changes: 13 additions & 13 deletions src/builders/openssl.ab
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@
import { env_var_test, env_var_set } from "std/env"
import { split_lines } from "std/text"

import { pull_source_file } from "../resources.ab"
import { get_dll_ext, get_cache_root } from "../platform.ab"
import { pull_source_file } from "../resources.ab"

import { pkg_exists, step_title, get_source_root } from "./common.ab"

/// Scans through and builds generated headers required for building OpenSSL.
///
/// For some reason the OpenSSL Makefile does not specify dependencies to those
/// targets, meaning we cannot simply `make libcrypto.so`.
fun make_headers()
{
for header in split_lines(trust $grep ".*\\.h:" ./Makefile | cut -f 1 -d :$) {
$make {header}$?
}
}

/// This function runs within the source directory, in a subshell.
fun build_openssl_inner()
{
Expand All @@ -30,7 +19,15 @@ fun build_openssl_inner()
trust $chmod +x ./config$

$./config$?
make_headers()?

// For some reason the OpenSSL Makefile does not specify dependencies to those
// targets, meaning we cannot simply `make libcrypto.so`.
for header in split_lines(trust $grep ".*\\.h:" ./Makefile | cut -f 1 -d :$) {
$make {header}$?
}
for hinc in split_lines(trust $grep ".*\\.inc:" ./Makefile | cut -f 1 -d :$) {
$make {hinc}$?
}
$make libcrypto.{dll_ext} libcrypto.pc$?

// Building libssl is:
Expand All @@ -50,6 +47,9 @@ pub fun build_openssl()
{
let source_root = get_source_root()
let cache_root = get_cache_root()
// Workaround for amber-lang/amber#1043
let dll_ext = get_dll_ext()
let _ = split_lines("hello")

step_title("libcrypto")

Expand Down
15 changes: 15 additions & 0 deletions tests/darwin/generation.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ config, pkgs, nixie, sources, static-bins ... }:

{
environment.systemPackages = with pkgs; [
nixie
git
];

test = ''
git init
nixie init --sources-derivation ${sources} --binaries-derivation ${static-bins} --with-binaries
./nix --nixie-extract
ls nixie | grep nix.Darwin.x86_64
'';
}
30 changes: 30 additions & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ nixpkgs, nixie, sources, static-bins
, system ? builtins.currentSystem, nix-darwin ? {}, ... }@as:

let
pkgs = import nixpkgs { inherit system; };

makeDarwinTest = import ./makeDarwinTest.nix as;
makeLinuxTest = f: pkgs.callPackage f as;

makeTest = t:
if pkgs.stdenv.isLinux then makeLinuxTest ./linux/${t}.nix
else if pkgs.stdenv.isDarwin then makeDarwinTest ./darwin/${t}.nix
else throw "Unsupported platform: ${pkgs.stdenv.platform}";
in {

# Tests available on both platforms
building = makeTest "building";
generation = makeTest "generation";
migration = makeTest "migration";
rootless = makeTest "rootless";

} // (if pkgs.stdenv.isLinux then {

# Linux-specific tests go here

} else if pkgs.stdenv.isDarwin then {

# macOS-specific tests go here

} else {})
27 changes: 27 additions & 0 deletions tests/linux/building.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ pkgs, nixie, sources, static-bins, ... }:
pkgs.testers.nixosTest {
name = "nixie-builds-nix-from-source";
nodes = {
machine = {
environment.systemPackages = with pkgs; [
nixie
git

gcc
pkg-config
gnumake
flex
bison
perl
];
};
};

testScript = ''
start_all()

machine.succeed("git init")
machine.succeed("nixie init --sources-derivation ${sources} --binaries-derivation ${static-bins} --with-sources")
machine.succeed("./nix --nixie-no-precompiled --version")
'';
}
2 changes: 1 addition & 1 deletion tests/generation.nix → tests/linux/generation.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, nixie, sources, static-bins }:
{ pkgs, nixie, sources, static-bins, ... }:
pkgs.testers.nixosTest {
name = "nixie-generates-offline-script";
nodes = {
Expand Down
2 changes: 1 addition & 1 deletion tests/migration.nix → tests/linux/migration.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, nixie, sources, static-bins }:
{ pkgs, nixie, sources, static-bins, ... }:
pkgs.testers.nixosTest {
name = "nixie-migrates-rootless-paths";
nodes = {
Expand Down
2 changes: 1 addition & 1 deletion tests/rootless.nix → tests/linux/rootless.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, nixie, sources, static-bins }:
{ pkgs, nixie, sources, static-bins, ... }:
pkgs.testers.nixosTest {
name = "nixie-runs-rootless";
nodes = {
Expand Down
51 changes: 51 additions & 0 deletions tests/makeDarwinTest.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{ nixpkgs, nixie, sources, static-bins
, system ? builtins.currentSystem, nix-darwin ? {}, ... }@as:

let
buildFromConfig = configuration: sel: sel
(import ./. { inherit nixpkgs configuration system; }).config;
in

test:
let
testName =
builtins.replaceStrings [ ".nix" ] [ "" ]
(builtins.baseNameOf test);

configuration =
{ config, lib, pkgs, ... }:
with lib;
{
imports = [ test ];

options = {
out = mkOption {
type = types.package;
};

test = mkOption {
type = types.lines;
};
};

config = {
system.stateVersion = lib.mkDefault config.system.maxStateVersion;

system.build.run-test = pkgs.runCommand "darwin-test-${testName}"
{ allowSubstitutes = false; preferLocalBuild = true; }
''
#! ${pkgs.stdenv.shell}
set -e

echo >&2 "running tests for system ${config.out}"
echo >&2
${config.test}
echo >&2 ok
touch $out
'';

out = config.system.build.toplevel;
};
};
in
buildFromConfig configuration (config: config.system.build.run-test)