summaryrefslogtreecommitdiff
path: root/templates/standard/flake.nix
blob: 23f6853ad2e153c948073d92e54081a6be4db777 (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
{
  description = "";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

  outputs =
    { self, nixpkgs }:

    let
      inherit (nixpkgs) lib;

      systems = [
        "x86_64-linux"
        "aarch64-linux"
        "x86_64-darwin"
        "aarch64-darwin"
      ];

      forAllSystems = lib.genAttrs systems;
    in

    {
      checks = forAllSystems (
        system:

        let
          pkgs = nixpkgs.legacyPackages.${system};

          mkCheck =
            name: deps: script:
            pkgs.runCommand name { nativeBuildInputs = deps; } ''
              ${script}
              touch $out
            '';
        in

        {
          nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] "nixfmt --check ${self}/**.nix";
        }
      );

      devShells = forAllSystems (
        system:

        let
          pkgs = nixpkgs.legacyPackages.${system};
        in

        {
          default = import ./shell.nix {
            inherit pkgs;
            inherit (self.packages.${system}) hello;
          };
        }
      );

      formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);

      nixosModules.default = lib.modules.importApply ./nix/module.nix { inherit self; };

      packages = forAllSystems (
        system:

        let
          pkgs = nixpkgs.legacyPackages.${system};

          pkgs' = import ./default.nix { inherit pkgs; };
        in

        pkgs' // { default = pkgs'.hello or pkgs.emptyFile; }
      );
    };
}