2023-06-20 21:01:31 +00:00
{ pkgs , . . . }:
2023-06-05 21:52:51 +00:00
2023-06-06 01:07:31 +00:00
{
2023-06-05 21:52:51 +00:00
system . stateVersion = " 2 2 . 1 1 " ;
2023-05-29 17:55:03 +00:00
2023-06-08 05:47:02 +00:00
# Set up two users to demonstrate the user separation
users . users . alice = {
2023-05-29 17:55:03 +00:00
isNormalUser = true ;
password = " a l p h a " ;
2023-06-19 19:33:39 +00:00
uid = 1000 ;
2023-06-22 01:32:44 +00:00
packages = [ pkgs . intake ] ;
2023-05-29 17:55:03 +00:00
} ;
2023-06-08 05:47:02 +00:00
users . users . bob = {
2023-05-29 17:55:03 +00:00
isNormalUser = true ;
password = " b e t a " ;
2024-09-21 19:51:24 +00:00
uid = 1001 ;
2023-06-22 01:32:44 +00:00
packages = [ pkgs . intake ] ;
2023-05-29 17:55:03 +00:00
} ;
2023-06-08 05:47:02 +00:00
# Set up intake for both users with an entry point at port 8080
services . intake = {
listen . port = 8080 ;
users . alice . enable = true ;
users . bob . enable = true ;
} ;
# Expose the vm's intake revproxy at host port 5234
2024-09-21 19:51:24 +00:00
virtualisation . forwardPorts = [
{
from = " h o s t " ;
host . port = 5234 ;
guest . port = 8080 ;
}
] ;
2023-06-08 05:47:02 +00:00
# Mount the demo content for both users
nixos-shell . mounts = {
mountHome = false ;
mountNixProfile = false ;
cache = " n o n e " ;
extraMounts = {
" / m n t / a l i c e " = ./alice ;
" / m n t / b o b " = ./bob ;
2023-06-09 00:07:19 +00:00
" / m n t / s o u r c e s " = ./sources ;
2023-06-08 05:47:02 +00:00
} ;
} ;
# Create an activation script that copies and chowns the demo content
2023-06-09 00:07:19 +00:00
# chmod 777 because the users may not exist when the activation script runs
2024-09-21 19:51:24 +00:00
system . activationScripts =
let
userSetup = name : uid : ''
$ { pkgs . coreutils } /bin/mkdir - p /home / $ { name } /.local/share/intake
$ { pkgs . coreutils } /bin/cp - r /mnt / $ { name } /* / h o m e / $ { n a m e } / . l o c a l / s h a r e / i n t a k e /
$ { pkgs . coreutils } /bin/chown - R $ { uid } /home / $ { name }
$ { pkgs . findutils } /bin/find /home / $ { name } - type d - exec $ { pkgs . coreutils } /bin/chmod 755 { } \ ;
$ { pkgs . findutils } /bin/find /home / $ { name } - type f - exec $ { pkgs . coreutils } /bin/chmod 644 { } \ ;
'' ;
in
{
aliceSetup = userSetup " a l i c e " " 1 0 0 0 " ;
bobSetup = userSetup " b o b " " 1 0 0 1 " ;
} ;
2023-06-09 00:07:19 +00:00
# Put the demo sources on the global PATH
environment . variables . PATH = " / m n t / s o u r c e s " ;
2023-06-19 19:33:39 +00:00
# Include some demo instructions
environment . etc . issue . text = ''
2023-06-23 04:47:16 +00:00
###
2023-06-19 19:33:39 +00:00
# Welcome to the intake demo! Log in as `alice` with password `alpha` to begin.
2023-06-23 04:47:16 +00:00
#
2023-06-19 19:33:39 +00:00
# Exit the VM with ctrl+a x, or switch to the qemu console with ctrl+a c and `quit`.
2023-06-23 04:47:16 +00:00
###
2023-07-03 00:15:52 +00:00
2023-06-19 19:33:39 +00:00
'' ;
users . motd = ''
2023-07-03 00:15:52 +00:00
2023-06-23 04:47:16 +00:00
###
2023-06-19 19:33:39 +00:00
# To set a password for the web interface, run `intake passwd` and set a password.
2023-06-23 04:47:16 +00:00
#
2023-06-19 19:33:39 +00:00
# Within this demo VM, the main intake entry point can be found at localhost:8080. This is also exposed on the host machine at localhost:5234. After you set a password, navigate to localhost:5234 on your host machine and log in to see the web interface.
2023-06-23 04:47:16 +00:00
#
# Try updating the `echo` source by running `intake update -s echo`. You should see a new item after refreshing the source's feed. This source uses `env` source configuration, so use `intake edit -s echo` or the web interface to change the message, then update the source again.
#
# Updating a source will also trigger intake to update the user crontab. If you run `crontab -l`, you should see that the `currenttime` source has a crontab entry. You can change this source's cron schedule in the source config.
###
2023-07-03 00:15:52 +00:00
2023-06-19 19:33:39 +00:00
'' ;
2023-05-29 17:55:03 +00:00
}