commit 57fa994768a224d41725c3760153bfbee2610c91 Author: outfoxxed Date: Sun Apr 20 21:48:59 2025 -0700 init diff --git a/boot.nix b/boot.nix new file mode 100644 index 0000000..9b50929 --- /dev/null +++ b/boot.nix @@ -0,0 +1,18 @@ +{ config, pkgs, ... }: { + boot = { + loader = { + grub.enable = false; + generic-extlinux-compatible.enable = true; + }; + + kernelPackages = pkgs.linuxPackages_latest; + }; + + fileSystems = { + "/" = { + fsType = "tmpfs"; + neededForBoot = true; + options = [ "mode=755" ]; + }; + }; +} diff --git a/builder.nix b/builder.nix new file mode 100644 index 0000000..dc71127 --- /dev/null +++ b/builder.nix @@ -0,0 +1,19 @@ +{ + nix = { + settings = { + builders-use-substitutes = true; + }; + + distributedBuilds = true; + buildMachines = [ { + hostName = "192.168.2.1"; + systems = [ "x86_64-linux" ]; + protocol = "ssh-ng"; + supportedFeatures = [ "big-parallel" "kvm" "nixos-test" "benchmark" ]; + speedFactor = 100; + maxJobs = 16; + sshUser = "nix-remote-build"; + sshKey = "/root/.ssh/id_build_server"; + } ]; + }; +} diff --git a/cpu.nix b/cpu.nix new file mode 100644 index 0000000..cbfcdfb --- /dev/null +++ b/cpu.nix @@ -0,0 +1,18 @@ +{ + nixpkgs.overlays = [(final: prev: { + stdenv = let + adapt = prev.stdenvAdapters; + unhardened = adapt.withDefaultHardeningFlags [] prev.stdenv; + #withflags = adapt.withCFlags [ "-misa-spec=2.2" ] unhardened; + in unhardened; + })]; + + nixpkgs.buildPlatform.system = "x86_64-linux"; + + nixpkgs.config.hostSystem = let + arch = "rv64imafdcv_zicbom_zicbob_zicboz_zicntr_zicond_zicsr_zifencei_zihintpause_zihpm_zfh_zfhmin_zkt_zba_zbb_zbc_zbs_zbkc_zvfh_zvfhmin_zvkt"; + in { + gcc.arch = arch; + system = "riscv64-unknown-linux-lp64d"; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..00e2ff6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1744932701, + "narHash": "sha256-fusHbZCyv126cyArUwwKrLdCkgVAIaa/fQJYFlCEqiU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b024ced1aac25639f8ca8fdfc2f8c4fbd66c48ef", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..29d5ce3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,38 @@ +{ + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + }; + + outputs = inputs @ { self, nixpkgs, ... }: { + nixosConfigurations = { + jupiter = nixpkgs.lib.nixosSystem rec { + system = "riscv64-linux"; + specialArgs = { + inherit self system inputs; + boot = self.packages.x86_64-linux.boot.entries; + }; + + modules = [ + ./cpu.nix + ./nixpkgs.nix + ./builder.nix + ./system.nix + ./boot.nix + + ./ghc.nix + ./riscvfixes.nix + ]; + }; + }; + + packages = { + x86_64-linux = let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + in { + boot = pkgs.linkFarm "boot" { + "ghc-9.4.8" = pkgs.pkgsCross.riscv64.haskell.compiler.native-bignum.ghc948; + }; + }; + }; + }; +} diff --git a/ghc.nix b/ghc.nix new file mode 100644 index 0000000..1eeef23 --- /dev/null +++ b/ghc.nix @@ -0,0 +1,101 @@ +# https://github.com/AlexandreTunstall/nixos-riscv/blob/master/modules/compilers/ghc.nix +{ boot, lib, ... }: + +{ + nixpkgs.overlays = lib.mkBefore [ + (self: super: let + mkBootCompiler = { drv, llvmPackages }: drv.overrideAttrs ({ passthru ? {}, ... }: { + passthru = passthru // { + inherit llvmPackages; + }; + }); + + mkBootPackages = { base, ghc }: let + buildHaskellPackages = base.override (old: { + inherit buildHaskellPackages ghc; + + overrides = bootOverrides; + }); + in buildHaskellPackages; + + hsLib = self.haskell.lib.compose; + + bootOverrides = self: super: { + mkDerivation = args: super.mkDerivation ({ + enableLibraryProfiling = false; + } // args); + + alex = hsLib.dontCheck super.alex; + data-array-byte = hsLib.dontCheck super.data-array-byte; + doctest = hsLib.dontCheck super.doctest; + extra = hsLib.dontCheck super.extra; + hashable = hsLib.dontCheck super.hashable; + optparse-applicative = hsLib.dontCheck super.optparse-applicative; + QuickCheck = hsLib.dontCheck super.QuickCheck; + temporary = hsLib.dontCheck super.temporary; + unordered-containers = hsLib.dontCheck super.unordered-containers; + vector = hsLib.dontCheck super.vector; + }; + + # There is no neater way of overriding Hadrian + withPatchedHadrian = ghc: ghc.override { + hadrian = hsLib.disableCabalFlag "threaded" (hsLib.appendPatches [ + (self.fetchpatch { + name = "enable-ghci.patch"; + url = "https://gitlab.haskell.org/ghc/ghc/-/commit/dd38aca95ac25adc9888083669b32ff551151259.patch"; + hash = "sha256-xqs6mw/akxMy+XmVabACzsIviIKP4fS0UEgTk0HJcIc="; + stripLen = 1; + }) + ] ghc.hadrian); + }; + + overrides = self: super: { + # Profiling is disabled for GHC on RISC-V due to size constraints + mkDerivation = args: super.mkDerivation ({ + enableLibraryProfiling = false; + } // args); + + # LLVM segfaults in one of the happy tests + happy = hsLib.dontCheck super.happy; + }; + + in { + haskell = super.haskell // { + compiler = { + ghc948Boot = mkBootCompiler { + drv = boot."ghc-9.4.8"; + llvmPackages = self.llvmPackages_15; + }; + + ghc966 = (withPatchedHadrian (super.haskell.compiler.ghc966.override { + bootPkgs = self.haskell.packages.ghc948Boot; + llvmPackages = self.llvmPackages_15; + })).overrideAttrs ({ patches ? [], ... }: { + patches = patches ++ [ + (self.fetchpatch { + name = "enable-ghci-hadrian.patch"; + url = "https://gitlab.haskell.org/ghc/ghc/-/commit/c5e47441ab2ee2568b5a913ce75809644ba83271.patch"; + hash = "sha256-t3KkuME6IqLWuESIMZ7OVAFu7s8G+x0ev+aVzBUqkhg="; + }) + ]; + }); + + ghc96 = self.haskell.compiler.ghc966; + }; + + packages = { + inherit (super.haskell.packages) ghc96; + + ghc966 = super.haskell.packages.ghc966.override { + inherit overrides; + }; + + ghc948Boot = mkBootPackages { + base = super.haskell.packages.ghc948; + ghc = self.pkgsBuildHost.haskell.compiler.ghc948Boot; + }; + }; + }; + }) + ]; +} diff --git a/nixpkgs.nix b/nixpkgs.nix new file mode 100644 index 0000000..4f8c491 --- /dev/null +++ b/nixpkgs.nix @@ -0,0 +1,20 @@ +{ inputs, ... }: { + nix = { + settings = { + experimental-features = [ "nix-command" "flakes" ]; + auto-optimise-store = true; + }; + + registry = { + nixpkgs.flake = inputs.nixpkgs; + }; + + nixPath = [ + "nixpkgs=/etc/nix/inputs/nixpkgs" + ]; + }; + + environment.etc = { + "nix/inputs/nixpkgs".source = inputs.nixpkgs.outPath; + }; +} diff --git a/riscvfixes.nix b/riscvfixes.nix new file mode 100644 index 0000000..c21132a --- /dev/null +++ b/riscvfixes.nix @@ -0,0 +1,51 @@ +{ + nixpkgs.overlays = [( + self: super: let + dontCheck = drv: drv.overrideAttrs (old: { + doCheck = false; + }); + + pyDontCheck = drv: drv.overridePythonAttrs (old: { + doCheck = false; + }); + + hsLib = self.haskell.lib.compose; + +in { + haskell = super.haskell // { + packages = super.haskell.packages // { + ghc964 = super.haskell.packages.ghc964.override { + overrides = hsSelf: hsSuper: { + # enableSeparateBinOutput causes cyclic references in build outputs + mkDerivation = self.lib.makeOverridable (args: hsSuper.mkDerivation (args // { + enableSeparateBinOutput = false; + })); + # Tests fail + happy = hsLib.dontCheck hsSuper.happy; + }; + }; + }; + }; + + libbsd = dontCheck super.libbsd; + libuv = dontCheck super.libuv; + + # Fails in ./configure when LuaJIT isn't available + neovim-unwrapped = super.neovim-unwrapped.overrideAttrs ({ preConfigure ? "", ... }: { + preConfigure = '' + ${preConfigure} + cmakeFlagsArray+=( -DPREFER_LUA=ON ) + ''; + }); + + pixman = dontCheck super.pixman; + protobuf = dontCheck super.protobuf; + + pythonPackagesExtensions = super.pythonPackagesExtensions ++ [ + (pySelf: pySuper: { + sphinx = pyDontCheck pySuper.sphinx; + }) + ]; +} + )]; +} diff --git a/system.nix b/system.nix new file mode 100644 index 0000000..60ee519 --- /dev/null +++ b/system.nix @@ -0,0 +1,20 @@ +{ pkgs, ... }: { + networking.hostName = "jupiter"; + system.stateVersion = "25.04"; + time.timeZone = "America/Vancouver"; + + environment.systemPackages = builtins.attrValues { + inherit (pkgs) vim; + }; + + users.users = { + admin = { + isNormalUser = true; + uid = 1000; + extraGroups = [ "wheel" ]; + initialPassword = "test"; + }; + }; + + security.rtkit.enable = true; +}