6 Commits

10 changed files with 256 additions and 166 deletions

View File

@@ -1,2 +1,2 @@
[codespell] [codespell]
skip = ./assets/pkg/aur/*/src,./assets/pkg/aur/*/*/objects skip = ./assets/pkg/aur/*/src,./assets/pkg/aur/*/*/objects,./assets/pkg/aur/*/*.tar.*

View File

@@ -23,26 +23,13 @@ jobs:
id: check-ver-changed id: check-ver-changed
run: | run: |
GIT_TAG=$(git describe --no-long --abbrev=0 --tags --always) GIT_TAG=$(git describe --no-long --abbrev=0 --tags --always)
MAKE_TAG=$(make print-version) MAKE_TAG=$(make print-version)
NIX_VER=$(sed -nE \
's/.*version\s*=\s*"([0-9.]*)".*/\1/p' \
assets/pkg/nix/module.nix
)
if [[ "$GIT_TAG" == "v$MAKE_TAG" ]]; then if [[ "$GIT_TAG" == "v$MAKE_TAG" ]]; then
echo "ERR: Git tag matches makefile, did you bump Makefile up?" >&2 echo "ERR: Git tag matches makefile, did you bump Makefile up?" >&2
exit 1 exit 1
fi fi
if [[ "$GIT_TAG" == "v$NIX_VER" ]]; then
echo "ERR: Nix module version matches git, did you bump Nix up?" >&2
exit 1
fi
if ! [[ "$NIX_VER" == "$MAKE_TAG" ]]; then
echo "ERR: Nix module version and make tag don't match" >&2
exit 1
fi
echo "VERSION=$MAKE_TAG" >> "$GITHUB_OUTPUT" echo "VERSION=$MAKE_TAG" >> "$GITHUB_OUTPUT"
@@ -86,7 +73,6 @@ jobs:
needs: [ release-checks, release ] needs: [ release-checks, release ]
steps: steps:
- run: pacman -Sy --noconfirm git github-cli base-devel pacman-contrib - run: pacman -Sy --noconfirm git github-cli base-devel pacman-contrib
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- run: | - run: |
@@ -112,3 +98,37 @@ jobs:
--body "*This PR was created automatically*" --body "*This PR was created automatically*"
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
nix-update:
name: Update NixOS module
runs-on: ubuntu-24.04
permissions: write-all
needs: [ release-checks, release ]
steps:
- uses: cachix/install-nix-action@v31
- uses: actions/checkout@v4
with:
fetch-tags: true
- run: |
tmpdir=$(mktemp -d)
git archive v${{ needs.release-checks.outputs.VERSION }} | tar -xC "$tmpdir"
sha256sum=$(nix hash path "$tmpdir")
sed -i -E 's/(.*version\s*=\s*")[0-9.]*(".*)/\1'${{ needs.release-checks.outputs.VERSION }}'\2/' assets/pkg/nix/module.nix
sed -i -E 's/(.*sha256\s*=\s*")[^"]*(".*)/\1'"$sha256sum"'\2/' assets/pkg/nix/module.nix
# would be cool to be able to check the new module.nix builds
- run: |
BRANCH=actions/update-nix-${{ needs.release-checks.outputs.VERSION }}
git config --global --add safe.directory $GITHUB_WORKSPACE
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git checkout -b $BRANCH
git commit -am "Update NixOS module to v${{ needs.release-checks.outputs.VERSION }}"
git push -u origin $BRANCH
gh pr create --head $BRANCH \
--title "[Nix update]: Bump to ${{ needs.release-checks.outputs.VERSION }}" \
--body "*This PR was created automatically*"
env:
GH_TOKEN: ${{ github.token }}

View File

