diff --git a/flake.lock b/flake.lock index f39c6f9..8d5f2bc 100644 --- a/flake.lock +++ b/flake.lock @@ -237,11 +237,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1715172584, - "narHash": "sha256-hB2QxcKNFILCtkRTEN3lf/ivY+KkDBRmthYFuT82iS4=", + "lastModified": 1715676857, + "narHash": "sha256-SSohpqbkPgyzLGT89hDxBD9WC88tm+eN5wGOZ6cupEc=", "owner": "helix-editor", "repo": "helix", - "rev": "f4a61006bf70340e57f10842abf47bd88c2cc1ec", + "rev": "e76020ddb93eeb051de606c24f92189c3fc55547", "type": "github" }, "original": { @@ -257,11 +257,11 @@ ] }, "locked": { - "lastModified": 1715077503, - "narHash": "sha256-AfHQshzLQfUqk/efMtdebHaQHqVntCMjhymQzVFLes0=", + "lastModified": 1715486357, + "narHash": "sha256-4pRuzsHZOW5W4CsXI9uhKtiJeQSUoe1d2M9mWU98HC4=", "owner": "nix-community", "repo": "home-manager", - "rev": "6e277d9566de9976f47228dd8c580b97488734d4", + "rev": "44677a1c96810a8e8c4ffaeaad10c842402647c1", "type": "github" }, "original": { @@ -293,11 +293,11 @@ ] }, "locked": { - "lastModified": 1714878592, - "narHash": "sha256-E68C03sYRsYFsK7wiGHUIJm8IsyPRALOrFoTL0glXnI=", + "lastModified": 1715483403, + "narHash": "sha256-WMDuQj7J5jbpXI/X/E6FZRKgBFGcaSTvYyVxPnKE6KU=", "owner": "Mic92", "repo": "nix-index-database", - "rev": "a362555e9dbd4ecff3bb98969bbdb8f79fe87f10", + "rev": "f9027322f48b427da23746aa359a6510dfcd0228", "type": "github" }, "original": { @@ -388,16 +388,14 @@ "nixos-cosmic": { "inputs": { "flake-compat": "flake-compat_4", - "nixpkgs": [ - "nixpkgs" - ] + "nixpkgs": "nixpkgs_3" }, "locked": { - "lastModified": 1715179875, - "narHash": "sha256-S8ZOu/PZwhnk825aRL6E5kVbi55Hj8+wGVzJdBhuRRs=", + "lastModified": 1715707961, + "narHash": "sha256-RW3Dq6hpupWYrArTRrIoYC61uXdsh/05UT5UWPLBnao=", "owner": "lilyinstarlight", "repo": "nixos-cosmic", - "rev": "aae0df6fd9c9e8498fca76bc3244189eddf99e34", + "rev": "953e1ae300211c0c3be925605e09e0675c45798e", "type": "github" }, "original": { @@ -489,11 +487,27 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1715087517, - "narHash": "sha256-CLU5Tsg24Ke4+7sH8azHWXKd0CFd4mhLWfhYgUiDBpQ=", + "lastModified": 1715534503, + "narHash": "sha256-5ZSVkFadZbFP1THataCaSf0JH2cAH3S29hU9rrxTEqk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b211b392b8486ee79df6cdfb1157ad2133427a29", + "rev": "2057814051972fa1453ddfb0d98badbea9b83c06", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1715534503, + "narHash": "sha256-5ZSVkFadZbFP1THataCaSf0JH2cAH3S29hU9rrxTEqk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2057814051972fa1453ddfb0d98badbea9b83c06", "type": "github" }, "original": { @@ -505,11 +519,11 @@ }, "nur": { "locked": { - "lastModified": 1715206400, - "narHash": "sha256-KxwYJL8ot3DyvIfNFeRdZCaIfvdz5QOBw+beKIAvwxk=", + "lastModified": 1715719537, + "narHash": "sha256-owPav2+iP7rOiZUzQHsKJ/bwqt7Bz5x7wTHY9ska0Bw=", "owner": "nix-community", "repo": "NUR", - "rev": "c08fcf2a2209e0dcba24555460a91aadfb89801d", + "rev": "2c670e2861a7c0e6405b3b19843a49082b773222", "type": "github" }, "original": { @@ -555,7 +569,7 @@ "nix-std": "nix-std", "nixd": "nixd", "nixos-cosmic": "nixos-cosmic", - "nixpkgs": "nixpkgs_3", + "nixpkgs": "nixpkgs_4", "nur": "nur", "rust-overlay": "rust-overlay_2" } @@ -595,11 +609,11 @@ ] }, "locked": { - "lastModified": 1715134005, - "narHash": "sha256-oujsCgNiQnZoQntNkkNkA7BhCmUvf9FLWj+2oGT2Jvc=", + "lastModified": 1715652909, + "narHash": "sha256-aCLEDvzL1j51Rf2mCFOqK1mieMO3pAn5ItCIdr5h2LA=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "a8bfc2569a1965c0da8711d289d973f0011b441a", + "rev": "1d8fcbbfcfd3476c2665384a46ee9d07ef2b4dd9", "type": "github" }, "original": { diff --git a/home/modules/theming.nix b/home/modules/theming.nix index 5e8649c..0deb27d 100644 --- a/home/modules/theming.nix +++ b/home/modules/theming.nix @@ -17,7 +17,7 @@ # inherit package name; # }; theme = { - name = "Adwaita-dark"; + name = "adw-gtk3-dark"; package = adw-gtk3; # cosmic }; iconTheme = with icons; { diff --git a/system/modules/cosmic.nix b/system/modules/cosmic.nix index 4d99d60..52439d4 100644 --- a/system/modules/cosmic.nix +++ b/system/modules/cosmic.nix @@ -1,5 +1,32 @@ {...}: { - services.desktopManager.cosmic.enable = true; + imports = [ + ../../util/cosmic.nix + ]; + services.desktopManager.cosmic = { + enable = true; + keybindings = [ + { + modifiers = ["Super"]; + key = "a"; + action = { + type = "Spawn"; + data = "echo ok!"; + }; + } + { + key = "b"; + action = { + type = "Move"; + data = "Down"; + }; + } + ]; + otherSettings = { + "com.system76.CosmicPanel.Dock" = { + option.opacity = 0.8; + }; + }; + }; services.displayManager.cosmic-greeter.enable = true; services.system76-scheduler.enable = true; } diff --git a/util/cosmic.nix b/util/cosmic.nix new file mode 100644 index 0000000..1f8a060 --- /dev/null +++ b/util/cosmic.nix @@ -0,0 +1,186 @@ +{ + lib, + config, + ... +}: +# possible actions: +# ----------------- +# Terminate, +# Debug, +# Close, +# Escape, +# Workspace(u8), +# NextWorkspace, +# PreviousWorkspace, +# LastWorkspace, +# MoveToWorkspace(u8), +# MoveToNextWorkspace, +# MoveToPreviousWorkspace, +# MoveToLastWorkspace, +# SendToWorkspace(u8), +# SendToNextWorkspace, +# SendToPreviousWorkspace, +# SendToLastWorkspace, +# NextOutput, +# PreviousOutput, +# MoveToNextOutput, +# MoveToPreviousOutput, +# SendToNextOutput, +# SendToPreviousOutput, +# SwitchOutput(Direction), +# MoveToOutput(Direction), +# SendToOutput(Direction), +# MigrateWorkspaceToNextOutput, +# MigrateWorkspaceToPreviousOutput, +# MigrateWorkspaceToOutput(Direction), +# Focus(FocusDirection), +# Move(Direction), +# ToggleOrientation, +# Orientation(crate::shell::layout::Orientation), +# ToggleStacking, +# ToggleTiling, +# ToggleWindowFloating, +# ToggleSticky, +# SwapWindow, +# Resizing(ResizeDirection), +# Minimize, +# Maximize, +# Spawn(String), +let + inherit (lib) concatStrings concatStringsSep mapAttrsToList concatLists foldlAttrs concatMapAttrs mapAttrs' nameValuePair boolToString; + inherit (builtins) typeOf toString stringLength; + + # build up serialisation machinery from here for various types + + # list -> array + array = a: "[${concatStringsSep "," a}]"; + # attrset -> hashmap + _assoc = a: mapAttrsToList (name: val: "${name}: ${val}") a; + assoc = a: '' { + ${concatStringsSep ",\n" (concatLists (map _assoc a))} + }''; + # attrset -> struct + __struct = k: v: (concatStringsSep "=" [k (serialise.${typeOf v} v)]); + _struct = s: + foldlAttrs ( + acc: k: v: + if stringLength acc > 0 + then concatStringsSep ", " [acc (__struct k v)] + else __struct k v + ) "" + s; + struct = s: "(${_struct s})"; + toQuotedString = s: ''"${toString s}"''; + + # make an attrset for struct serialisation + serialise = { + int = toString; + float = toString; + bool = boolToString; + string = toString; + path = toString; + null = toString; + set = struct; + list = array; + }; + + # define the key for a keybind + defineBinding = binding: + struct { + inherit (binding) modifiers; + key = toQuotedString binding.key; + }; + + # map keybinding from list of attrset to hashmap of (mod,key): action + _mapBindings = bindings: + map ( + inner: {"${defineBinding inner}" = maybeToString (checkAction inner.action);} + ) + bindings; + mapBindings = bindings: + assoc (_mapBindings bindings); + + # check a keybinding's action + # escape with quotes if it's a Spawn action + checkAction = a: + if typeOf a == "set" && a.type == "Spawn" + then { + inherit (a) type; + data = toQuotedString a.data; + } + else a; + + maybeToString = s: + if typeOf s == "set" + then concatStrings [s.type "(" s.data ")"] + else s; + + # set up boilerplate for keybinding config file + cosmic-bindings = a: + struct { + key_bindings = mapBindings a; + data_control_enabled = false; + }; +in { + options.services.desktopManager.cosmic.keybindings = with lib; + mkOption { + default = []; + type = with types; + listOf (submodule { + options = { + modifiers = mkOption { + type = listOf str; + default = []; + }; + key = mkOption { + type = str; + }; + action = mkOption { + type = either str (submodule { + options = { + type = mkOption { + type = str; + }; + data = mkOption { + type = oneOf [str int]; + default = ""; + }; + }; + }); + }; + }; + }); + }; + + options.services.desktopManager.cosmic.otherSettings = with lib; + mkOption { + default = {}; + type = with types; + attrsOf (submodule { + options = { + version = mkOption { + type = str; + default = "1"; + }; + option = mkOption { + type = attrsOf anything; + }; + }; + }); + }; + + config.environment.etc = + { + "cosmic-comp/config-test.ron".text = cosmic-bindings config.services.desktopManager.cosmic.keybindings; + } + // concatMapAttrs ( + application: options: + mapAttrs' (k: v: + nameValuePair "xdg/cosmic-test/${application}/v${options.version}/${k}" { + enable = true; + text = serialise.${typeOf v} v; + }) + options.option + ) + config.services.desktopManager.cosmic.otherSettings; +}