From cb9ae44ec4d2e4db07ea38fefcc1227403ebbddb Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Mon, 9 Jun 2025 22:06:51 +0200 Subject: [PATCH 01/65] added nix support --- config/client_session_key | 1 + config/settings.yml | 1 + flake.nix | 94 +++++++++++++++++++++++++++++++++++++++ shell.nix | 11 +++++ src/Foundation.hs | 4 +- src/Settings.hs | 4 +- 6 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 config/client_session_key create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/config/client_session_key b/config/client_session_key new file mode 100644 index 0000000..bada1b0 --- /dev/null +++ b/config/client_session_key @@ -0,0 +1 @@ +þxdHB>èû“,ñ‚rM‘íE®vóªÆ’úä`’¤ŽeØ“\híuQÑë¯R4­ýQ \ No newline at end of file diff --git a/config/settings.yml b/config/settings.yml index dce5c99..f02a46e 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -2,6 +2,7 @@ # See https://github.com/yesodweb/yesod/wiki/Configuration#overriding-configuration-values-with-environment-variables static-dir: "_env:YESOD_STATIC_DIR:static" +session-key: "_env:YESOD_SESSION_KEY:config/client_session_key" host: "_env:YESOD_HOST:*4" # any IPv4 host port: "_env:YESOD_PORT:3000" # NB: The port `yesod devel` uses is distinct from this value. Set the `yesod devel` port from the command line. # For `keter` user, enable the follwing line, and comment out previous one. diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..273b351 --- /dev/null +++ b/flake.nix @@ -0,0 +1,94 @@ +{ + description = "A flake to install sTodo"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; + + outputs = { + self, + nixpkgs, + }: { + packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; + stdenv.mkDerivation { + pname = "sTodo"; + version = "1.0.0"; + + src = fetchTarball { + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + }; + buildInputs = [zlib gmp libffi openssl]; + installPhase = '' + mkdir -p $out/bin + cp $src/sTodo $out/bin + ''; + mainProgram = "sTodo"; + }; + nixosModules.sTodo = { + config, + lib, + ... + }: let + cfg = config.services.sTodo; + in { + options.services.sTodo = { + # options.programs.sTodo = { + enable = lib.mkEnableOption "sTodo"; + package = lib.mkOption { + type = lib.types.package; + default = self.packages.x86_64-linux.sTodo; + }; + appRoot = lib.mkOption { + type = lib.types.str; + default = "http://localhost:6901"; + description = "Link used to access the webapp"; + }; + + staticRoot = lib.mkOption { + type = lib.types.str; + default = "/etc/sTodo/static"; + description = "Location of the static folder"; + }; + + databaseFolder = lib.mkOption { + type = lib.types.str; + default = "/etc/sTodo/sTodo.sqlite3"; + description = "Location of the database folder"; + }; + + clientSessionKey = lib.mkOption { + type = lib.types.str; + default = "/etc/sTodo/client_session_key.aes"; + description = "Location of the client session key"; + }; + + port = lib.mkOption { + type = lib.types.int; + default = 6901; + description = "Default port of the app"; + }; + }; + + # Systemd Service + config = lib.mkIf cfg.enable { + systemd.services.sTodo = { + description = "Launch a sTodo app to have a online todolist"; + after = ["network.target"]; + wantedBy = ["multi-user.target"]; + serviceConfig = { + ExecStart = "${cfg.package}/bin/sTodo"; + Restart = "always"; + }; + environment = { + YESOD_PORT = "${toString cfg.port}"; + YESOD_APPROOT = "${cfg.appRoot}"; + YESOD_SQLITE_DATABASE = "${cfg.databaseFolder}"; + YESOD_STATIC_DIR = "${cfg.staticRoot}"; + YESOD_SESSION_KEY = "${cfg.clientSessionKey}"; + }; + }; + }; + }; + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..e036ca9 --- /dev/null +++ b/shell.nix @@ -0,0 +1,11 @@ +{pkgs ? import {}}: +pkgs.mkShell { + buildInputs = [ + pkgs.haskellPackages.ghc + pkgs.haskellPackages.stack + pkgs.haskellPackages.yesod + pkgs.haskellPackages.yesod-bin + pkgs.haskellPackages.haskell-language-server + pkgs.zlib + ]; +} diff --git a/src/Foundation.hs b/src/Foundation.hs index 241e246..2c365fe 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -80,9 +80,9 @@ instance Yesod App where -- Store session data on the client in encrypted cookies, -- default session idle timeout is 120 minutes makeSessionBackend :: App -> IO (Maybe SessionBackend) - makeSessionBackend _ = Just <$> defaultClientSessionBackend + makeSessionBackend app = Just <$> defaultClientSessionBackend 120 -- timeout in minutes - "config/client_session_key.aes" + (appSessionKey $ appSettings app) -- Yesod Middleware allows you to run code before and after each handler function. -- The defaultYesodMiddleware adds the response header "Vary: Accept, Accept-Language" and performs authorization checks. diff --git a/src/Settings.hs b/src/Settings.hs index 5da2963..c66c174 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -33,7 +33,8 @@ data AppSettings = AppSettings -- ^ Configuration settings for accessing the database. , appRoot :: Maybe Text -- ^ Base for all generated URLs. If @Nothing@, determined - -- from the request headers. + , appSessionKey :: [Char] + -- ^ Where to get the client session key , appHost :: HostPreference -- ^ Host/interface the server should bind to. , appPort :: Int @@ -74,6 +75,7 @@ instance FromJSON AppSettings where appStaticDir <- o .: "static-dir" appDatabaseConf <- o .: "database" appRoot <- o .:? "approot" + appSessionKey <- o .: "session-key" appHost <- fromString <$> o .: "host" appPort <- o .: "port" appIpFromHeader <- o .: "ip-from-header" From 57d862183db453310b44ad3b3a7c69214e960c64 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 08:44:51 +0200 Subject: [PATCH 02/65] added etc --- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 35 ++++++++++++++--------------------- 2 files changed, 41 insertions(+), 21 deletions(-) create mode 100644 flake.lock diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a67fb22 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1749285348, + "narHash": "sha256-frdhQvPbmDYaScPFiCnfdh3B/Vh81Uuoo0w5TkWmmjU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "3e3afe5174c561dee0df6f2c2b2236990146329f", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 273b351..1f8f546 100644 --- a/flake.nix +++ b/flake.nix @@ -8,16 +8,18 @@ outputs = { self, nixpkgs, - }: { + }: let + src = fetchTarball { + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + }; + in +{ packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; stdenv.mkDerivation { pname = "sTodo"; version = "1.0.0"; - src = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; - }; buildInputs = [zlib gmp libffi openssl]; installPhase = '' mkdir -p $out/bin @@ -44,19 +46,6 @@ default = "http://localhost:6901"; description = "Link used to access the webapp"; }; - - staticRoot = lib.mkOption { - type = lib.types.str; - default = "/etc/sTodo/static"; - description = "Location of the static folder"; - }; - - databaseFolder = lib.mkOption { - type = lib.types.str; - default = "/etc/sTodo/sTodo.sqlite3"; - description = "Location of the database folder"; - }; - clientSessionKey = lib.mkOption { type = lib.types.str; default = "/etc/sTodo/client_session_key.aes"; @@ -72,6 +61,10 @@ # Systemd Service config = lib.mkIf cfg.enable { + environment.etc = { + source = "$src/static"; + target = "sTodo/static"; + }; systemd.services.sTodo = { description = "Launch a sTodo app to have a online todolist"; after = ["network.target"]; @@ -83,9 +76,9 @@ environment = { YESOD_PORT = "${toString cfg.port}"; YESOD_APPROOT = "${cfg.appRoot}"; - YESOD_SQLITE_DATABASE = "${cfg.databaseFolder}"; - YESOD_STATIC_DIR = "${cfg.staticRoot}"; - YESOD_SESSION_KEY = "${cfg.clientSessionKey}"; + YESOD_SQLITE_DATABASE = "/etc/sTodo/sTodo.sqlite3"; + YESOD_STATIC_DIR = "/etc/sTodo/static"; + YESOD_SESSION_KEY = "/etc/sTodo/client_session_key.aes"; }; }; }; From 0952b28e6b95284b60a8768122dbfe491e73a535 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 08:47:47 +0200 Subject: [PATCH 03/65] updated flake --- flake.lock | 27 --------------------------- flake.nix | 3 +-- 2 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 flake.lock diff --git a/flake.lock b/flake.lock deleted file mode 100644 index a67fb22..0000000 --- a/flake.lock +++ /dev/null @@ -1,27 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1749285348, - "narHash": "sha256-frdhQvPbmDYaScPFiCnfdh3B/Vh81Uuoo0w5TkWmmjU=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "3e3afe5174c561dee0df6f2c2b2236990146329f", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix index 1f8f546..e845400 100644 --- a/flake.nix +++ b/flake.nix @@ -61,9 +61,8 @@ # Systemd Service config = lib.mkIf cfg.enable { - environment.etc = { + environment."sTodo".etc = { source = "$src/static"; - target = "sTodo/static"; }; systemd.services.sTodo = { description = "Launch a sTodo app to have a online todolist"; From 876da44f498ad3b112a8847b68ce16d9c2401746 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 08:48:46 +0200 Subject: [PATCH 04/65] updated flake --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index e845400..04db7c0 100644 --- a/flake.nix +++ b/flake.nix @@ -61,7 +61,7 @@ # Systemd Service config = lib.mkIf cfg.enable { - environment."sTodo".etc = { + environment.etc."sTodo".etc = { source = "$src/static"; }; systemd.services.sTodo = { From 05cfe09e165ccfbfd23b390f1da22111ce7ca14a Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 08:51:23 +0200 Subject: [PATCH 05/65] updated flake --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 04db7c0..17198a6 100644 --- a/flake.nix +++ b/flake.nix @@ -61,7 +61,7 @@ # Systemd Service config = lib.mkIf cfg.enable { - environment.etc."sTodo".etc = { + environment.etc."sTodo" = { source = "$src/static"; }; systemd.services.sTodo = { From 37153676055ac95f6d5948e0f4ee02c2acceea8a Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 08:53:44 +0200 Subject: [PATCH 06/65] updated flake --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 17198a6..003f181 100644 --- a/flake.nix +++ b/flake.nix @@ -62,7 +62,7 @@ # Systemd Service config = lib.mkIf cfg.enable { environment.etc."sTodo" = { - source = "$src/static"; + source = "${src}/static"; }; systemd.services.sTodo = { description = "Launch a sTodo app to have a online todolist"; From 993d1ee521d7cb481d6eb44a7acbe2abfcb787e3 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 09:07:03 +0200 Subject: [PATCH 07/65] updated flake --- flake.nix | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index 003f181..7440df6 100644 --- a/flake.nix +++ b/flake.nix @@ -8,13 +8,12 @@ outputs = { self, nixpkgs, - }: let - src = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; - }; - in + }: { + src = fetchTarball { + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + }; packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; stdenv.mkDerivation { pname = "sTodo"; @@ -62,7 +61,10 @@ # Systemd Service config = lib.mkIf cfg.enable { environment.etc."sTodo" = { - source = "${src}/static"; + source = fetchTarball { + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + }; }; systemd.services.sTodo = { description = "Launch a sTodo app to have a online todolist"; From 054d8d6807680a1f51e426b9c9b03a87d1c6f497 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 09:15:08 +0200 Subject: [PATCH 08/65] updated flake --- flake.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 7440df6..3696e68 100644 --- a/flake.nix +++ b/flake.nix @@ -10,15 +10,15 @@ nixpkgs, }: { - src = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; - }; packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; stdenv.mkDerivation { pname = "sTodo"; version = "1.0.0"; + src = fetchTarball { + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + }; buildInputs = [zlib gmp libffi openssl]; installPhase = '' mkdir -p $out/bin From 2a67ab52123355e95d24ff67ac65ba3902b71f2a Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 09:19:31 +0200 Subject: [PATCH 09/65] updated flake --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 3696e68..b510efc 100644 --- a/flake.nix +++ b/flake.nix @@ -65,6 +65,7 @@ url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; }; + environment.etc."sTodo/client_session_key.aes".text = "dasdhadhkjashdajhdkjahdakjsh"; }; systemd.services.sTodo = { description = "Launch a sTodo app to have a online todolist"; From 09979689371b961ad19af7982db59b026d343ad0 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 09:38:28 +0200 Subject: [PATCH 10/65] updated flake --- flake.nix | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/flake.nix b/flake.nix index b510efc..a4043ab 100644 --- a/flake.nix +++ b/flake.nix @@ -8,17 +8,16 @@ outputs = { self, nixpkgs, - }: -{ + }: { packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; stdenv.mkDerivation { pname = "sTodo"; version = "1.0.0"; src = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; - }; + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + }; buildInputs = [zlib gmp libffi openssl]; installPhase = '' mkdir -p $out/bin @@ -61,12 +60,12 @@ # Systemd Service config = lib.mkIf cfg.enable { environment.etc."sTodo" = { - source = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; - }; - environment.etc."sTodo/client_session_key.aes".text = "dasdhadhkjashdajhdkjahdakjsh"; - }; + source = "${fetchTarball { + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + }}/source"; + }; + environment.etc."sTodo/client_session_key.aes".text = "dasdhadhkjashdajhdkjahdakjsh"; systemd.services.sTodo = { description = "Launch a sTodo app to have a online todolist"; after = ["network.target"]; From ebb3d06881004116a6233d0596891cbe04046145 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 09:42:30 +0200 Subject: [PATCH 11/65] updated flake --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index a4043ab..5b8e845 100644 --- a/flake.nix +++ b/flake.nix @@ -65,7 +65,7 @@ sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; }}/source"; }; - environment.etc."sTodo/client_session_key.aes".text = "dasdhadhkjashdajhdkjahdakjsh"; + # environment.etc."sTodo/client_session_key.aes".text = "dasdhadhkjashdajhdkjahdakjsh"; systemd.services.sTodo = { description = "Launch a sTodo app to have a online todolist"; after = ["network.target"]; From b8cebf3584e5a45aa192004864a32fae946c5b26 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 10:21:33 +0200 Subject: [PATCH 12/65] updated flake --- flake.nix | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 5b8e845..bc58153 100644 --- a/flake.nix +++ b/flake.nix @@ -1,3 +1,9 @@ +let + tarball = fetchTarball { + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + }; +in { description = "A flake to install sTodo"; @@ -60,10 +66,8 @@ # Systemd Service config = lib.mkIf cfg.enable { environment.etc."sTodo" = { - source = "${fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; - }}/source"; + source = "${tarball}/config"; + }; }; # environment.etc."sTodo/client_session_key.aes".text = "dasdhadhkjashdajhdkjahdakjsh"; systemd.services.sTodo = { @@ -84,5 +88,3 @@ }; }; }; - }; -} From 1bd3be3c0fa6ac09641d202b45c6bc551f028c6c Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 10:24:58 +0200 Subject: [PATCH 13/65] updated flake --- flake.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index bc58153..066b565 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,9 @@ let - tarball = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; - }; -in -{ + tarball = fetchTarball { + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + }; +in { description = "A flake to install sTodo"; inputs = { @@ -67,7 +66,6 @@ in config = lib.mkIf cfg.enable { environment.etc."sTodo" = { source = "${tarball}/config"; - }; }; # environment.etc."sTodo/client_session_key.aes".text = "dasdhadhkjashdajhdkjahdakjsh"; systemd.services.sTodo = { @@ -88,3 +86,5 @@ in }; }; }; + }; +} From 6be9bd78028dcc3b86a479f514df2e59a2d309be Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 10:30:40 +0200 Subject: [PATCH 14/65] flake updated --- flake.nix | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index 066b565..16c8887 100644 --- a/flake.nix +++ b/flake.nix @@ -1,9 +1,4 @@ -let - tarball = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; - }; -in { +{ description = "A flake to install sTodo"; inputs = { @@ -13,20 +8,21 @@ in { outputs = { self, nixpkgs, - }: { + }: let + tarball = fetchTarball { + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + }; + in { packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; stdenv.mkDerivation { pname = "sTodo"; version = "1.0.0"; - src = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; - }; buildInputs = [zlib gmp libffi openssl]; installPhase = '' mkdir -p $out/bin - cp $src/sTodo $out/bin + cp $tarball/sTodo $out/bin ''; mainProgram = "sTodo"; }; From b04ab998ce86311f7464cd8928297355221fd1e1 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 10:32:16 +0200 Subject: [PATCH 15/65] flake updated --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 16c8887..337589b 100644 --- a/flake.nix +++ b/flake.nix @@ -18,7 +18,7 @@ stdenv.mkDerivation { pname = "sTodo"; version = "1.0.0"; - + src = tarball; buildInputs = [zlib gmp libffi openssl]; installPhase = '' mkdir -p $out/bin From 0aac40808eae5b286e155bf6209d07b951dd1f58 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 10:33:37 +0200 Subject: [PATCH 16/65] flake updated --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 337589b..ba77379 100644 --- a/flake.nix +++ b/flake.nix @@ -22,7 +22,7 @@ buildInputs = [zlib gmp libffi openssl]; installPhase = '' mkdir -p $out/bin - cp $tarball/sTodo $out/bin + cp $src/sTodo $out/bin ''; mainProgram = "sTodo"; }; From 39e68d7d82000059befb953f232e25730bd1f542 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 10:44:39 +0200 Subject: [PATCH 17/65] flake updated --- flake.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index ba77379..508ba2e 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,7 @@ nixosModules.sTodo = { config, lib, + pkgs, ... }: let cfg = config.services.sTodo; @@ -63,7 +64,13 @@ environment.etc."sTodo" = { source = "${tarball}/config"; }; - # environment.etc."sTodo/client_session_key.aes".text = "dasdhadhkjashdajhdkjahdakjsh"; + environment.systemPackages = [pkgs.openssl]; + + systemd.services.sTodo.preStart = '' + [ -f /etc/sTodo/client_session_key.aes ] || { + "${pkgs.openssl}/bin/openssl" rand -base64 32 > /etc/sTodo/client_session_key.aes + } + ''; systemd.services.sTodo = { description = "Launch a sTodo app to have a online todolist"; after = ["network.target"]; From fe22b61a15c4739deb3cb703267adcde06d49d72 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 10:54:30 +0200 Subject: [PATCH 18/65] flake updated --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 508ba2e..05c1d08 100644 --- a/flake.nix +++ b/flake.nix @@ -62,7 +62,7 @@ # Systemd Service config = lib.mkIf cfg.enable { environment.etc."sTodo" = { - source = "${tarball}/config"; + source = "${tarball.out}/config"; }; environment.systemPackages = [pkgs.openssl]; From f65eb94d18b16670a5a6f1fcf1fe029ffe8265b6 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 10:57:11 +0200 Subject: [PATCH 19/65] flake updated --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 05c1d08..d3f8919 100644 --- a/flake.nix +++ b/flake.nix @@ -62,7 +62,7 @@ # Systemd Service config = lib.mkIf cfg.enable { environment.etc."sTodo" = { - source = "${tarball.out}/config"; + source = "${tarball}"; }; environment.systemPackages = [pkgs.openssl]; From fe57ada6007d83012e9a6c02e7d33ef5b3559953 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 10:59:27 +0200 Subject: [PATCH 20/65] flake updated --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index d3f8919..508ba2e 100644 --- a/flake.nix +++ b/flake.nix @@ -62,7 +62,7 @@ # Systemd Service config = lib.mkIf cfg.enable { environment.etc."sTodo" = { - source = "${tarball}"; + source = "${tarball}/config"; }; environment.systemPackages = [pkgs.openssl]; From 2f51d7a569dae21aa0885a0144ab6f2c1fb28efe Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 11:01:45 +0200 Subject: [PATCH 21/65] flake updated --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 508ba2e..79cdff1 100644 --- a/flake.nix +++ b/flake.nix @@ -61,8 +61,8 @@ # Systemd Service config = lib.mkIf cfg.enable { - environment.etc."sTodo" = { - source = "${tarball}/config"; + environment.etc."sTodo/static" = { + source = "${tarball}/static"; }; environment.systemPackages = [pkgs.openssl]; From a2bfb5eb9ef1c10f16469251cc02f496b50185cf Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 11:12:55 +0200 Subject: [PATCH 22/65] flake updated --- flake.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 79cdff1..bb93941 100644 --- a/flake.nix +++ b/flake.nix @@ -33,6 +33,7 @@ ... }: let cfg = config.services.sTodo; + sessionKey = "/etc/sTodo/client_session_key.aes"; in { options.services.sTodo = { # options.programs.sTodo = { @@ -67,8 +68,8 @@ environment.systemPackages = [pkgs.openssl]; systemd.services.sTodo.preStart = '' - [ -f /etc/sTodo/client_session_key.aes ] || { - "${pkgs.openssl}/bin/openssl" rand -base64 32 > /etc/sTodo/client_session_key.aes + [ -f ${sessionKey} ] || { + "${pkgs.openssl}/bin/openssl" rand -base64 32 > ${sessionKey} } ''; systemd.services.sTodo = { @@ -82,9 +83,9 @@ environment = { YESOD_PORT = "${toString cfg.port}"; YESOD_APPROOT = "${cfg.appRoot}"; - YESOD_SQLITE_DATABASE = "/etc/sTodo/sTodo.sqlite3"; + YESOD_SQLITE_DATABASE = "/var/lib/sTodo.sqlite3"; YESOD_STATIC_DIR = "/etc/sTodo/static"; - YESOD_SESSION_KEY = "/etc/sTodo/client_session_key.aes"; + YESOD_SESSION_KEY = sessionKey; }; }; }; From 85bae9d67ddcd942d6c3a4101aee46e6700b7b38 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 11:20:24 +0200 Subject: [PATCH 23/65] updated flake --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index bb93941..b95ca06 100644 --- a/flake.nix +++ b/flake.nix @@ -69,7 +69,7 @@ systemd.services.sTodo.preStart = '' [ -f ${sessionKey} ] || { - "${pkgs.openssl}/bin/openssl" rand -base64 32 > ${sessionKey} + "${pkgs.openssl}/bin/openssl" rand 256 > ${sessionKey} } ''; systemd.services.sTodo = { @@ -83,7 +83,7 @@ environment = { YESOD_PORT = "${toString cfg.port}"; YESOD_APPROOT = "${cfg.appRoot}"; - YESOD_SQLITE_DATABASE = "/var/lib/sTodo.sqlite3"; + YESOD_SQLITE_DATABASE = "/var/lib/sTodo/sTodo.sqlite3"; YESOD_STATIC_DIR = "/etc/sTodo/static"; YESOD_SESSION_KEY = sessionKey; }; From 95ffbf6300eb902f10cbbab580332883d845efc0 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 12:32:37 +0200 Subject: [PATCH 24/65] added some security options --- flake.nix | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/flake.nix b/flake.nix index b95ca06..d34867b 100644 --- a/flake.nix +++ b/flake.nix @@ -79,6 +79,30 @@ serviceConfig = { ExecStart = "${cfg.package}/bin/sTodo"; Restart = "always"; + User = "sTodo"; + Group = "sTodo"; + StateDirectory = "sTodo"; + StateDirectoryMode = "0700"; + + AmbientCapabilities = ""; + CapabilityBoundingSet = ""; + DeviceAllow = ""; + LockPersonality = true; + MemoryDenyWriteExecute = true; + NoNewPrivileges = true; + + PrivateDevices = true; + PrivateUsers = true; + + ProtectClock = true; + ProtectControlGroups = true; + ProtectHome = "read-only"; + ProtectHostname = true; + ProtectKernelLogs = true; + ProtectKernelModules = true; + ProtectKernelTunables = true; + ProtectProc = "noaccess"; + ProtectSystem = "strict"; }; environment = { YESOD_PORT = "${toString cfg.port}"; From 286622351843d4ee6f18a25fb856c6ae62e388f0 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 12:44:28 +0200 Subject: [PATCH 25/65] added users --- flake.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index d34867b..8ddc08e 100644 --- a/flake.nix +++ b/flake.nix @@ -66,7 +66,12 @@ source = "${tarball}/static"; }; environment.systemPackages = [pkgs.openssl]; - + groups."sTodo".name = "sTodo"; + users."sTodo" = { + name = "sTodo"; + isSystemUser = true; + group = "sTodo"; + }; systemd.services.sTodo.preStart = '' [ -f ${sessionKey} ] || { "${pkgs.openssl}/bin/openssl" rand 256 > ${sessionKey} From b2db2dc9f9774f0fc53f561feebd948d2eeda114 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 12:46:32 +0200 Subject: [PATCH 26/65] added users --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index 8ddc08e..d6f49d3 100644 --- a/flake.nix +++ b/flake.nix @@ -66,7 +66,6 @@ source = "${tarball}/static"; }; environment.systemPackages = [pkgs.openssl]; - groups."sTodo".name = "sTodo"; users."sTodo" = { name = "sTodo"; isSystemUser = true; From ad0d0c3a55e10f8cdda8e552888ec2b325363f28 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Tue, 10 Jun 2025 12:47:22 +0200 Subject: [PATCH 27/65] added users --- flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index d6f49d3..8cec79d 100644 --- a/flake.nix +++ b/flake.nix @@ -66,7 +66,8 @@ source = "${tarball}/static"; }; environment.systemPackages = [pkgs.openssl]; - users."sTodo" = { + users.groups."sTodo".name = "sTodo"; + users.users."sTodo" = { name = "sTodo"; isSystemUser = true; group = "sTodo"; From 113990ac54216bcc57e06a52519c0b4ce15c78fe Mon Sep 17 00:00:00 2001 From: Stuce Date: Fri, 13 Jun 2025 13:36:50 +0100 Subject: [PATCH 28/65] updated readme documentation --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4584fdd..aacc35a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,25 @@ # sTodo Stuce's simple todo is a web app that let's you self host a simple todolist. The goal is to provide a minimalistic and fast todo list that is self hostable. - +## Next goals +- Make multi user support + - [ ] Get user by trusted header + - [ ] Add option to enable single user (usefull for vpn single user easy setup) + - [ ] Add menu to add other users to the group + - [ ] make the code more readable by renaming/moving the handlers better + - [ ] write a minimal step by step guide to install with nix, + - [ ] add some css to make it look nicer + - [ ] add htmx to make more agreable without making js manadatory ## Version 1.0.0 Simple todo list for **single user only** at the moment. +Features : + - add and delete (and soon share) groups that contain a list of todolists + - add and delete todolists inside groups + - add todolist items or edit complete list via text for easy manipulation + - possibility to deploy easily via nix module with a flake + - that's it, the goal is to keep it minimal !!! -## Haskell Setup +## Haskell Setup (I sadly don't use nix develop at the moment) 1. If you haven't already, [install Stack](https://haskell-lang.org/get-started) * On POSIX systems, this is usually `curl -sSL https://get.haskellstack.org/ | sh` From 4b9d2e8733a4586fae64325df80891a91c50b157 Mon Sep 17 00:00:00 2001 From: Stuce Date: Fri, 13 Jun 2025 15:12:47 +0100 Subject: [PATCH 29/65] user is no longer hardcoded --- src/Handler/TodoEntry.hs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Handler/TodoEntry.hs b/src/Handler/TodoEntry.hs index 757d024..4ce96d6 100644 --- a/src/Handler/TodoEntry.hs +++ b/src/Handler/TodoEntry.hs @@ -5,6 +5,8 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE FlexibleContexts #-} +{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} +{-# HLINT ignore "Replace case with fromMaybe" #-} module Handler.TodoEntry where import Import @@ -41,7 +43,7 @@ postAddGroupR = do _ <- runDB $ do gId <- insert $ Group g success <- insertUnique $ GroupUser user g gId - when (isNothing success) $ delete gId + when (isNothing success) $ delete gId redirect HomeR postAddTodolistR :: GroupId -> Handler Html postAddTodolistR groupId = do @@ -169,10 +171,9 @@ postEditTodolistR groupId = error "not done yet" getEditGroupR :: Handler Html getEditGroupR = do + userId <- getUserId groups <- runDB $ do - -- TODO: using 404 is just a hack to win time, but next it needs better auth handling - userId <- getBy404 $ UniqueName getUser - selectList [GroupUserUser ==. entityKey userId] [Asc GroupUserGroup] + selectList [GroupUserUser ==. userId] [Asc GroupUserGroup] mToken <- fmap reqToken getRequest defaultLayout $ do let a e = pack $ show $ fromSqlKey $ entityKey e ::Text @@ -231,14 +232,27 @@ getItems text todolistId = map read (lines text) something -> filter (/= '\r') something TodolistItem todolistId value name -- TODO: complete implementation should short circuit if multi user is on but no user exist -getUser = "Stuce" :: Text + +-- getUserId :: Handler (Key User) +-- getUserId = do +-- mUser <- runDB $ getBy $ UniqueName "Stuce" +-- case mUser of +-- Nothing -> runDB $ insert $ User "Stuce" +-- Just u -> return $ entityKey u + +-- TODO: this is kinda ugly, i need to try to find better solution, maybe do a custom auth instance, but i guess it goes for the moment getUserId :: Handler (Key User) getUserId = do - mUser <- runDB $ getBy $ UniqueName getUser - case mUser of - Nothing -> runDB $ insert $ User getUser - Just u -> return $ entityKey u + mName <- lookupHeader "Remote-User" + case mName of + -- TODO: if this temporary solution stays, we need here a way to use authDummy somehow in developpement + Nothing -> permissionDenied "no trusted header found !" + Just name -> do + mUser <- runDB $ getBy $ UniqueName (decodeUtf8 name) + case mUser of + Nothing -> runDB $ insert $ User (decodeUtf8 name) + Just u -> return $ entityKey u dbIfAuth groupId action = do -- TODO: decide if we prefer fast (rawSql) or safe (type safe persist query) after in production latency tests From ab707af87083a2ee0519b74a569118aecb9de26f Mon Sep 17 00:00:00 2001 From: Stuce Date: Mon, 23 Jun 2025 11:25:55 +0100 Subject: [PATCH 30/65] implemented yesodauth, now need use it in handler --- src/Application.hs | 26 ++++++++++++++++++++++++++ src/Handler/TodoEntry.hs | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Application.hs b/src/Application.hs index cb03f37..314b501 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -1,11 +1,14 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE RecordWildCards #-} {-# OPTIONS_GHC -fno-warn-orphans #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE InstanceSigs #-} module Application ( getApplicationDev , appMain @@ -43,6 +46,9 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet, import Handler.Common import Handler.Home import Handler.TodoEntry +import Yesod.Auth +import Database.Persist.Class.PersistUnique (getByValueUniques) +import Database.Persist.SqlBackend.SqlPoolHooks (getAlterBackend) -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the @@ -187,3 +193,23 @@ handler h = getAppSettings >>= makeFoundation >>= flip unsafeHandler h -- | Run DB queries db :: ReaderT SqlBackend Handler a -> IO a db = handler . runDB +instance YesodAuthPersist App +instance YesodAuth App where + type AuthId App = Key User + loginDest _ = HomeR + logoutDest _ = HomeR + + authPlugins _ = [ ] + + authenticate :: (MonadHandler m, HandlerSite m ~ App) => Creds App -> m (AuthenticationResult App) + authenticate _ = liftHandler $ do + mUserName <- lookupHeader "remoteUser" + case mUserName of + Just userNameBS -> do + let userName = decodeUtf8 userNameBS + x <- runDB $ insertBy $ User userName + return $ Authenticated $ + case x of + Left (Entity user _) -> user -- existing user + Right user -> user -- newly added user + Nothing -> notAuthenticated \ No newline at end of file diff --git a/src/Handler/TodoEntry.hs b/src/Handler/TodoEntry.hs index 4ce96d6..b49ac60 100644 --- a/src/Handler/TodoEntry.hs +++ b/src/Handler/TodoEntry.hs @@ -241,7 +241,7 @@ getItems text todolistId = map read (lines text) -- Nothing -> runDB $ insert $ User "Stuce" -- Just u -> return $ entityKey u --- TODO: this is kinda ugly, i need to try to find better solution, maybe do a custom auth instance, but i guess it goes for the moment +-- TODO: use yesodAuth and clean this mess getUserId :: Handler (Key User) getUserId = do mName <- lookupHeader "Remote-User" From ce2dd6c750af7d1b6a407868b9e2c2190a202956 Mon Sep 17 00:00:00 2001 From: Stuce Date: Wed, 25 Jun 2025 11:13:18 +0100 Subject: [PATCH 31/65] decided not to use auth in the end --- src/Application.hs | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/Application.hs b/src/Application.hs index 314b501..667b72d 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -44,11 +44,7 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet, -- Import all relevant handler modules here. -- Don't forget to add new modules to your cabal file! import Handler.Common -import Handler.Home import Handler.TodoEntry -import Yesod.Auth -import Database.Persist.Class.PersistUnique (getByValueUniques) -import Database.Persist.SqlBackend.SqlPoolHooks (getAlterBackend) -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the @@ -192,24 +188,4 @@ handler h = getAppSettings >>= makeFoundation >>= flip unsafeHandler h -- | Run DB queries db :: ReaderT SqlBackend Handler a -> IO a -db = handler . runDB -instance YesodAuthPersist App -instance YesodAuth App where - type AuthId App = Key User - loginDest _ = HomeR - logoutDest _ = HomeR - - authPlugins _ = [ ] - - authenticate :: (MonadHandler m, HandlerSite m ~ App) => Creds App -> m (AuthenticationResult App) - authenticate _ = liftHandler $ do - mUserName <- lookupHeader "remoteUser" - case mUserName of - Just userNameBS -> do - let userName = decodeUtf8 userNameBS - x <- runDB $ insertBy $ User userName - return $ Authenticated $ - case x of - Left (Entity user _) -> user -- existing user - Right user -> user -- newly added user - Nothing -> notAuthenticated \ No newline at end of file +db = handler . runDB \ No newline at end of file From b601bdd79693b7fae04542c772a91db17b254f20 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Wed, 25 Jun 2025 14:08:37 +0200 Subject: [PATCH 32/65] updated tarball --- flake.nix | 10 +++++----- stack.yaml | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 8cec79d..d7222c2 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ nixpkgs, }: let tarball = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release1/release1.tar.gz"; + url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release2/release2.tar.gz"; sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; }; in { @@ -68,10 +68,10 @@ environment.systemPackages = [pkgs.openssl]; users.groups."sTodo".name = "sTodo"; users.users."sTodo" = { - name = "sTodo"; - isSystemUser = true; - group = "sTodo"; - }; + name = "sTodo"; + isSystemUser = true; + group = "sTodo"; + }; systemd.services.sTodo.preStart = '' [ -f ${sessionKey} ] || { "${pkgs.openssl}/bin/openssl" rand 256 > ${sessionKey} diff --git a/stack.yaml b/stack.yaml index be7a8b4..3092e82 100644 --- a/stack.yaml +++ b/stack.yaml @@ -20,6 +20,10 @@ snapshot: url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/26.yaml +nix: + enable: true + pure: false + # User packages to be built. # Various formats can be used as shown in the example below. # From c84fa67136162cef2d54246e5631842c2ebf8b03 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Wed, 25 Jun 2025 15:47:12 +0200 Subject: [PATCH 33/65] . --- flake.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index d7222c2..3896e0e 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }: let tarball = fetchTarball { url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release2/release2.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jscn7nhlvn56g0709l5jp91qimw7xiqz"; + sha256 = "10jyldwmcs5zyz1k8lp3jsdn7nhlvn56g0709l5jp91qimw7xiqz"; }; in { packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; @@ -19,7 +19,8 @@ pname = "sTodo"; version = "1.0.0"; src = tarball; - buildInputs = [zlib gmp libffi openssl]; + buildInputs = [zlib gmp libffi]; + nativeBuildInputs = [openssl]; installPhase = '' mkdir -p $out/bin cp $src/sTodo $out/bin From c259f6dc1ae8ac467adb08aaf96aad227340d1d2 Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Wed, 25 Jun 2025 16:19:18 +0200 Subject: [PATCH 34/65] fixed link --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 3896e0e..7756549 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ nixpkgs, }: let tarball = fetchTarball { - url = "https://git.stuce.ch/stuce/sTodo/releases/download/Release2/release2.tar.gz"; + url = "https://git.stuce.ch/stuce/sTodo/releases/download/r2/release2.tar.gz"; sha256 = "10jyldwmcs5zyz1k8lp3jsdn7nhlvn56g0709l5jp91qimw7xiqz"; }; in { From e2c414f1085dd89a2de40f552769b3fd526dbf4c Mon Sep 17 00:00:00 2001 From: stuce-bot Date: Wed, 25 Jun 2025 16:26:04 +0200 Subject: [PATCH 35/65] fixed sha --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 7756549..243cf0c 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }: let tarball = fetchTarball { url = "https://git.stuce.ch/stuce/sTodo/releases/download/r2/release2.tar.gz"; - sha256 = "10jyldwmcs5zyz1k8lp3jsdn7nhlvn56g0709l5jp91qimw7xiqz"; + sha256 = "11mmq60w5da42mzlckizbrgnpzzj8a8jz69ap5k86zh6a536v456"; }; in { packages.x86_64-linux.sTodo = with nixpkgs.legacyPackages.x86_64-linux; From 596c830febb89494d1a4119f4166e3ce775fa566 Mon Sep 17 00:00:00 2001 From: stuce Date: Wed, 25 Jun 2025 17:03:58 +0200 Subject: [PATCH 36/65] Update README.md tested, it works --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aacc35a..4840165 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Stuce's simple todo is a web app that let's you self host a simple todolist. The goal is to provide a minimalistic and fast todo list that is self hostable. ## Next goals - Make multi user support - - [ ] Get user by trusted header + - [x] Get user by trusted header - [ ] Add option to enable single user (usefull for vpn single user easy setup) - [ ] Add menu to add other users to the group - [ ] make the code more readable by renaming/moving the handlers better From ee6d6de2124b52525da2d1324e266e3001e728dc Mon Sep 17 00:00:00 2001 From: stuce Date: Wed, 25 Jun 2025 17:05:46 +0200 Subject: [PATCH 37/65] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4840165..7579f1c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The goal is to provide a minimalistic and fast todo list that is self hostable. - [ ] write a minimal step by step guide to install with nix, - [ ] add some css to make it look nicer - [ ] add htmx to make more agreable without making js manadatory -## Version 1.0.0 +## Version 0.0.0 Simple todo list for **single user only** at the moment. Features : - add and delete (and soon share) groups that contain a list of todolists From 81ca02948bf357f98bede859e45d5e5cd975ec24 Mon Sep 17 00:00:00 2001 From: Stuce Date: Wed, 25 Jun 2025 17:03:00 +0100 Subject: [PATCH 38/65] qol improvements --- config/routes.yesodroutes | 3 ++ src/Handler/TodoEntry.hs | 77 +++++++++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/config/routes.yesodroutes b/config/routes.yesodroutes index 9413671..86f2549 100644 --- a/config/routes.yesodroutes +++ b/config/routes.yesodroutes @@ -16,8 +16,11 @@ /check/group/#GroupId/todolist/#TodolistId/#TodolistItemId CheckTodolistItemR POST /edit/group/#GroupId/todolist/#TodolistId EditTodolistItemsR GET POST +/sort/group/#GroupId/todolist/#TodolistId SortTodolistItemsR POST +/trim/group/#GroupId/todolist/#TodolistId TrimTodolistItemsR POST /edit/group/#GroupId EditTodolistR GET POST +/adduser/group/#GroupId AddUserR POST /edit EditGroupR GET POST /delete DeleteGroupR POST diff --git a/src/Handler/TodoEntry.hs b/src/Handler/TodoEntry.hs index b49ac60..11f7fb2 100644 --- a/src/Handler/TodoEntry.hs +++ b/src/Handler/TodoEntry.hs @@ -12,6 +12,7 @@ module Handler.TodoEntry where import Import import Text.Read import Database.Persist.Sql (rawExecute, fromSqlKey, toSqlKey) +import GHC.RTS.Flags (TraceFlags(user)) -- TODO: move this back to another handler getHomeR :: Handler Html getHomeR = do @@ -71,12 +72,21 @@ getTodolistR groupId = do $maybe token <- mToken