Initial import

This commit is contained in:
Mikael 2024-07-21 16:55:31 +02:00
commit a56bc1799a
8 changed files with 361 additions and 0 deletions

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
# Hidden files
.*
!.git*
# Nix
/result
/result-*

27
flake.lock Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1722062969,
"narHash": "sha256-QOS0ykELUmPbrrUGmegAUlpmUFznDQeR4q7rFhl8eQg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "b73c2221a46c13557b1b3be9c2070cc42cf01eb3",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

70
flake.nix Normal file
View file

@ -0,0 +1,70 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
nixConfig = {
extra-substituters = [ "https://cache.kyouma.net" ];
extra-trusted-public-keys = [ "cache.kyouma.net:Frjwu4q1rnwE/MnSTmX9yx86GNA/z3p/oElGvucLiZg=" ];
};
outputs = { self, nixpkgs, ... }@inputs:
let
inherit (builtins) mapAttrs;
inherit (nixpkgs) lib;
platforms = mapAttrs
(name: platform: lib.systems.elaborate platform)
(import ./platforms.nix);
in {
lib = {
inherit platforms;
replaceConfig = {
replaceStdenv =
{ pkgs }: pkgs.idiosyn pkgs.stdenv;
replaceCrossStdenv =
{ buildPackages, baseStdenv }: buildPackages.idiosyn baseStdenv;
};
};
overlays.default = import ./overlay.nix inputs;
nixosModules.default = { ... }: {
nixpkgs = {
overlays = [ self.overlays.default ];
config = self.lib.replaceConfig // {
allowUnsupportedSystem = true;
};
};
imports = [ ./module.nix ];
};
legacyPackages = mapAttrs (system: platform:
import nixpkgs {
localSystem = system;
crossSystem = platform;
overlays = [ self.overlays.default ];
config = self.lib.replaceConfig // {
allowUnsupportedSystem = true;
};
}) platforms;
nixosConfigurations = mapAttrs (system: platform: lib.nixosSystem {
modules = [
self.nixosModules.default
./nixos.nix {
nixpkgs.buildPlatform = system;
nixpkgs.hostPlatform = platform;
}
];
}) platforms;
hydraJobs = {
stdenv = mapAttrs (system: pkgs: pkgs.stdenv) self.legacyPackages;
nixos = mapAttrs (system: host: host.config.system.build.toplevel) self.nixosConfigurations;
pkgs = mapAttrs (system: pkgs: {
inherit (pkgs) rustc;
}) self.legacyPackages;
};
};
}

34
module.nix Normal file
View file

@ -0,0 +1,34 @@
{ config, lib, pkgs, modulesPath, ... }:
let
inherit (pkgs.stdenv) hostPlatform;
locale-archive-stub =
pkgs.stdenvNoCC.mkDerivation {
pname = "locale-archive-stub";
version = "0";
buildCommand = ''
mkdir -p "$out/lib/locale"
touch "$out/lib/locale/locale-archive"
'';
};
in {
disabledModules = [
(modulesPath + "/config/ldso.nix")
(modulesPath + "/config/stub-ld.nix")
(modulesPath + "/programs/nix-ld.nix")
];
config = lib.mkMerge [
(lib.mkIf hostPlatform.isMusl {
i18n.glibcLocales = lib.mkDefault locale-archive-stub;
i18n.supportedLocales = lib.mkDefault [ ];
programs.command-not-found.enable = lib.mkDefault false;
programs.less.lessopen = lib.mkDefault null;
security.pam.services.login.updateWtmp = lib.mkForce false;
services.nscd.enable = lib.mkForce false;
system.nssModules = lib.mkForce [ ];
})
];
}

18
nixos.nix Normal file
View file

@ -0,0 +1,18 @@
{ pkgs, ... }: {
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
fileSystems."/".label = "nixos";
security.sudo.wheelNeedsPassword = false;
services.getty.autologinUser = "nixos";
users.users.nixos = {
isNormalUser = true;
extraGroups = [ "wheel" ];
};
system.stateVersion = "24.11";
virtualisation.vmVariant.virtualisation.diskImage = null;
}

126
overlay.nix Normal file
View file

