From 91bc09157ae3ff260618f5ad59562115cba7ff2c Mon Sep 17 00:00:00 2001 From: Felix Suchert Date: Tue, 24 Jan 2023 10:43:41 +0100 Subject: [PATCH] Switch to flake-based configuration --- entropy/kanshi/config | 4 +- entropy/nixos/configuration.nix | 6 +- entropy/nixos/flake.lock | 61 +++++++++++++++ entropy/nixos/flake.nix | 43 ++++++++++ entropy/nixos/mlir/flake.lock | 26 ++++++ entropy/nixos/mlir/flake.nix | 135 ++++++++++++++++++++++++++++++++ 6 files changed, 272 insertions(+), 3 deletions(-) create mode 100644 entropy/nixos/flake.lock create mode 100644 entropy/nixos/flake.nix create mode 100644 entropy/nixos/mlir/flake.lock create mode 100644 entropy/nixos/mlir/flake.nix diff --git a/entropy/kanshi/config b/entropy/kanshi/config index 9dca6fd..99ce39d 100644 --- a/entropy/kanshi/config +++ b/entropy/kanshi/config @@ -3,8 +3,8 @@ profile office { # output eDP-1 disable # output "Dell Inc. DELL U2415 08DXD6121ARL" mode 1920x1200 position 0,0 transform 90 # output "Dell Inc. DELL S3221QS 4HMVTB3" mode 3840x2160@30Hz position 1200,400 scale 1.25 - # output "Dell Inc. DELL S3221QS 4HMVTB3" mode 3840x2160@30Hz position 1920,0 scale 1.25 - output "Dell Inc. DELL S3221QS 4HMVTB3" mode 3840x2160@30Hz position 1920,0 scale 1 + output "Dell Inc. DELL S3221QS 4HMVTB3" mode 3840x2160@30Hz position 1920,0 scale 1.25 + # output "Dell Inc. DELL S3221QS 4HMVTB3" mode 3840x2160@30Hz position 1920,0 scale 1 # output "Dell Inc. DELL S3221QS 4HMVTB3" mode 2560x1440 position 1920,0 # output "Dell Inc. DELL U2419HC 6Z7JSS2" mode 1920x1080 position 1920,420 # output "Dell Inc. DELL U2419HC 879JSS2" mode 1920x1080 position 3840,0 transform 90 diff --git a/entropy/nixos/configuration.nix b/entropy/nixos/configuration.nix index 2ca8d7d..8b42c81 100644 --- a/entropy/nixos/configuration.nix +++ b/entropy/nixos/configuration.nix @@ -12,7 +12,7 @@ let in { imports = - [ + [ # Include the results of the hardware scan. ./hardware-configuration.nix @@ -203,6 +203,10 @@ in valgrind heaptrack #lingua-franca-ide + + # provided by my own overlay + mlir + ## I heard you like man pages? man-pages ## git and friends diff --git a/entropy/nixos/flake.lock b/entropy/nixos/flake.lock new file mode 100644 index 0000000..6ccab9c --- /dev/null +++ b/entropy/nixos/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "mlir": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1, + "narHash": "sha256-h25YqRVPLnAurF22yqPcSM7p3LwuZRwNODaO4k7nl94=", + "path": "/nix/store/dnijhprbg3ixgn69fg48i25fns88w2yj-source/entropy/nixos/mlir", + "type": "path" + }, + "original": { + "path": "/nix/store/dnijhprbg3ixgn69fg48i25fns88w2yj-source/entropy/nixos/mlir", + "type": "path" + } + }, + "nixos-hardware": { + "locked": { + "lastModified": 1673803274, + "narHash": "sha256-zaJDlHFXewT4KUsidMpRcPE+REymGH1Y3Eoc3Pjv4Xs=", + "owner": "NixOS", + "repo": "nixos-hardware", + "rev": "7bd6b87b3712e68007823e8dd5c37ee9b114fee3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixos-hardware", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1673957332, + "narHash": "sha256-njH7Szk1BLVWGMw7IRibgGejSlxXHj9saZHfH20gHdk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b83e7f5a04a3acc8e92228b0c4bae68933d504eb", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-22.11", + "type": "indirect" + } + }, + "root": { + "inputs": { + "mlir": "mlir", + "nixos-hardware": "nixos-hardware", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/entropy/nixos/flake.nix b/entropy/nixos/flake.nix new file mode 100644 index 0000000..4e05b83 --- /dev/null +++ b/entropy/nixos/flake.nix @@ -0,0 +1,43 @@ +{ + description = "NixOS configuration"; + + inputs = { + nixpkgs.url = "nixpkgs/nixos-22.11"; + nixos-hardware.url = "github:NixOS/nixos-hardware/master"; + #home-manager = { + #url = "github:nix-community/home-manager"; + #inputs.nixpkgs.follows = "nixpkgs"; + #}; + mlir = { + url = "./mlir"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + # TODO: define nixos-unstable and nixos-hardware as dependencies here + + # outputs = inputs@{ nixpkgs, nixos-hardware, home-manager, mlir, ... }: { + outputs = inputs@{ nixpkgs, nixos-hardware, mlir, ... }: { + nixosConfigurations = { + entropy = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + nixos-hardware.nixosModules.lenovo-thinkpad-t14 + #home-manager.nixosModules.home-manager + #{ + #home-manager.useGlobalPkgs = true; + #home-manager.useUserPackages = true; + #home-manager.users.jdoe = import ./home.nix; + + ## Optionally, use home-manager.extraSpecialArgs to pass + ## arguments to home.nix + #} + (_: { + nixpkgs.overlays = [ mlir.overlay ]; + }) + ]; + }; + }; + }; +} diff --git a/entropy/nixos/mlir/flake.lock b/entropy/nixos/mlir/flake.lock new file mode 100644 index 0000000..5c83774 --- /dev/null +++ b/entropy/nixos/mlir/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1673800717, + "narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-22.11", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/entropy/nixos/mlir/flake.nix b/entropy/nixos/mlir/flake.nix new file mode 100644 index 0000000..5839c6b --- /dev/null +++ b/entropy/nixos/mlir/flake.nix @@ -0,0 +1,135 @@ +{ + description = "Custom-Built MLIR"; + + # Nixpkgs / NixOS version to use. + inputs.nixpkgs.url = "nixpkgs/nixos-22.11"; + + outputs = { self, nixpkgs }: + let + + # to work with older version of flakes + lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; + + # Generate a user-friendly version number. + version = builtins.substring 0 8 lastModifiedDate; + + # System types to support. + supportedSystems = [ "x86_64-linux" ]; #"x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + + # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + + # Nixpkgs instantiated for supported system types. + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; }); + + in + + { + + # A Nixpkgs overlay. + overlay = final: prev: { + + mlir = with final; llvmPackages_14.stdenv.mkDerivation rec { + name = "mlir-${version}"; + + #readOnlySrc = ./.; + + #src = ./.; + #src = runCommand "${name}-src-${version}" {} ('' + #mkdir -p "$out" + #cp -r ${readOnlySrc}/cmake "$out" + #cp -r ${readOnlySrc}/llvm "$out" + #cp -r ${readOnlySrc}/third-party "$out" + #''); + + src = fetchFromGitHub { + owner = "llvm"; + repo = "llvm-project"; + rev = "49caf7012170422afa84868598063818f9344228"; + sha256 = "sha256-j+ladpx8NfJGszj17oRkgvb4U2race+2DTKLtRZGeUM="; + }; + + sourceRoot = "source/llvm"; + + nativeBuildInputs = [ + python3 + ninja + cmake + ncurses + zlib + #pkg-config + llvmPackages_14.llvm + llvmPackages_14.clang + llvmPackages_14.bintools + ]; + + buildInputs = [ libxml2 ]; + + #propagatedBuildInputs = [ ncurses zlib ]; + + # where to find libgcc + #NIX_LDFLAGS="-L${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}"; # -L ${zlib}/lib"; + # teach clang about C startup file locations + #CFLAGS="-B${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version} -B ${stdenv.cc.libc}/lib"; + + #LD_LIBRARY_PATH="${zlib}/lib:${ncurses}/lib:$LD_LIBRARY_PATH"; + + cmakeFlags = [ + # "-DGCC_INSTALL_PREFIX=${gcc}" + #"-DC_INCLUDE_DIRS=${stdenv.cc.libc.dev}/include" + "-GNinja" + # Debug for debug builds + "-DCMAKE_BUILD_TYPE=Release" + # from the original LLVM expr + "-DLLVM_LINK_LLVM_DYLIB=ON" + # inst will be our installation prefix + #"-DCMAKE_INSTALL_PREFIX=../inst" + # "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON" + # change this to enable the projects you need + "-DLLVM_ENABLE_PROJECTS=mlir" + "-DLLVM_BUILD_EXAMPLES=ON" + # this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need + "-DLLVM_TARGETS_TO_BUILD=X86" +# -DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \ + "-DLLVM_ENABLE_ASSERTIONS=ON" + # Using clang and lld speeds up the build, we recomment adding: + "-DCMAKE_C_COMPILER=clang" + "-DCMAKE_CXX_COMPILER=clang++" + "-DLLVM_ENABLE_LLD=ON" + #"-DLLVM_USE_LINKER=${llvmPackages_14.bintools}/bin/lld" + # CCache can drastically speed up further rebuilds, try adding: + #"-DLLVM_CCACHE_BUILD=ON" + # libxml2 needs to be disabled because the LLVM build system ignores its .la + # file and doesn't link zlib as well. + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 + #"-DLLVM_ENABLE_LIBXML2=OFF" + ]; + }; + + }; + + # Provide some binary packages for selected system types. + packages = forAllSystems (system: + { + inherit (nixpkgsFor.${system}) mlir; + }); + + # The default package for 'nix build'. This makes sense if the + # flake provides only one package or there is a clear "main" + # package. + defaultPackage = forAllSystems (system: self.packages.${system}.mlir); + + # A NixOS module, if applicable (e.g. if the package provides a system service). + nixosModules.mlir = + { pkgs, ... }: + { + nixpkgs.overlays = [ self.overlay ]; + + environment.systemPackages = [ pkgs.mlir ]; + + #systemd.services = { ... }; + }; + + }; +} +