neosyn/flake.nix
2024-12-04 17:57:35 +01:00

135 lines
4.2 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/staging";
lix = {
url = "https://git.lix.systems/lix-project/lix/archive/main.tar.gz";
flake = false;
};
lix-module = {
url = "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz";
inputs.nixpkgs.follows = "nixpkgs";
inputs.lix.follows = "lix";
};
};
outputs = { self, nixpkgs, lix-module, ... }: let
inherit (builtins) mapAttrs match;
inherit (lib) filterAttrs genAttrs;
lib = nixpkgs.lib.extend (import ./lib.nix);
systems = [ "riscv64-linux" "aarch64-linux" "x86_64-linux" ];
packages = builtins.readDir ./packages
|> filterAttrs (name: type: (type == "regular" && match "[-.+_?=0-9a-zA-Z]+\.nix" name != null)
|| (type == "directory" && match "[-.+_?=0-9a-zA-Z]+" name != null))
|> lib.mapAttrs' (name: type: {
name = if type == "regular" then lib.removeSuffix ".nix" name else name;
value =
let path = if type == "directory" then "${name}/package.nix" else name;
in ./packages/${path};
});
in {
inherit lib;
packages = self.legacyPackages
|> mapAttrs (system: pkgs: mapAttrs (name: path: pkgs.${name}) packages);
overlays = let
lib' = final: prev: { inherit lib; };
packages' = final: prev: packages |> mapAttrs (name: path: final.callPackage path { });
in {
default = lib.composeManyExtensions (with self.overlays; [
lib'
packages'
lix
stdenv
alloc
non-x86-build
non-x86-host
#security
modern
python
fixes
]);
lib = lib';
packages = packages';
lix = lix-module.overlays.default;
} // (builtins.readDir ./overlays
|> filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name)
|> lib.mapAttrs' (name: type: {
name = lib.removeSuffix ".nix" name;
value = import ./overlays/${name};
}));
legacyPackages = genAttrs systems (system: let
pkgs' = import nixpkgs {
localSystem = {
inherit system;
gcc.arch = {
riscv64-linux = "rv64gc";
aarch64-linux = "armv8.2-a+fp16+rcpc+dotprod";
x86_64-linux = "x86-64-v3";
}.${system};
};
overlays = [ self.overlays.default ];
config.allowUnfree = true;
};
in import nixpkgs {
localSystem = pkgs'.hostPlatform;
overlays = [ self.overlays.default ];
config = {
allowUnfree = true;
replaceStdenv = { pkgs }:
import ./stdenv.nix pkgs' pkgs.stdenv;
replaceCrossStdenv = { buildPackages, baseStdenv }:
import ./stdenv.nix pkgs' baseStdenv;
};
});
nixosModules = {
default = import ./module.nix;
};
hydraJobs = let
inherit (builtins) filter attrNames;
inherit (lib) any concat hydraJob;
inherit (lib.meta) platformMatch;
extra = import ./hydra.nix;
in {
stdenv = self.legacyPackages |> mapAttrs (system: pkgs: hydraJob pkgs.stdenv);
} // {
nixos = self.legacyPackages |> mapAttrs (system: pkgs: let
nixos = lib.nixosSystem {
modules = [
self.nixosModules.default {
system.stateVersion = "25.05";
nixpkgs = { inherit (pkgs) hostPlatform overlays config; };
boot = {
kernel.enable = false;
initrd.enable = false;
loader.grub.enable = false;
};
users.allowNoPasswordLogin = true;
}
];
};
in hydraJob nixos.config.system.build.toplevel);
} // lib.foldlAttrs (jobs: system: pkgs: let
inherit (pkgs.stdenv) hostPlatform;
names = extra ++ attrNames (self.overlays.default pkgs pkgs) |> filter (name: pkgs ? ${name});
in lib.recursiveUpdate jobs (genAttrs names (name: pkgs.${name})
|> filterAttrs (name: pkg: lib.isDerivation pkg
&& (pkg.meta.hydraPlatforms or pkg.meta.platforms or [ ] |> any (platformMatch hostPlatform))
&& !(pkg.meta.badPlatforms or [ ] |> any (platformMatch hostPlatform)))
|> mapAttrs (name: pkg: { ${system} = hydraJob pkg; }))) { } self.legacyPackages;
};
}