From d84ed13e0f0910820eb3806343e1bd5044bbece4 Mon Sep 17 00:00:00 2001 From: Artur Manuel Date: Sat, 18 Jan 2025 12:34:41 +0000 Subject: [PATCH] refactor(flake): wrap xonsh as a package --- flake.lock | 122 ++++++++++++++++++++++--- flake.nix | 53 +++-------- hosts/python/apps.nix | 5 +- hosts/python/users/default.nix | 1 + hosts/shared/users.nix | 3 +- hosts/shared/xonsh.nix | 81 ++-------------- lib/default.nix | 8 +- overlays/default.nix | 1 + overlays/derivations/xonsh/cfg/rc.xsh | 1 + overlays/derivations/xonsh/default.nix | 98 ++++++++++++++++++++ shells/default.nix | 49 ++++++++++ 11 files changed, 287 insertions(+), 135 deletions(-) create mode 100644 overlays/derivations/xonsh/cfg/rc.xsh create mode 100644 overlays/derivations/xonsh/default.nix create mode 100644 shells/default.nix diff --git a/flake.lock b/flake.lock index 007a6c0..daef235 100644 --- a/flake.lock +++ b/flake.lock @@ -2,17 +2,18 @@ "nodes": { "chaotic": { "inputs": { + "fenix": "fenix", "flake-schemas": "flake-schemas", "home-manager": "home-manager", "jovian": "jovian", "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1736848948, - "narHash": "sha256-P9XZoUzRxjq5AJxR1+F0HEyzggNX/zt+A3cuwXER4qM=", + "lastModified": 1736971453, + "narHash": "sha256-X3f+KFNg+xJcvz3LbV8Sncwnk9AfjzliY5vpw7IpX5c=", "owner": "chaotic-cx", "repo": "nyx", - "rev": "e75f332c423ae95164ec188c0406c2d47b8a4a65", + "rev": "368f97d223fc5b5278b520e456a53551d7ac5318", "type": "github" }, "original": { @@ -27,11 +28,11 @@ "nixpkgs": ["nixpkgs"] }, "locked": { - "lastModified": 1736711425, - "narHash": "sha256-8hKhPQuMtXfJi+4lPvw3FBk/zSJVHeb726Zo0uF1PP8=", + "lastModified": 1737038063, + "narHash": "sha256-rMEuiK69MDhjz1JgbaeQ9mBDXMJ2/P8vmOYRbFndXsk=", "owner": "nix-community", "repo": "disko", - "rev": "f720e64ec37fa16ebba6354eadf310f81555cc07", + "rev": "bf0abfde48f469c256f2b0f481c6281ff04a5db2", "type": "github" }, "original": { @@ -59,6 +60,25 @@ "type": "github" } }, + "fenix": { + "inputs": { + "nixpkgs": ["chaotic", "nixpkgs"], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1736836313, + "narHash": "sha256-zdZ7/T6yG0/hzoVOiNpDiR/sW3zR6oSMrfIFJK2BrrE=", + "owner": "nix-community", + "repo": "fenix", + "rev": "056c9393c821a4df356df6ce7f14c722dc8717ec", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -150,11 +170,11 @@ "nixpkgs": ["nixpkgs"] }, "locked": { - "lastModified": 1735882644, - "narHash": "sha256-3FZAG+pGt3OElQjesCAWeMkQ7C/nB1oTHLRQ8ceP110=", + "lastModified": 1737043064, + "narHash": "sha256-I/OuxGwXwRi5gnFPsyCvVR+IfFstA+QXEpHu1hvsgD8=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "a5a961387e75ae44cc20f0a57ae463da5e959656", + "rev": "94ee657f6032d913fe0ef49adaa743804635b0bb", "type": "github" }, "original": { @@ -181,6 +201,26 @@ "type": "github" } }, + "hetch": { + "inputs": { + "nixpkgs": ["nixpkgs"], + "treefmt": "treefmt" + }, + "locked": { + "lastModified": 1737045336, + "narHash": "sha256-0LiXE5Z7V3gKt2BfZokhnK5GOoCIkLpFoONEucFASv8=", + "ref": "master", + "rev": "7b8af02bcc2d4d56ac09b2de2179de7453925d48", + "revCount": 4, + "type": "git", + "url": "https://codeberg.org/amadaluzia/hetch.git" + }, + "original": { + "ref": "master", + "type": "git", + "url": "https://codeberg.org/amadaluzia/hetch.git" + } + }, "home-manager": { "inputs": { "nixpkgs": ["chaotic", "nixpkgs"] @@ -318,11 +358,27 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1736798957, - "narHash": "sha256-qwpCtZhSsSNQtK4xYGzMiyEDhkNzOCz/Vfu4oL2ETsQ=", + "lastModified": 1731890469, + "narHash": "sha256-D1FNZ70NmQEwNxpSSdTXCSklBH1z2isPR84J6DQrJGs=", "owner": "nixos", "repo": "nixpkgs", - "rev": "9abb87b552b7f55ac8916b6fc9e5cb486656a2f3", + "rev": "5083ec887760adfe12af64830a66807423a859a7", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1736883708, + "narHash": "sha256-uQ+NQ0/xYU0N1CnXsa2zghgNaOPxWpMJXSUJJ9W7140=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "eb62e6aa39ea67e0b8018ba8ea077efe65807dc8", "type": "github" }, "original": { @@ -332,7 +388,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_4": { "locked": { "lastModified": 1735523292, "narHash": "sha256-opBsbR/nrGxiiF6XzlVluiHYb6yN/hEwv+lBWTy9xoM=", @@ -370,7 +426,7 @@ "flake-utils": "flake-utils", "mnw": "mnw", "nil": "nil", - "nixpkgs": "nixpkgs_3", + "nixpkgs": "nixpkgs_4", "nmd": "nmd", "plugin-aerial-nvim": "plugin-aerial-nvim", "plugin-alpha-nvim": "plugin-alpha-nvim", @@ -2529,7 +2585,8 @@ "disko": "disko", "flake-parts": "flake-parts", "git-hooks-nix": "git-hooks-nix", - "nixpkgs": "nixpkgs_2", + "hetch": "hetch", + "nixpkgs": "nixpkgs_3", "painless-neovim": "painless-neovim", "pankomacs": "pankomacs", "rosepine-qutebrowser": "rosepine-qutebrowser", @@ -2552,6 +2609,23 @@ "type": "github" } }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1736690231, + "narHash": "sha256-g9gyxX+F6CrkT5gRIMKPnCPom0o9ZDzYnzzeNF86D6Q=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "8364ef299790cb6ec22b9e09e873c97dbe9f2cb5", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, "rust-overlay": { "inputs": { "nixpkgs": ["painless-neovim", "nvf", "nil", "nixpkgs"] @@ -2615,6 +2689,24 @@ "type": "github" } }, + "treefmt": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1733222881, + "narHash": "sha256-JIPcz1PrpXUCbaccEnrcUS8jjEb/1vJbZz5KkobyFdM=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "49717b5af6f80172275d47a418c9719a31a78b53", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, "wallpkgs": { "inputs": { "nixpkgs": ["nixpkgs"], diff --git a/flake.nix b/flake.nix index 3568427..17dd18c 100644 --- a/flake.nix +++ b/flake.nix @@ -55,13 +55,22 @@ ref = "master"; inputs.nixpkgs.follows = "nixpkgs"; }; + hetch = { + type = "git"; + url = "https://codeberg.org/amadaluzia/hetch.git"; + ref = "master"; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; }; outputs = inputs @ { + self, nixpkgs, flake-parts, ... }: let - lib = nixpkgs.lib.extend (import ./lib {inherit inputs;}); + lib = nixpkgs.lib.extend (import ./lib {inherit inputs self;}); in flake-parts.lib.mkFlake { inherit inputs; @@ -71,48 +80,8 @@ imports = [ ./hosts ./overlays - inputs.git-hooks-nix.flakeModule + ./shells ]; flake = {inherit lib;}; - perSystem = { - config, - pkgs, - ... - }: { - pre-commit = { - check.enable = true; - settings.hooks = { - alejandra.enable = true; - nil.enable = true; - shellcheck.enable = true; - prettier.enable = true; - ruff.enable = true; - ruff-format.enable = true; - shfmt.enable = true; - deadnix = { - enable = true; - args = ["-e"]; - }; - statix = { - enable = true; - args = ["fix"]; - }; - }; - }; - devShells.default = config.pre-commit.devShell; - devShells.haskell = pkgs.mkShell { - name = "haskell"; - packages = builtins.attrValues { - inherit (pkgs) ghc; - inherit - (pkgs.haskellPackages) - cabal-install - haskell-language-server - ormolu - ; - }; - }; - formatter = pkgs.alejandra; - }; }; } diff --git a/hosts/python/apps.nix b/hosts/python/apps.nix index e7295f4..e22db47 100644 --- a/hosts/python/apps.nix +++ b/hosts/python/apps.nix @@ -18,7 +18,10 @@ }; alqueva = { - xonsh.enable = true; + xonsh = { + enable = true; + package = pkgs.amadaluzian-xonsh; + }; libvirt.enable = true; direnv.enable = true; git.enable = true; diff --git a/hosts/python/users/default.nix b/hosts/python/users/default.nix index 99c8dfa..60dbca7 100644 --- a/hosts/python/users/default.nix +++ b/hosts/python/users/default.nix @@ -38,6 +38,7 @@ qutebrowser dunst ; + inherit (inputs.hetch.packages.${pkgs.system}) hetch; }; groups = [ "wheel" diff --git a/hosts/shared/users.nix b/hosts/shared/users.nix index fab24fb..cbf8c9c 100644 --- a/hosts/shared/users.nix +++ b/hosts/shared/users.nix @@ -42,8 +42,7 @@ in { description = user; isNormalUser = true; extraGroups = ucfg.groups; - inherit (ucfg) packages; - shell = ucfg.shell; + inherit (ucfg) packages shell; initialPassword = "password"; }) cfg; diff --git a/hosts/shared/xonsh.nix b/hosts/shared/xonsh.nix index d4f5512..0c82424 100644 --- a/hosts/shared/xonsh.nix +++ b/hosts/shared/xonsh.nix @@ -5,10 +5,16 @@ ... }: let cfg = config.alqueva.xonsh; - inherit (pkgs) fetchFromGitHub; + attrsToPyDict = attrs: (lib.pipe attrs [ + (builtins.mapAttrs (n: v: "aliases['${n}'] = '${v}'")) + builtins.attrValues + (lib.concatStringsSep "\n") + (s: s + "\n") + ]); in { options.alqueva.xonsh = { enable = lib.mkEnableOption "xonsh"; + package = lib.mkPackageOption pkgs "xonsh" {}; }; config = lib.mkIf cfg.enable { @@ -16,83 +22,14 @@ in { xonsh = { config = "from xonsh.xontribs import get_xontribs\n" - + lib.concatStringsSep "\n" (builtins.attrValues (builtins.mapAttrs (n: v: "aliases['${n}'] = '${v}'\n") config.environment.shellAliases)) + + attrsToPyDict config.environment.shellAliases + '' for xontrib in get_xontribs(): xontrib load @(xontrib) - - execx($(zoxide init xonsh --cmd j), 'exec', __xonsh__.ctx, filename='zoxide') ''; - package = pkgs.xonsh.override { - extraPackages = ps: [ - (let - pname = "xontrib-fish-completer"; - version = "0.0.1"; - in - ps.buildPythonPackage { - inherit pname version; - src = fetchFromGitHub { - owner = "xonsh"; - repo = pname; - rev = version; - hash = "sha256-PhhdZ3iLPDEIG9uDeR5ctJ9zz2+YORHBhbsiLrJckyA="; - }; - }) - (let - pname = "xontrib-prompt-starship"; - version = "0.3.6"; - in - ps.buildPythonPackage { - inherit pname version; - src = fetchFromGitHub { - owner = "anki-code"; - repo = pname; - tag = version; - hash = "sha256-CLOvMa3L4XnH53H/k6/1W9URrPakPjbX1T1U43+eSR0="; - }; - }) - (let - pname = "xontrib-init-ssh-agent"; - version = "1.0.1"; - in - ps.buildPythonPackage { - inherit pname version; - pyproject = true; - build-system = [ - ps.setuptools - ps.wheel - ]; - dependencies = [ - ps.xonsh - ]; - src = fetchFromGitHub { - owner = "amadaluzia"; - repo = pname; - rev = "cac9cfec70ec15b0ed4f1c8a18154ea9b4f8fb47"; - hash = "sha256-UkRPdaZFNP8qv7lMwsTUalnre3k2UMfqMzmiTveLiBM="; - }; - }) - (let - pname = "xonsh-direnv"; - version = "1.6.5"; - in - ps.buildPythonPackage { - inherit pname version; - src = fetchFromGitHub { - owner = "74th"; - repo = pname; - tag = version; - hash = "sha256-huBJ7WknVCk+WgZaXHlL+Y1sqsn6TYqMP29/fsUPSyU="; - }; - }) - ]; - }; + inherit (cfg) package; enable = true; }; }; - environment.systemPackages = [ - pkgs.zoxide - pkgs.amadaluzian-starship - ]; }; } diff --git a/lib/default.nix b/lib/default.nix index dc52b9e..27206b0 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,4 +1,7 @@ -{inputs}: _: _: let +{ + inputs, + self, +}: _: _: let mkHost = { host, system, @@ -36,8 +39,7 @@ }) ]; specialArgs = { - inherit inputs; - inherit (inputs) self; + inherit inputs self; }; }; in { diff --git a/overlays/default.nix b/overlays/default.nix index 2652701..14ef179 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -21,6 +21,7 @@ }; }); amadaluzian-starship = prev.callPackage ./derivations/starship.nix {}; + amadaluzian-xonsh = prev.callPackage ./derivations/xonsh {}; }; perSystem = {pkgs, ...}: { packages = self.overlays.default null pkgs; diff --git a/overlays/derivations/xonsh/cfg/rc.xsh b/overlays/derivations/xonsh/cfg/rc.xsh new file mode 100644 index 0000000..d585899 --- /dev/null +++ b/overlays/derivations/xonsh/cfg/rc.xsh @@ -0,0 +1 @@ +execx($(zoxide init xonsh --cmd j), 'exec', __xonsh__.ctx, filename='zoxide') diff --git a/overlays/derivations/xonsh/default.nix b/overlays/derivations/xonsh/default.nix new file mode 100644 index 0000000..4e234a5 --- /dev/null +++ b/overlays/derivations/xonsh/default.nix @@ -0,0 +1,98 @@ +{ + makeWrapper, + fetchFromGitHub, + symlinkJoin, + python3, + amadaluzian-starship, + zoxide, +}: let + xonsh = python3.withPackages (ps: [ + ps.xonsh + (let + pname = "xontrib-fish-completer"; + version = "0.0.1"; + in + ps.buildPythonPackage { + inherit pname version; + src = fetchFromGitHub { + owner = "xonsh"; + repo = pname; + rev = version; + hash = "sha256-PhhdZ3iLPDEIG9uDeR5ctJ9zz2+YORHBhbsiLrJckyA="; + }; + }) + (let + pname = "xontrib-prompt-starship"; + version = "0.3.6"; + in + ps.buildPythonPackage { + inherit pname version; + src = fetchFromGitHub { + owner = "anki-code"; + repo = pname; + tag = version; + hash = "sha256-CLOvMa3L4XnH53H/k6/1W9URrPakPjbX1T1U43+eSR0="; + }; + }) + (let + pname = "xontrib-init-ssh-agent"; + version = "1.0.1"; + in + ps.buildPythonPackage { + inherit pname version; + pyproject = true; + build-system = [ + ps.setuptools + ps.wheel + ]; + dependencies = [ + ps.xonsh + ]; + src = fetchFromGitHub { + owner = "amadaluzia"; + repo = pname; + rev = "cac9cfec70ec15b0ed4f1c8a18154ea9b4f8fb47"; + hash = "sha256-UkRPdaZFNP8qv7lMwsTUalnre3k2UMfqMzmiTveLiBM="; + }; + }) + (let + pname = "xonsh-direnv"; + version = "1.6.5"; + in + ps.buildPythonPackage { + inherit pname version; + src = fetchFromGitHub { + owner = "74th"; + repo = pname; + tag = version; + hash = "sha256-huBJ7WknVCk+WgZaXHlL+Y1sqsn6TYqMP29/fsUPSyU="; + }; + }) + ]); +in + symlinkJoin { + name = "xonsh"; + + paths = [ + xonsh + amadaluzian-starship + zoxide + ]; + + nativeBuildInputs = [ + makeWrapper + ]; + + postBuild = '' + wrapProgram $out/bin/xonsh \ + --set XONSH_CONFIG_DIR ${./cfg} + ''; + + passthru = { + shellPath = "/bin/xonsh"; + }; + + meta = { + mainProgram = "xonsh"; + }; + } diff --git a/shells/default.nix b/shells/default.nix new file mode 100644 index 0000000..bfb8df1 --- /dev/null +++ b/shells/default.nix @@ -0,0 +1,49 @@ +{inputs, ...}: { + imports = [ + inputs.git-hooks-nix.flakeModule + ]; + + perSystem = { + config, + pkgs, + ... + }: { + pre-commit = { + check.enable = true; + settings.hooks = { + alejandra.enable = true; + nil.enable = true; + shellcheck.enable = true; + prettier.enable = true; + ruff.enable = true; + ruff-format.enable = true; + shfmt.enable = true; + deadnix = { + enable = true; + args = ["-e"]; + }; + statix = { + enable = true; + args = ["fix"]; + }; + }; + }; + + devShells = { + default = config.pre-commit.devShell; + haskell = pkgs.mkShell { + name = "haskell"; + packages = builtins.attrValues { + inherit (pkgs) ghc; + inherit + (pkgs.haskellPackages) + stack + haskell-language-server + ormolu + ; + }; + }; + }; + formatter = pkgs.alejandra; + }; +}