summaryrefslogtreecommitdiff
path: root/flake.nix
blob: e603e312105ce28a856bee38b46c22a6305234e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#──────────────────────────────────────────────────────────────────────────────┐
# SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/>             │
# SPDX-License-Identifier: LGPL-2.1-or-later                                   │
#──────────────────────────────────────────────────────────────────────────────┘
{
  description = "Nixtamal - A Nix version pinning tool with first-class support for Darcs, Pijul, and other VCS systems";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/16c7794d0a28b5a37904d55bcca36003b9109aaa";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [
            (import ./nix/overlay/default.nix)
            (import ./nix/overlay/development.nix)
            (import ./nix/overlay/check.nix)
          ];
        };
        
        # Build nixtamal package using callPackage
        nixtamalPkg = pkgs.callPackage ./nix/package/nixtamal.nix {
          nixtamal = null; # Prevent infinite recursion
        };
        
        # Development shell using the same approach as shell.nix
        devShell = pkgs.mkShell {
          buildInputs = (nixtamalPkg.buildInputs or []) ++ (nixtamalPkg.checkInputs or []);
          nativeBuildInputs = nixtamalPkg.nativeBuildInputs or [];
        };
      in
      {
        # Package outputs
        packages = {
          nixtamal = nixtamalPkg;
          default = nixtamalPkg;
        };

        # Development shell
        devShells.default = devShell;

        # Test suite integration
        checks = {
          # Basic check that the package builds
          nixtamal-build = nixtamalPkg;

          # Explicit test check
          nixtamal-test = nixtamalPkg;

          # Coverage instrumentation sanity check
          nixtamal-coverage = pkgs.runCommand "nixtamal-coverage-check"
            {
              nativeBuildInputs = (nixtamalPkg.nativeBuildInputs or [ ])
                ++ (nixtamalPkg.buildInputs or [ ])
                ++ (with pkgs.ocamlPackages; [
                  bisect_ppx
                  dune_3
                ]);
            }
            ''
              export HOME="$TMPDIR"
              cp -r ${nixtamalPkg.src} source
              chmod -R u+w source
              cd source

              BISECT_ENABLE=YES dune runtest --instrument-with bisect_ppx --force
              bisect-ppx-report summary --coverage-path _build/default/test > coverage-summary.txt

              mkdir -p "$out"
              cp coverage-summary.txt "$out"/
            '';
        };

        # Library outputs for ecosystem integration
        lib = {
          # Expose the nixtamal package for flake consumption
          nixtamal = nixtamalPkg;
          
          # Helper functions for hybrid workflows
          makeHybridInputs = { 
            extraInputs ? {}
          }: {
            inherit nixtamalPkg;
          } // extraInputs;

          # Utility to create flake-compatible inputs from nixtamal projects
          fromNixtamalProject = projectPath: 
            import (projectPath + "/nix/tamal") { 
              inherit system; 
              nixpkgs = pkgs;
            };
        };

        # App output for running nixtamal directly
        apps = {
          nixtamal = {
            type = "app";
            program = "${nixtamalPkg}/bin/nixtamal";
          };
          default = self.apps.${system}.nixtamal;
        };
      });
}