@ -0,0 +1,126 @@
{ nixpkgs, ... }: final: prev:
let
inherit (builtins)
trace traceVerbose;
inherit (lib.attrsets)
optionalAttrs;
inherit (lib.lists)
intersectLists
mutuallyExclusive
subtractLists
toList;
inherit (prev)
addAttrsToDerivation
fetchpatch
lib;
inherit (prev.stdenv)
hostPlatform;
pkgs = import nixpkgs {
inherit (final) overlays;
localSystem = final.buildPlatform;
crossSystem = final.hostPlatform;
config = removeAttrs final.config [
"replaceStdenv"
"replaceCrossStdenv"
];
};
idiosyn = import ./stdenv.nix pkgs;
pname = base:
if base ? pname
then "package ${base.pname}"
else "unknown package";
attrs = pkg: fun: pkg.overrideAttrs (base:
if base ? idiosynAttrGuard
then traceVerbose "Attribute override applied repeatedly on ${pname base}," { }
else { idiosynAttrGuard = null; } // (fun base));
patch = pkg: patches: attrs pkg (base:
if mutuallyExclusive (base.patches or [ ]) patches
then { patches = base.patches or [ ] ++ patches; }
else trace "Patches applied previously for ${pname base}: ${intersectLists base.patches patches}" {
patches = base.patches ++ subtractLists base.patches patches;
});
nocheck = pkg: attrs pkg (base: {
doCheck = false;
doInstallCheck = false;
});
alpine-patches = "https://git.alpinelinux.org/aports/plain";
gentoo-patches = "https://gitweb.gentoo.org/repo/gentoo.git/plain";
in optionalAttrs (!prev ? idiosyn) ({
inherit idiosyn;
buildPackages = prev.buildPackages // {
inherit (final) stdenv;
};
busybox = prev.busybox.override {
stdenv = final.gccStdenv;
};
efivar = attrs prev.efivar (base: {
buildFlags = base.buildFlags or [ ]
++ [ "CC=$(CC)" ];
});
icu = attrs prev.icu (base: {
configureFlags = base.configureFlags or [ ]
++ [ "ac_cv_c_bigendian=${if hostPlatform.isBigEndian then "yes" else "no"}" ];
});
keyutils = attrs prev.keyutils (base: {
LDFLAGS = base.LDFLAGS or [ ]
++ [ "-Wl,--undefined-version" ];
});
kexec-tools = prev.kexec-tools.override {
stdenv = final.gccStdenv;
};
libgcrypt = attrs prev.libgcrypt (base: {
configureFlags = base.configureFlags or [ ]
++ [ "--disable-jent-support" ];
});
mbrola = prev.mbrola.override {
stdenv = addAttrsToDerivation (base: {
env = base.env or { } // {
NIX_CFLAGS_COMPILE = toString (toList base.env.NIX_CFLAGS_COMPILE or [ ]
++ [ "-Wno-error=implicit-function-declaration" ]);
};
}) final.stdenv;
};
musl = (attrs prev.musl (base: {
LDFLAGS = base.LDFLAGS or [ ]
++ [ "-Wl,-u,__dls2" ];
})).override { inherit final.stdenv; };
python3 = prev.python3.override {
packageOverrides = py-final: py-prev: optionalAttrs hostPlatform.isRiscV {
psutil = nocheck py-prev.psutil;
};
};
python3Packages = final.python3.pkgs;
time = patch prev.time [
(fetchpatch {
url = "${gentoo-patches}/sys-process/time/files/time-1.9-implicit-func-decl-clang.patch";
hash = "sha256-Asz8mWxVh4y3In5NU1dDV7nrJO+XlIhmKIvVFuPH8QE=";
})
];
} // optionalAttrs hostPlatform.isRiscV {
boehm-gc = nocheck prev.boehm-gc;
libuv = nocheck prev.libuv;
})

23
platforms.nix Normal file
View file

@ -0,0 +1,23 @@
{
"x86_64-linux" = {
system = "x86_64-linux";
config = "x86_64-unknown-linux-musl";
gcc.arch = "x86-64-v3";
useLLVM = true;
linker = "lld";
};
"aarch64-linux" = {
system = "aarch64-linux";
config = "aarch64-unknown-linux-musl";
gcc.arch = "armv8.2-a";
useLLVM = true;
linker = "lld";
};
"riscv64-linux" = {
system = "aarch64-linux";
config = "riscv64-unknown-linux-musl";
gcc.arch = "rv64imafdc_zicsr_zba_zbb";
useLLVM = true;
linker = "lld";
};
}

56
stdenv.nix Normal file
View file

@ -0,0 +1,56 @@
pkgs: stdenv:
let
inherit (pkgs) addAttrsToDerivation mimalloc overrideCC;
inherit (pkgs.lib) getLib optionalAttrs optionals toList;
inherit (pkgs.llvmPackages_latest) clangUseLLVM bintools;
inherit (stdenv) hostPlatform targetPlatform;
cflags = [
"-pipe" # Prefer pipes over temporary files between stages
"-O2" # Safe compiler optimisations
"-flto"
];
ldflags = [
"-O2" # Enable tail merging of strings
"--hash-style=gnu" # Produce only DT_GNU_HASH
"--icf=safe" # Fold identical code where safe
"--lto-O2"
"-L${getLib mimalloc}/lib" "-lmimalloc"
];
rustflags = [
"-C opt-level=2"
"-C linker-flavor=lld"
"-C lto"
"-C linker-plugin-lto"
] ++ optionals (targetPlatform.isx86_64 && targetPlatform ? gcc.arch) [
"-C target-cpu=${targetPlatform.gcc.arch}"
] ++ map (flag: "-C link-arg=${flag}") ldflags;
pname = base:
if base ? pname
then "package ${base.pname}"
else "unknown package";
in addAttrsToDerivation (base:
if base ? idiosynStdenvGuard
then builtins.traceVerbose "stdenv override applied repeatedly for ${pname base}," { }
else {
idiosynStdenvGuard = null;
env = (base.env or { }) // optionalAttrs (!base ? NIX_CFLAGS_COMPILE) {
NIX_CFLAGS_COMPILE =
toString (toList base.env.NIX_CFLAGS_COMPILE or [ ] ++ cflags);
} // optionalAttrs (base ? env.NIX_LDFLAGS) {
NIX_LDFLAGS =
toString (toList base.env.NIX_LDFLAGS or [ ] ++ ldflags);
};
NIX_RUSTFLAGS = toList base.NIX_RUSTFLAGS or [ ] ++ rustflags;
} // optionalAttrs (base ? env.NIX_CFLAGS) {
NIX_CFLAGS_COMPILE = toList base.NIX_CFLAGS_COMPILE or [ ] ++ cflags;
} // optionalAttrs (!base ? env.NIX_LDFLAGS) {
NIX_LDFLAGS = toList base.NIX_LDFLAGS or [ ] ++ ldflags;
}) (overrideCC stdenv (clangUseLLVM.override { inherit bintools; }))