An application can be thought of as a combination of the binary, libraries, resources, and state. By default the applications needs to be able to read any of these and be able to read and write the state. Unix's FSH's biggest problem is that it tries to group files together by type instead of grouping files together by application. Nix can technically group things by application, but it is not really standardized so things can get messy and it is still normal for applications to read and write files from anywhere.
That's not really scattered. /nix/store has the generated files. They get linked to /etc if the app requires that kind of thing - often it's just added to the arguments instead. ~/.config is for user preferences (possible to flip at app runtime or static) which are not a system setting. /var is for system services states. Those are very separate use cases and get managed in different ways. The apps should also never be aware that /nix/store is a thing.
To me they all look the same. For example you could have a /nix/state that had a directory for each program. Each program could have its own global and user specific state it could manage from within its directory.
NixOS already has that. It's called `/var/lib`.
> Each program could have its own global and user specific state it could manage from within its directory.
The user-specific state is (and should be) in each user's home directory, not scattered around in a bunch of system-wide directories, one for each application...
That's not just for convenience, but also for security (and privacy) reasons.
I'd be interested to know who gets to manage the user-specific state in your proposal. Does each app have it's own per-user directory for each user? i.e. if you have 1000 apps and 10 users, do you need exactly 10,000 user-specific directories? And if not, who gets to create these directories and when are they created/removed?
To be honest, it sounds like you're not aware of all the complexities and implications / consequences of what you're proposing, i.e. it sounds like you didn't think this through. But on the off-chance I'm wrong, I'd be happy to be proven so.
I disagree with this because state is owned by the program so it would make the most sense for it to live in the directory for the program. A user can tell the program that they want to modify the state, but ultimately the program has total ownership of its state. The program should not be leaching into user's home directory to read and write files and should be restricted to directories it owns.
>I'd be interested to know who gets to manage the user-specific state in your proposal.
One way to do it would be for the program to manage it.
>Does each app have it's own per-user directory for each user?
It could choose.
>if you have 1000 apps and 10 users, do you need exactly 10,000 user-specific directories?
This is unrealistic. On the want majority of computers an app will only be run by 1 user. Focusing on handling multiple users is a more special case and is a distraction from the point I'm trying to make.
Really? So a program can access (and modify!) the state of all of its users?
Do you realize how easy it would be to trick my Firefox instance into reading (and even modifying) the state of another user, and even running other code on behalf of another user, given that it would have privileges to do so?
If I understand correctly your proposal, you basically just converted almost every single application bug into a privilege escalation bug.
Not to mention that how do you even define what the same "app" is?
Is Firefox 28 the same app as Firefox 45? And if so, can a user install his own Firefox (like you currently can on NixOS and even other OSes)?
Also, how would you backup all of your own per-user state, given that every app can decide to manage it differently (i.e. storing it in different files and/or directories inside their own per-app directory, or perhaps even in a single per-app database which you wouldn't have access to).
Look, I'm not trying to grill you, I just think you haven't thought this through (but again, I'm happy to be proven wrong).
> This is unrealistic. On the want majority of computers an app will only be run by 1 user. Focusing on handling multiple users is a more special case and is a distraction from the point I'm trying to make.
What does this even mean? We're talking about user-specific state. So there's different state for each user, which means there are multiple users, by definition!
So how is focusing on multiple users a distraction? It's the whole point...
As I mentioned, on NixOS, the system-wide mutable state is already stored on /var/lib/<app>, which is what you are (redundantly) proposing. So we're just arguing about how to handle user-specific state, nothing else.
I never said that. The same binary can be run by multiple users and the user running it affects what files it can read and write.
>Not to mention that how do you even define what the same "app" is?
The user has an idea on what the same app is. Unfortunately Nix does not properly understand this concept.
>Also, how would you backup all of your own per-user state, given that every app can decide to manage it differently
You could back up the entire state visible to the user.
>What does this even mean?
Having a single set of state for each program would be good enough for most users.
>As I mentioned, on NixOS, the system-wide mutable state is already stored on /var/lib/<app>, which is what you are (redundantly) proposing.
That is one place. Some programs don't use it. It's not a centralized place of state for every program.
What you're proposing is not even possible with standard Unix permissions (without leaving a huge security hole). You're suggesting that each program can create the state for each user inside the program's directory but somehow cannot read or modify the state for other users.
This suggests the program runs with each user's privileges and therefore these directories would require the sticky bit for state creation (like /tmp does) but this would not prevent a user from roguely creating the state for another user (this is why files in /tmp should be created with random names, they should not be predictable).
Or maybe you're suggesting that all apps should run with setuid privileges (so that they can create the state for each user, but users themselves couldn't) but we already know that would be absolutely terrible for security.
So something like AppArmor (which AFAIK has security flaws) or even SELinux would be required to implement this scheme, I believe, if it's possible at all.
SELinux, AppArmor and other jail-like mechanisms can be a huge burden to manage, especially since most apps would require a substantial number of exceptions to a default security policy (think GUI apps, or apps that require access to a user's files, for example)...
Since most apps do require read/write access to a user's files, or permission to show things on a screen, I'm not sure if you're gaining much security with your scheme. There would be almost infinite ways for an app to exfiltrate or modify a user's files or trick the user into doing things on behalf of the app, I think (like running other apps...).
And if you're implementing a restrictive security policy with something like SELinux or even some kind of container/jail, you might as well do the same but without having to change each and every app to use the weird per-app directory containing the state of all users. This would save you a huge amount of work and potential security vulnerabilities, since private home directories are already secure by default (in terms of protecting a user from other users) and restricting an app not to access the state of other apps could be equally done when using home directories.
> The user has an idea on what the same app is. Unfortunately Nix does not properly understand this concept.
So a user can decide what "Firefox" is? Then what prevents a user from installing a rogue Firefox that exfiltrates the other users' state, in your scheme?
> That is one place. Some programs don't use it. It's not a centralized place of state for every program.
It is for programs that run system-wide and they should be using it.
Which system-wide programs are not using /var/lib for their mutable state?
It's not like they have many other places to save their state... I mean, there is /var/cache but that's for state that can be removed without data loss.
Then you get firejail for more custom apps. You still need that layer and needs to be configured per-app. Would moving config+state into one path really improve the experience? In what way would it be simpler?
Those are features, not bugs... There are reasons for all of those existing and for why you wouldn't want everything in a centralized place.
> NixOS's handling of state is poor. Even ignoring the problem of it all being spread out it is not uncommon for secrets to make it into /nix/store which is world readable.
The secrets handling is a well-known issue and easy to avoid when you're familiar with Nix. Although yes, it can be a problem when people are not aware of it.
And I disagree with NixOS's handling of state being poor. Apart from this "secrets" problem you mentioned, it's not worse than other Linux-based operating systems and in fact it can be argued that it's significantly better.
Just the fact that /nix/store is mounted read-only is, on its own, already a huge improvement over letting users and applications installing and modifying the system in an ad-hoc fashion (good luck when you upgrade your system!).
Not to mention all the other advantages of /nix/store (such as user-installed applications, no package or library conflicts even if you install multiple versions of them, etc).
And as another example, the `stateVersion` feature is something that also makes upgrades a lot more reliable, and I know of no other operating system that has a similar feature.
Atomic configuration changes, booting into specific configurations, and system-wide configuration roll-backs (configurations which also include changes in package versions or even entire OS upgrades), also makes upgrades and configuration changes easy to try / fix if anything goes wrong. No other widely-used operating system has such a reliable configuration change mechanism, as far as I know.
But, you know, if you have other ideas of how things can be improved (apart from your idea of merging user and system-wide state into the same place, which I think makes no sense), I would definitely appreciate to hear it!
It will need to happen sooner or later once distros realize that security is important.
>it's not worse than other Linux-based operating systems
I was not talking in relative terms. NixOS made steps in the right direction, but there is still much more that can be done.
Who knows, maybe something can be fleshed out and improvements come out of it...
https://wiki.gobolinux.org/Overview/GoboLinux-Filesystem-Hie...
Source: https://nixos.wiki/wiki/Overview_of_the_NixOS_Linux_distribu...
That sounds horrible. NixOS sounded kind of interesting, but if that's true it kills any interest I had in it.
On the other hand, your personal files I your home directory are left alone; they don't get put in the nix store. An environment that needs access to your personal files (such as your desktop) simply has your home directory mounted into it.
That's what a file system is.