diff --git a/OwOpointTracker.cabal b/OwOpointTracker.cabal index e854b55..6c7ac59 100644 --- a/OwOpointTracker.cabal +++ b/OwOpointTracker.cabal @@ -39,6 +39,7 @@ library Handler.Common Handler.Home Handler.Station + Handler.Ad Import Import.NoFoundation Model @@ -72,6 +73,7 @@ library , persistent >=2.9 && <2.15 , persistent-sqlite >=2.9 && <2.14 , persistent-template >=2.5 && <2.14 + , random , safe , shakespeare >=2.0 && <2.2 , template-haskell diff --git a/ads/image0.png b/ads/image0.png new file mode 100644 index 0000000..c39dd73 Binary files /dev/null and b/ads/image0.png differ diff --git a/ads/image1.png b/ads/image1.png new file mode 100644 index 0000000..456cc8d Binary files /dev/null and b/ads/image1.png differ diff --git a/ads/image2.png b/ads/image2.png new file mode 100644 index 0000000..8df5cc1 Binary files /dev/null and b/ads/image2.png differ diff --git a/ads/image3.png b/ads/image3.png new file mode 100644 index 0000000..d716045 Binary files /dev/null and b/ads/image3.png differ diff --git a/ads/image4.png b/ads/image4.png new file mode 100644 index 0000000..97b1be1 Binary files /dev/null and b/ads/image4.png differ diff --git a/config/favicon.ico b/config/favicon.ico index 9dd5f35..2f5158d 100644 Binary files a/config/favicon.ico and b/config/favicon.ico differ diff --git a/config/routes.yesodroutes b/config/routes.yesodroutes index b069d4f..0607e98 100644 --- a/config/routes.yesodroutes +++ b/config/routes.yesodroutes @@ -15,6 +15,8 @@ -- stationName/roundNumber /station/#Text/#Int StationRoundR GET POST +/ad/ AdR GET + -- /comments CommentR POST diff --git a/config/settings.yml b/config/settings.yml index 6d5445c..eb9bea6 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -41,3 +41,5 @@ copyright: Insert copyright statement here stations: - station-id: "test" station-name: "Test" + +ad-files: "ads/" diff --git a/flake.lock b/flake.lock index ffd96bf..275f934 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1719994518, - "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "haskell-flake": { "locked": { - "lastModified": 1720977934, - "narHash": "sha256-k9kwz2lpUqafRUpuCMgkv4AWtHEoJPCds1ZPRkyW2XE=", + "lastModified": 1728227251, + "narHash": "sha256-JLDhMFyGyFe0QJAbCuSxB7/kjUCA7uUAMa6BFRORwXk=", "owner": "srid", "repo": "haskell-flake", - "rev": "cd449f1c04175efdf5b553302d22916640090066", + "rev": "9cbfbfc38f1fbf9a0f471795c84780211875fd45", "type": "github" }, "original": { @@ -35,11 +35,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1721466660, - "narHash": "sha256-pFSxgSZqZ3h+5Du0KvEL1ccDZBwu4zvOil1zzrPNb3c=", + "lastModified": 1728279793, + "narHash": "sha256-W3D5YpNrUVTFPVU4jiEiboaaUDShaiH5fRl9aJLqUnU=", "owner": "nixos", "repo": "nixpkgs", - "rev": "6e14bbce7bea6c4efd7adfa88a40dac750d80100", + "rev": "f85a2d005e83542784a755ca8da112f4f65c4aa4", "type": "github" }, "original": { @@ -51,14 +51,14 @@ }, "nixpkgs-lib": { "locked": { - "lastModified": 1719876945, - "narHash": "sha256-Fm2rDDs86sHy0/1jxTOKB1118Q0O3Uc7EC0iXvXKpbI=", + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" }, "original": { "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" } }, "root": { diff --git a/flake.nix b/flake.nix index e7da03c..c8d8d2c 100644 --- a/flake.nix +++ b/flake.nix @@ -6,6 +6,9 @@ }; outputs = inputs@{ self, nixpkgs, flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } { + flake = { + nixosModules.OwOpointTracker = { import ./module.nix self + }; systems = nixpkgs.lib.systems.flakeExposed; imports = [ inputs.haskell-flake.flakeModule ]; diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..db53a1e --- /dev/null +++ b/module.nix @@ -0,0 +1,89 @@ +self: {config, pkgs, lib ...}: +with lib; + +let + cfg = config.services.owOPointTracker; + format = pkgs.formats.yaml {}; + configFile = format.generate "settings.yml" cfg.config + databaseOptionType = types.submodule { + options = { + database = mkOption { + default = "_env:YESOD_SQLITE_DATABASE:OwOpointTracker.sqlite3"; + type = types.str; + }; + poolsize = mkOption { + default = "_env:YESOD_SQLITE_POOLSIZE:10"; + type = types.str; + }; + }; + }; + stationType = types.submodule { + options = { + station-id = mkOption { + default = "Station"; + type = types.str; + }; + station-name = mkOption { + types = types.str; + }; + }; + }; +{ + imports = []; + options.services.owOPointTracker = { + enable = mkEnableOption "OwOPointTracker"; + config = { + static-dir = mkOption { + type = types.path; + }; + host = mkOption { + type = types.str; + default = "_env:YESOD_HOST:*4"; + ad-files = mkOption { + type = types.path; + }; + port = mkOption { + default = "_env:YESOD_PORT:3000"; + type = types.str; + }; + ip-from-header = mkOption { + default = "_env:YESOD_IP_FROM_HEADER:false"; + type = types.str; + }; + database = { + type = databaseOptionType; + }; + copyright = mkOption { + default = "copyright for this mess?"; + type = types.str; + }; + station = mkOption { + type = types.listOf stationType; + }; + + }; + + }; + config = mkIf cfg.enable { + users.users.owopoint = { + isSystemUser = true; + group = "owopoint"; + createHome = true; + home = "/var/owopoint"; + }; + users.groups = { + owopoint = {}; + }; + systemd.services.owOPointTracker = { + wantedBy = ["multi-user.target"]; + after = ["network.target"]; + serviceConfig = { + ExecStart = "${self.packages.${pkgs.system}.default} ${configFile}"; + Restart = always; + User = "owopoint"; + Group = "owopoint"; + }; + }; + + }; +} diff --git a/src/Application.hs b/src/Application.hs index 1d42428..3f8b7f1 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -43,6 +43,7 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet, import Handler.Common import Handler.Home import Handler.Station +import Handler.Ad -- 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 diff --git a/src/Foundation.hs b/src/Foundation.hs index 2e0ba24..ff6cf9e 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -146,8 +146,10 @@ instance Yesod App where -- value passed to hamletToRepHtml cannot be a widget, this allows -- you to use normal widget features in default-layout. + -- randomAddNumber <- liftIO $ getStdRandom (randomR (0,4)) + pc <- widgetToPageContent $ do - addStylesheet $ StaticR css_bootstrap_css + -- addStylesheet $ StaticR css_bootstrap_css -- ^ generated from @Settings/StaticFiles.hs@ $(widgetFile "default-layout") withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet") diff --git a/src/Handler/Ad.hs b/src/Handler/Ad.hs new file mode 100644 index 0000000..d209c72 --- /dev/null +++ b/src/Handler/Ad.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeApplications #-} +module Handler.Ad where + +import Import + +getAdR :: Handler Html +getAdR = do + basePath <- getsYesod (appAdFilePath . appSettings) + number <- applyAtomicGen (randomR (0 :: Int ,4)) globalStdGen + sendFile typePng $ basePath <> "image" <> show number <> ".png" diff --git a/src/Handler/Station.hs b/src/Handler/Station.hs index fccd8bd..f4600d5 100644 --- a/src/Handler/Station.hs +++ b/src/Handler/Station.hs @@ -19,7 +19,8 @@ checkStation stationIdentifier = do Nothing -> notFound Just m -> return m -repsertBy :: (MonadIO m, PersistUniqueRead backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record, SafeToInsert record) => record -> ReaderT backend m () +-- TODO works without the type annotation, but I don't know why this one is wrong. No time to find out now +-- repsertBy :: (MonadIO m, PersistUniqueRead backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record, SafeToInsert record) => record -> ReaderT backend m () repsertBy val = do valM <- getByValue val case valM of diff --git a/src/Import/NoFoundation.hs b/src/Import/NoFoundation.hs index 9ca93f2..9419d1a 100644 --- a/src/Import/NoFoundation.hs +++ b/src/Import/NoFoundation.hs @@ -10,3 +10,5 @@ import Settings.StaticFiles as Import import Yesod.Auth as Import import Yesod.Core.Types as Import (loggerSet) import Yesod.Default.Config2 as Import +import System.Random as Import +import System.Random.Stateful as Import diff --git a/src/Settings.hs b/src/Settings.hs index 8c347c4..3908ea4 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -71,6 +71,7 @@ data AppSettings = AppSettings -- ^ Copyright text to appear in the footer of the page , appStations :: Map Text Text + , appAdFilePath :: String } instance FromJSON AppSettings where @@ -98,6 +99,7 @@ instance FromJSON AppSettings where appCopyright <- o .: "copyright" appStations <- M.fromList . map (\x -> (stationId x, stationName x)) <$> o .: "stations" + appAdFilePath <- o .: "ad-files" return AppSettings {..} diff --git a/static/css/test.css b/static/css/test.css new file mode 100644 index 0000000..589b626 --- /dev/null +++ b/static/css/test.css @@ -0,0 +1,3 @@ +.blubb { + border-width: 300px +} diff --git a/static/grauenhafte_werbung.gif b/static/grauenhafte_werbung.gif new file mode 100644 index 0000000..4df0eba Binary files /dev/null and b/static/grauenhafte_werbung.gif differ diff --git a/templates/default-layout.hamlet b/templates/default-layout.hamlet index 983a412..5dc8a02 100644 --- a/templates/default-layout.hamlet +++ b/templates/default-layout.hamlet @@ -1,16 +1,6 @@ - -$if (Just HomeR == mcurrentRoute) - ^{widget} -$else -
-
-
- ^{widget} - - -