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

  inputs = {
    nixpkgs.url = "nixpkgs/nixos-unstable";
  };

  outputs = {
    self,
    nixpkgs,
    ...
  }: let
    version = builtins.substring 0 8 self.lastModifiedDate;

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

    forAllSystems = nixpkgs.lib.genAttrs systems;
    nixpkgsFor = forAllSystems (system:
      import nixpkgs {
        inherit system;
        overlays = [self.overlays.default];
      });

    packageFn = pkgs: let
      inherit (pkgs.lib) licenses maintainers platforms;
    in {
      hello = pkgs.stdenv.mkDerivation rec {
        pname = "hello";
        inherit version;

        src = builtins.path {
          name = "${pname}-src";
          path = ./.;
        };

        installPhase = ''
          echo "hi" > $out
        '';

        meta = {
          description = "";
          homepage = "";
          license = licenses.mit;
          maintainers = [maintainers.getchoo];
          platforms = platforms.linux;
        };
      };
    };
  in {
    devShells = forAllSystems (s: let
      pkgs = nixpkgsFor.${s};
      inherit (pkgs) mkShell;
    in {
      default = mkShell {
        packages = with pkgs; [
          bash
        ];
      };
    });

    formatter = forAllSystems (s: nixpkgsFor.${s}.alejandra);

    packages = forAllSystems (s: rec {
      inherit (nixpkgsFor.${s}) hello;
      default = hello;
    });

    overlays.default = final: _: packageFn final;
  };
}