From e51e50e74bfad1c91ed4fc492f374efffe29b94f Mon Sep 17 00:00:00 2001 From: Ruixi-rebirth Date: Mon, 13 Feb 2023 12:27:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20nix=20flake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + README.md | 32 ++++++++++++++++++++++++++-- flake.lock | 7 ++++--- flake.nix | 61 +++++++++++++++++++++++++++++++++++------------------- 4 files changed, 75 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 8a469ced..47657606 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ config.h autostart.sh statusbar/ +result dwm *.o .ccls-cache/ diff --git a/README.md b/README.md index 65a31dbc..8f73d6ea 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,36 @@ exec dwm ### Nix Flake -```sh -nix run github:yaocccc/dwm +下面是在 nixos configuration 中使用它的示例 + +```nix +{ + description = "My configuration"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + dwm.url = "github:yaocccc/dwm"; + }; + + outputs = { nixpkgs, dwm, ... }: + { + nixosConfigurations = { + hostname = nixpkgs.lib.nixosSystem + { + system = "x86_64-linux"; + modules = [ + { + nixpkgs.overlays = [ dwm.overlays.default ]; + services.xserver = { + enable = true; + windowManager.dwm.enable = true; + }; + } + ]; + }; + }; + }; +} ``` ## 状态栏 diff --git a/flake.lock b/flake.lock index c3fbdbd5..c8565b39 100644 --- a/flake.lock +++ b/flake.lock @@ -17,15 +17,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1669387357, - "narHash": "sha256-z1azVj/5Em5kGhh9OgBOsjTEgMab7hXL/aRilH9tzyI=", + "lastModified": 1675763311, + "narHash": "sha256-bz0Q2H3mxsF1CUfk26Sl9Uzi8/HFjGFD/moZHz1HebU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "55b3f68bda6d4f4dc6092eed0508063f154fa4fd", + "rev": "fab09085df1b60d6a0870c8a89ce26d5a4a708c2", "type": "github" }, "original": { "id": "nixpkgs", + "ref": "nixos-unstable", "type": "indirect" } }, diff --git a/flake.nix b/flake.nix index 21d99cdd..0af3e3c8 100644 --- a/flake.nix +++ b/flake.nix @@ -1,27 +1,46 @@ { description = "A very basic flake"; + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; - inputs.flake-utils.url = "github:numtide/flake-utils"; - - outputs = { - self, - nixpkgs, - flake-utils, - }: - flake-utils.lib.eachDefaultSystem ( - system: let - pkgs = nixpkgs.legacyPackages.${system}; - in rec { - packages = flake-utils.lib.flattenTree { - dwm = pkgs.dwm.overrideAttrs (old: { - src = pkgs.lib.cleanSource self; + outputs = + { self + , nixpkgs + , flake-utils + , + }: + let + overlay = + final: prev: { + dwm = prev.dwm.overrideAttrs (oldAttrs: rec { + postPatch = (oldAttrs.postPatch or "") + '' + cp -r DEF/* . + ''; + version = "master"; + src = ./.; }); }; - defaultPackage = packages.dwm; - apps.default = flake-utils.lib.mkApp { - drv = packages.dwm; - exePath = "/bin/dwm"; - }; - } - ); + in + flake-utils.lib.eachDefaultSystem + ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ + self.overlays.default + ]; + }; + in + rec { + packages.dwm = pkgs.dwm; + packages.default = pkgs.dwm; + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ xorg.libX11 xorg.libXft xorg.libXinerama gcc ]; + }; + } + ) + // { overlays.default = overlay; }; }