@@ -12,7 +12,24 @@ jobs:
name: Check name: Check
uses: ./.github/workflows/check.yml uses: ./.github/workflows/check.yml
permissions: write-all permissions: write-all
check_paths:
name: Paths Filter
runs-on: ubuntu-latest
outputs:
code_changed: ${{ steps.filter.outputs.code }}
steps:
- uses: actions/checkout@v4
- id: filter
uses: dorny/paths-filter@v3
with:
filters: |
code:
- Makefile
- 'src/**'
- 'include/**'
build: build:
name: Build name: Build
needs: check_paths
if: github.event_name != 'push' || needs.check_paths.outputs.code_changed == 'true'
uses: ./.github/workflows/build.yml uses: ./.github/workflows/build.yml
permissions: write-all permissions: write-all

View File

@@ -102,21 +102,24 @@ pass:
* A string to copy the config from a theme in `themes/` with said name * A string to copy the config from a theme in `themes/` with said name
(**name**, e.g `"cherry"`). (**name**, e.g `"cherry"`).
* An attribute tree with the same names as the config file, e.g: * An attribute tree with the same names as the config file, e.g:
```nix ```nix
{ with config.lidm.keysEnum; {
strings = { strings = {
f_poweroff = "custom_poweroff"; f_poweroff = "custom_poweroff";
# etc
}; };
behavior = { behavior = {
include_defshell = true; include_defshell = true;
source = [ source = [
"path1" "path1"
"path2" "path2"
]; ];
# etc
}; };
# etc
functions = { poweroff = F1; };
# etc...
}; };
``` ```

View File

@@ -1,13 +1,23 @@
{ cfg, src, lib, ... }: {
cfg,
src,
lib,
...
}:
let let
maker = import ./make-cfg.nix { maker = import ./make-cfg.nix {
inherit lib; inherit lib;
keys-h-file = builtins.readFile "${src}/include/keys.h"; keys-h-file = builtins.readFile "${src}/include/keys.h";
}; };
in builtins.toFile "lidm.conf" ( in
if builtins.isString cfg {
then builtins.readFile "${src}/themes/${cfg}.ini" inherit maker;
else if builtins.isAttrs cfg file = builtins.toFile "lidm.conf" (
then maker.make cfg if builtins.isString cfg then
else builtins.throw "invalid cfg type, expected str or attrs" builtins.readFile "${src}/themes/${cfg}.ini"
) else if builtins.isAttrs cfg then
maker.make cfg
else
builtins.throw "invalid cfg type, expected str or attrs"
);
}

View File

@@ -1,11 +1,20 @@
{ config, pkgs, lib, ...}: {
config,
pkgs,
lib,
...
}:
let let
cfg-file = if config.cfg != null then get-cfg =
if config.cfg != null then
import ./get-cfg-file.nix { import ./get-cfg-file.nix {
inherit lib; inherit lib;
inherit (config) cfg src; inherit (config) cfg src;
} }
else null; else
null;
cfg-file = get-cfg.file;
maker = get-cfg.maker;
in in
pkgs.stdenv.mkDerivation rec { pkgs.stdenv.mkDerivation rec {
pname = "lidm"; pname = "lidm";
@@ -18,18 +27,24 @@ pkgs.stdenv.mkDerivation rec {
linux-pam linux-pam
]; ];
makeFlags = [ makeFlags =
[
"DESTDIR=$(out)" "DESTDIR=$(out)"
"PREFIX=" "PREFIX="
] ]
++ lib.optional (config.xsessions != null) ++ lib.optional (
"CPPFLAGS+=-DSESSIONS_XSESSIONS=\\\"${config.xsessions}\\\"" config.xsessions != null
++ lib.optional (config.wayland-sessions != null) ) "CPPFLAGS+=-DSESSIONS_XSESSIONS=\\\"${config.xsessions}\\\""
"CPPFLAGS+=-DSESSIONS_WAYLAND=\\\"${config.wayland-sessions}\\\"" ++ lib.optional (
++ lib.optional (cfg-file != null) config.wayland-sessions != null
"CPPFLAGS+=-DLIDM_CONF_PATH=\\\"${cfg-file}\\\""; ) "CPPFLAGS+=-DSESSIONS_WAYLAND=\\\"${config.wayland-sessions}\\\""
++ lib.optional (cfg-file != null) "CPPFLAGS+=-DLIDM_CONF_PATH=\\\"${cfg-file}\\\"";
fixupPhase = '' fixupPhase = ''
rm -rf $out/etc rm -rf $out/etc
''; '';
passthru = {
keysEnum = maker.keys-enum;
};
} }

