summaryrefslogtreecommitdiff
path: root/templates/basic/flake.nix
blob: 00ec696d81168b61c3cca5e5d2b43cf34a9c62ca (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
{
  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];
      });

    forEachSystem = fn:
      forAllSystems (system:
        fn {
          inherit system;
          pkgs = nixpkgsFor.${system};
        });
  in {
    devShells = forEachSystem ({pkgs, ...}: let
      inherit (pkgs) mkShell;
    in {
      default = mkShell {
        packages = with pkgs; [
          bash
        ];
      };
    });

    formatter = forEachSystem ({pkgs, ...}: pkgs.alejandra);

    packages = forEachSystem ({pkgs, ...}: {
      inherit (pkgs) hello;
      default = pkgs.hello;
    });

    overlays.default = _: prev: {
      hello = prev.stdenv.mkDerivation {
        pname = "hello";
        inherit version;

        src = self;

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

        meta = with prev.lib; {
          description = "";
          homepage = "";
          license = licenses.mit;
          maintainers = [maintainers.getchoo];
          platforms = platforms.linux;
        };
      };
    };
  };
}