summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 70c1d19c8dbd78904a08932630cdf46a626c81ff (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
{
  description = "A small experiment in combining NixOS, musl, busybox, and other hipster trash";

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

  outputs =
    { self, nixpkgs }:
    let
      inherit (nixpkgs) lib;
      inherit (lib.systems.parse) abis tripleFromSystem;

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

      forAllSystems = lib.genAttrs systems;
      nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});

      # Get some extra information about all of our systems to use later
      parsedFor = forAllSystems (system: (lib.systems.elaborate system).parsed);

      # nixpkgs defaults to gnu/glibc when elaborating Linux doubles like
      # `x86_64-linux`. Make it use musl instead
      muslSystemFor = forAllSystems (system: parsedFor.${system} // { abi = abis.musl; });

      muslConfigurationFor = forAllSystems (
        system:
        lib.nixosSystem {
          modules = [
            ./configuration
            # Make sure our system configuration is built for musl
            { nixpkgs.hostPlatform.config = tripleFromSystem muslSystemFor.${system}; }
          ];
        }
      );
    in
    {
      checks = forAllSystems (
        system:
        let
          cpuArch = parsedFor.${system}.cpu.name;
        in
        {
          configuration = self.nixosConfigurations."musl-${cpuArch}".config.system.build.vm;
        }
      );

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

      nixosConfigurations = {
        musl-x86_64 = muslConfigurationFor.x86_64-linux;
        musl-aarch64 = muslConfigurationFor.aarch64-linux;
      };
    };
}