diff --git a/flake.lock b/flake.lock index 23ee4e8..93f637f 100644 --- a/flake.lock +++ b/flake.lock @@ -175,6 +175,24 @@ "type": "github" } }, + "nix-darwin": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1772379624, + "narHash": "sha256-NG9LLTWlz4YiaTAiRGChbrzbVxBfX+Auq4Ab/SWmk4A=", + "owner": "nix-darwin", + "repo": "nix-darwin", + "rev": "52d061516108769656a8bd9c6e811c677ec5b462", + "type": "github" + }, + "original": { + "owner": "nix-darwin", + "repo": "nix-darwin", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1741037377, @@ -240,6 +258,22 @@ } }, "nixpkgs_3": { + "locked": { + "lastModified": 1765934234, + "narHash": "sha256-pJjWUzNnjbIAMIc5gRFUuKCDQ9S1cuh3b2hKgA7Mc4A=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "af84f9d270d404c17699522fab95bbf928a2d92f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { "locked": { "lastModified": 1771520265, "narHash": "sha256-ZVfCQHlXPP6ju9u9UQ4RrmVCif3wJvo5Scm5RhtGEZw=", @@ -260,7 +294,8 @@ "fakedir": "fakedir", "flake-utils": "flake-utils", "nix": "nix", - "nixpkgs": "nixpkgs_3" + "nix-darwin": "nix-darwin", + "nixpkgs": "nixpkgs_4" } }, "rust-overlay": { diff --git a/flake.nix b/flake.nix index d8bc1d3..499c30f 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; @@ -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 { diff --git a/src/builders/openssl.ab b/src/builders/openssl.ab index 409fd7e..1a2404b 100644 --- a/src/builders/openssl.ab +++ b/src/builders/openssl.ab @@ -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() { @@ -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: @@ -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") diff --git a/tests/darwin/generation.nix b/tests/darwin/generation.nix new file mode 100644 index 0000000..a430352 --- /dev/null +++ b/tests/darwin/generation.nix @@ -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 + ''; +} diff --git a/tests/default.nix b/tests/default.nix new file mode 100644 index 0000000..223737e --- /dev/null +++ b/tests/default.nix @@ -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 {}) diff --git a/tests/linux/building.nix b/tests/linux/building.nix new file mode 100644 index 0000000..1b2fc8e --- /dev/null +++ b/tests/linux/building.nix @@ -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") + ''; +} diff --git a/tests/generation.nix b/tests/linux/generation.nix similarity index 92% rename from tests/generation.nix rename to tests/linux/generation.nix index 834cd81..1a1b5d0 100644 --- a/tests/generation.nix +++ b/tests/linux/generation.nix @@ -1,4 +1,4 @@ -{ pkgs, nixie, sources, static-bins }: +{ pkgs, nixie, sources, static-bins, ... }: pkgs.testers.nixosTest { name = "nixie-generates-offline-script"; nodes = { diff --git a/tests/migration.nix b/tests/linux/migration.nix similarity index 95% rename from tests/migration.nix rename to tests/linux/migration.nix index f19b678..7096d63 100644 --- a/tests/migration.nix +++ b/tests/linux/migration.nix @@ -1,4 +1,4 @@ -{ pkgs, nixie, sources, static-bins }: +{ pkgs, nixie, sources, static-bins, ... }: pkgs.testers.nixosTest { name = "nixie-migrates-rootless-paths"; nodes = { diff --git a/tests/rootless.nix b/tests/linux/rootless.nix similarity index 90% rename from tests/rootless.nix rename to tests/linux/rootless.nix index 76b8b82..c02dcf5 100644 --- a/tests/rootless.nix +++ b/tests/linux/rootless.nix @@ -1,4 +1,4 @@ -{ pkgs, nixie, sources, static-bins }: +{ pkgs, nixie, sources, static-bins, ... }: pkgs.testers.nixosTest { name = "nixie-runs-rootless"; nodes = { diff --git a/tests/makeDarwinTest.nix b/tests/makeDarwinTest.nix new file mode 100644 index 0000000..63c481c --- /dev/null +++ b/tests/makeDarwinTest.nix @@ -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)