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

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

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

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

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

    forAllSystems = fn: genSystems (sys: fn nixpkgsFor.${sys});
  in {
    devShells = forAllSystems (pkgs: {
      default = pkgs.mkShell {
        packages = with pkgs; [
          bash
        ];
      };
    });

    formatter = forAllSystems (p: p.alejandra);

    packages = forAllSystems (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;
        };
      };
    };
  };
}