View File

@@ -1,53 +1,54 @@
{ lib, keys-h-file }: { lib, keys-h-file }:
let let
double-match-to-nameval = dmatch: { name = builtins.elemAt dmatch 0; value = builtins.elemAt dmatch 1; }; double-match-to-nameval = dmatch: {
name = builtins.elemAt dmatch 0;
value = builtins.elemAt dmatch 1;
};
keys-enum = let keys-enum =
key-names = builtins.replaceStrings ["\n" " "] ["" ""] ( let
builtins.elemAt ( key-names = builtins.replaceStrings [ "\n" " " ] [ "" "" ] (
builtins.match builtins.elemAt (builtins.match ".*KEY_NAMES\\[][[:blank:]]*=[[:blank:]]*\\{([^}]*)}.*" keys-h-file) 0
".*KEY_NAMES\\[][[:blank:]]*=[[:blank:]]*\\{([^}]*)}.*"
keys-h-file
) 0
); );
keys-2d-list = builtins.map keys-2d-list = builtins.map (builtins.match "\\[(.*)]=\"(.*)\"") (
(builtins.match "\\[(.*)]=\"(.*)\"") builtins.filter (s: builtins.isString s && s != "") (builtins.split "," key-names)
(builtins.filter
(s: builtins.isString s && s != "")
(builtins.split "," key-names)
); );
in builtins.listToAttrs ( in
builtins.map builtins.listToAttrs (
(k: k // { value = { __enum_key = k.value; }; }) builtins.map (
(builtins.map double-match-to-nameval keys-2d-list) k:
k
// {
value = {
__enum_key = k.value;
};
}
) (builtins.map double-match-to-nameval keys-2d-list)
); );
in { in
{
inherit keys-enum; inherit keys-enum;
make = let make =
name-val-to-attrs = (name: value: { inherit name value; } ); let
map-attrs = attrset: fn: lib.map fn name-val-to-attrs = (name: value: { inherit name value; });
(lib.attrsets.mapAttrsToList name-val-to-attrs attrset); map-attrs = attrset: fn: lib.map fn (lib.attrsets.mapAttrsToList name-val-to-attrs attrset);
try-foldl' = op: nul: list: try-foldl' =
if (builtins.length list) == 0 then "" op: nul: list:
else builtins.foldl' op nul list; if (builtins.length list) == 0 then "" else builtins.foldl' op nul list;
concat-with = sepr: list: try-foldl' concat-with = sepr: list: try-foldl' (x: y: if x == null then y else x + sepr + y) null list;
(x: y: if x == null then y else x + sepr + y)
null
list;
ser-bool = bool: if bool then "true" else "false"; ser-bool = bool: if bool then "true" else "false";
ser-str = str: "\"${builtins.replaceStrings ["\n" "\""] ["\\n" "\\\""] str}\""; ser-str = str: "\"${builtins.replaceStrings [ "\n" "\"" ] [ "\\n" "\\\"" ] str}\"";
ser-kvs = { name, value }: if builtins.isList value then ser-kvs =
concat-with "\n" ( { name, value }:
builtins.map if builtins.isList value then
(value: ser-kvs { inherit name value; }) concat-with "\n" (builtins.map (value: ser-kvs { inherit name value; }) value)
value else
) "${name} = ${
else "${name} = ${
if builtins.isString value then if builtins.isString value then
ser-str value ser-str value
else if builtins.isInt value then else if builtins.isInt value then
@@ -56,15 +57,17 @@ in {
ser-bool value ser-bool value
else if builtins.isAttrs value then else if builtins.isAttrs value then
value.__enum_key value.__enum_key
else builtins.throw "type not supported" else
builtins.throw "type not supported"
}"; }";
ser-table = table': let ser-table =
table':
let
tname = table'.name; tname = table'.name;
table = table'.value; table = table'.value;
in in
"[${tname}]\n" + ( "[${tname}]\n" + (concat-with "\n" (map-attrs table ser-kvs));
concat-with "\n" (map-attrs table ser-kvs) in
); cfg: concat-with "\n\n" (map-attrs cfg ser-table);
in cfg: concat-with "\n\n" (map-attrs cfg ser-table);
} }

