From c747a18f219b3dd3d556b4e4222f613b0fd27f6f Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 22 Dec 2023 11:12:51 +0100 Subject: [PATCH] Create flake.nix --- flake.lock | 46 ++++++++++++++++++++++++ flake.nix | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7c560f5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,46 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1703013332, + "narHash": "sha256-+tFNwMvlXLbJZXiMHqYq77z/RfmpfpiI3yjL6o/Zo9M=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "54aac082a4d9bb5bbc5c4e899603abfb76a3f6d6", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "wlroots-src": "wlroots-src" + } + }, + "wlroots-src": { + "flake": false, + "locked": { + "host": "gitlab.freedesktop.org", + "lastModified": 1700582773, + "narHash": "sha256-VUrnSG4UAAH0cBy15lG0w8RernwegD6lkOdLvWU3a4c=", + "owner": "wlroots", + "repo": "wlroots", + "rev": "767eedd3cbe9900687bf3b82236320dcd7b77aae", + "type": "gitlab" + }, + "original": { + "host": "gitlab.freedesktop.org", + "owner": "wlroots", + "ref": "refs/tags/0.17.0", + "repo": "wlroots", + "type": "gitlab" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..fa84a9f --- /dev/null +++ b/flake.nix @@ -0,0 +1,100 @@ +{ + description = "A hackable wayland compositor based on views"; + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + + wlroots-src = { + type = "gitlab"; + host = "gitlab.freedesktop.org"; + owner = "wlroots"; + repo = "wlroots"; + ref = "refs/tags/0.17.0"; + flake = false; + }; + }; + + outputs = { + self, + nixpkgs, + wlroots-src, + }: let + version = self.shortRev or "dirty"; + supportedSystems = ["x86_64-linux"]; + + # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. + forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); + # Nixpkgs instantiated for supported system types. + nixpkgsFor = forAllSystems (system: + import nixpkgs { + inherit system; + overlays = [self.overlay]; + }); + in { + overlay = final: prev: + with final; rec { + wlroots = prev.wlroots.overrideAttrs (old: { + version = wlroots-src.shortRev or "dirty"; + src = wlroots-src; + buildInputs = + old.buildInputs + ++ [ + hwdata + libliftoff + libdisplay-info + ]; + }); + + gaze = with final; + final.callPackage ({inShell ? false}: + stdenv.mkDerivation rec { + name = "gaze-${version}"; + + # In 'nix develop', we don't need a copy of the source tree in the Nix store. + src = + if inShell + then null + else ./.; + + buildInputs = + [ + zig + wlroots + ] + ++ ( + if inShell + then [ + # TODO: In 'nix develop', provide some developer tools. + ] + else [] + ); + + target = "-Dcpu=baseline -Doptimize=ReleaseSafe"; + + buildPhase = "zig build ${target}"; + + doCheck = true; + + checkPhase = "zig build test ${target}"; + + installPhase = '' + mkdir -p $out + # TODO: implement this :) + ''; + }) {}; + }; + + packages = forAllSystems (system: { + inherit (nixpkgsFor.${system}) gaze; + }); + defaultPackage = forAllSystems (system: self.packages.${system}.gaze); + + devShell = forAllSystems (system: self.packages.${system}.gaze.override {inShell = true;}); + + nixosModules.gaze = {pkgs, ...}: { + nixpkgs.overlays = [self.overlay]; + + passthru.providedSessions = ["gaze"]; + # TODO: this + }; + }; +}