View File

@@ -1,4 +1,9 @@
{ config, lib, pkgs, ... }: {
config,
lib,
pkgs,
...
}:
let let
cfg = config.services.lidm; cfg = config.services.lidm;
@@ -25,11 +30,24 @@ let
}; };
in in
{ {
options.services.lidm.config = lib.mkOption { options = {
type = with lib.types; oneOf [ str attrs ]; lidm.keysEnum = lib.mkOption {
default = {}; type = with lib.types; attrs;
default = lidm.passthru.keysEnum;
readOnly = true;
description = "Keys enum constants";
};
services.lidm.config = lib.mkOption {
type =
with lib.types;
oneOf [
str
attrs
];
default = { };
description = "Config options for lidm | Either attr tree or name of bundled themes"; description = "Config options for lidm | Either attr tree or name of bundled themes";
}; };
};
config = { config = {
services.displayManager.defaultSession = "lidm"; services.displayManager.defaultSession = "lidm";

12
flake.lock generated
View File

@@ -5,11 +5,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1710146030, "lastModified": 1731533236,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -20,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1724224976, "lastModified": 1751637120,
"narHash": "sha256-Z/ELQhrSd7bMzTO8r7NZgi9g5emh+aRKoCdaAv5fiO0=", "narHash": "sha256-xVNy/XopSfIG9c46nRmPaKfH1Gn/56vQ8++xWA8itO4=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "c374d94f1536013ca8e92341b540eba4c22f9c62", "rev": "5c724ed1388e53cc231ed98330a60eb2f7be4be3",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -7,16 +7,18 @@
}; };
outputs = outputs =
{ flake-utils, nixpkgs, ... }: {
flake-utils,
nixpkgs,
self,
}:
flake-utils.lib.eachDefaultSystem ( flake-utils.lib.eachDefaultSystem (
system: system:
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
name = "lidm"; name = "lidm";
version = builtins.elemAt ( version = builtins.elemAt (builtins.match "VERSION[[:blank:]]*=[[:space:]]*([^\n]*)\n.*" (builtins.readFile ./Makefile)) 0;
builtins.match "VERSION[[:blank:]]*=[[:space:]]*([^\n]*)\n.*" (builtins.readFile ./Makefile)
) 0;
lidm = pkgs.callPackage assets/pkg/nix/lidm.nix { lidm = pkgs.callPackage assets/pkg/nix/lidm.nix {
inherit pkgs; inherit pkgs;
@@ -35,8 +37,10 @@
defaultApp = flake-utils.lib.mkApp { drv = defaultPackage; }; defaultApp = flake-utils.lib.mkApp { drv = defaultPackage; };
defaultPackage = lidm; defaultPackage = lidm;
devShell = pkgs.mkShell { buildInputs = lidm.nativeBuildInputs ++ [ pkgs.clang-tools ]; }; devShell = pkgs.mkShell { buildInputs = lidm.nativeBuildInputs ++ [ pkgs.clang-tools ]; };
formatter = nixpkgs.legacyPackages.${system}.nixfmt-tree;
} }
) // { )
// {
nixosModules.lidm = assets/pkg/nix/module.nix; nixosModules.lidm = assets/pkg/nix/module.nix;
}; };
} }